From 46ceaf49dd48f98a289d22f039d933d3138d3130 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 21 Aug 2024 01:40:21 -0400 Subject: [PATCH] meow --- CMakeLists.txt | 2 +- tests/gp_test_1.cpp | 15 ++++++--------- tests/gp_test_2.cpp | 22 ++++++++++------------ tests/order_tests.cpp | 16 ++++++---------- tests/stack_tests.cpp | 24 ++++++++++++------------ 5 files changed, 35 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2240b9..c7bdaad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.17) +project(blt-gp VERSION 0.1.18) include(CTest) diff --git a/tests/gp_test_1.cpp b/tests/gp_test_1.cpp index e1fe9be..bf0b295 100644 --- a/tests/gp_test_1.cpp +++ b/tests/gp_test_1.cpp @@ -319,9 +319,9 @@ namespace blt::gp::detail explicit operator_storage_test(blt::gp::operator_builder& ops): ops(ops) {} - inline blt::gp::detail::callable_t& operator[](blt::size_t index) + inline blt::gp::detail::operator_func_t& operator[](blt::size_t index) { - return ops.storage.operators[index].function; + return ops.storage.operators[index].func; } private: @@ -447,24 +447,21 @@ int main() //BLT_TRACE(blt::type_string>()); //BLT_TRACE("Same types? %s", (std::is_same_v>) ? "true" : "false"); - ops.add_operator(silly_op_3); - ops.add_operator(silly_op_4); - ops.add_operator(silly_op_2); - + ops.build(silly_op_3, silly_op_4, silly_op_2); blt::gp::detail::operator_storage_test de(ops); context hello{5, 10}; alloc.push(1.153f); - de[0](static_cast(&hello), alloc, alloc, nullptr); + de[0](static_cast(&hello), alloc, alloc); BLT_TRACE("first value: %f", alloc.pop()); - de[1](static_cast(&hello), alloc, alloc, nullptr); + de[1](static_cast(&hello), alloc, alloc); BLT_TRACE("second value: %f", alloc.pop()); alloc.push(1.0f); alloc.push(52.213f); - de[2](static_cast(&hello), alloc, alloc, nullptr); + de[2](static_cast(&hello), alloc, alloc); BLT_TRACE("third value: %f", alloc.pop()); //auto* pointer = static_cast(head->metadata.offset); diff --git a/tests/gp_test_2.cpp b/tests/gp_test_2.cpp index e2c641f..50a68dc 100644 --- a/tests/gp_test_2.cpp +++ b/tests/gp_test_2.cpp @@ -32,18 +32,21 @@ blt::gp::operation_t add([](float a, float b) { }); blt::gp::operation_t sub([](float a, float b) { BLT_TRACE("a: %f - b: %f = %f", a, b, a - b); - return a - b; }); + return a - b; +}); blt::gp::operation_t mul([](float a, float b) { BLT_TRACE("a: %f * b: %f = %f", a, b, a * b); - return a * b; }); + return a * b; +}); blt::gp::operation_t pro_div([](float a, float b) { BLT_TRACE("a: %f / b: %f = %f", a, b, (b == 0 ? 0.0f : a / b)); - return b == 0 ? 0.0f : a / b; }); -blt::gp::operation_t lit([]() { + return b == 0 ? 0.0f : a / b; +}); +auto lit = blt::gp::operation_t([]() { //static std::uniform_real_distribution dist(-32000, 32000); // static std::uniform_real_distribution dist(0.0f, 10.0f); return program.get_random().get_float(0.0f, 10.0f); -}); +}).set_ephemeral(); /** * This is a test using a type with blt::gp @@ -53,18 +56,13 @@ int main() type_system.register_type(); blt::gp::operator_builder silly{type_system}; - silly.add_operator(add); - silly.add_operator(sub); - silly.add_operator(mul); - silly.add_operator(pro_div); - silly.add_operator(lit, true); - program.set_operations(silly.build()); + program.set_operations(silly.build(add, sub, mul, pro_div, lit)); blt::gp::grow_generator_t grow; auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type().id(), 3, 7}); - auto value = tree.get_evaluation_value(nullptr); + auto value = tree.get_evaluation_value(nullptr, program.get_eval_func()); BLT_TRACE(value); diff --git a/tests/order_tests.cpp b/tests/order_tests.cpp index 1eb05c6..d59ea4e 100644 --- a/tests/order_tests.cpp +++ b/tests/order_tests.cpp @@ -72,13 +72,13 @@ blt::gp::operation_t basic_sub([](float a, float b, bool choice) { } }, "sub"); -blt::gp::operation_t basic_lit_f([]() { +auto basic_lit_f= blt::gp::operation_t([]() { return b_rand.choice() ? 5.0f : 10.0f; -}); +}).set_ephemeral(); -blt::gp::operation_t basic_lit_b([]() { +auto basic_lit_b = blt::gp::operation_t([]() { return false; -}); +}).set_ephemeral(); void basic_test() { @@ -86,18 +86,14 @@ void basic_test() blt::gp::operator_builder builder{type_system}; - builder.add_operator(basic_sub); - builder.add_operator(basic_lit_f, true); - builder.add_operator(basic_lit_b, true); - - program.set_operations(builder.build()); + program.set_operations(builder.build(basic_sub, basic_lit_f, basic_lit_b)); blt::gp::grow_generator_t gen; blt::gp::generator_arguments args{program, type_system.get_type().id(), 1, 1}; auto tree = gen.generate(args); context ctx{&program}; - auto result = tree.get_evaluation_value(&ctx); + auto result = tree.get_evaluation_value(&ctx, program.get_eval_func()); BLT_TRACE(result); BLT_ASSERT(result == -5.0f || result == 5.0f || result == 0.0f); tree.print(program, std::cout, true, true); diff --git a/tests/stack_tests.cpp b/tests/stack_tests.cpp index bb66af6..c9a34c7 100644 --- a/tests/stack_tests.cpp +++ b/tests/stack_tests.cpp @@ -302,7 +302,7 @@ void test_basic() stack.push(50.0f); stack.push(10.0f); BLT_TRACE_STREAM << stack.size() << "\n"; - basic_2.make_callable()(nullptr, stack, stack, nullptr); + basic_2.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(val != 60.000000f, stack, "Basic 2 Test Passed", "Basic 2 Test Failed. Unexpected value produced '%lf'", val); @@ -318,7 +318,7 @@ void test_basic() auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; //BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!"); - basic_2.make_callable()(nullptr, stack, stack, nullptr); + basic_2.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); stack.pop>(); @@ -339,7 +339,7 @@ void test_mixed() stack.push(false); BLT_TRACE_STREAM << stack.size() << "\n"; - basic_mixed_4.make_callable()(nullptr, stack, stack, nullptr); + basic_mixed_4.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(val != 50.000000f, stack, "Mixed 4 Test Passed", "Mixed 4 Test Failed. Unexpected value produced '%lf'", val); @@ -357,7 +357,7 @@ void test_mixed() auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; // BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!"); - basic_mixed_4.make_callable()(nullptr, stack, stack, nullptr); + basic_mixed_4.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); stack.pop>(); @@ -377,7 +377,7 @@ void test_large_256() stack.push(69.420f); BLT_TRACE_STREAM << stack.size() << "\n"; - large_256_basic_3.make_callable()(nullptr, stack, stack, nullptr); + large_256_basic_3.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(!compare(val, base_256), stack, "Large 256 3 Test Passed", "Large 256 3 Test Failed. Unexpected value produced '%lf'", val); @@ -394,7 +394,7 @@ void test_large_256() auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; // BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!"); - large_256_basic_3.make_callable()(nullptr, stack, stack, nullptr); + large_256_basic_3.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); stack.pop>(); @@ -413,7 +413,7 @@ void test_large_4096() stack.push(33.0f); stack.push(true); BLT_TRACE_STREAM << stack.size() << "\n"; - large_4096_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_4096_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val); @@ -429,7 +429,7 @@ void test_large_4096() auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; // BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!"); - large_4096_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_4096_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val); @@ -447,7 +447,7 @@ void test_large_18290() stack.push(-2543.0f); stack.push(true); BLT_TRACE_STREAM << stack.size() << "\n"; - large_18290_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_18290_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val); @@ -464,7 +464,7 @@ void test_large_18290() auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; // BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!"); - large_18290_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_18290_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); stack.pop>(); @@ -480,12 +480,12 @@ void test_large_18290() stack.push(true); auto size = stack.size(); BLT_TRACE_STREAM << size << "\n"; - large_18290_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_18290_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; stack.push(-2543.0f); stack.push(true); BLT_TRACE_STREAM << stack.size() << "\n"; - large_18290_basic_3b.make_callable()(nullptr, stack, stack, nullptr); + large_18290_basic_3b.make_callable()(nullptr, stack, stack); BLT_TRACE_STREAM << stack.size() << "\n"; auto val = stack.pop(); RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);