From 58b68b70bb1d3086124b688f477544c3f94fb606 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 22 Jul 2024 20:49:34 -0400 Subject: [PATCH] fix the bug? --- CMakeLists.txt | 2 +- include/blt/gp/operations.h | 15 -------- include/blt/gp/stack.h | 7 ++-- lib/blt | 2 +- tests/stack_tests.cpp | 70 +++++++++++++++++++++++++++++-------- 5 files changed, 62 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0faa4e..7ee5925 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.0.99) +project(blt-gp VERSION 0.0.100) include(CTest) diff --git a/include/blt/gp/operations.h b/include/blt/gp/operations.h index 32c43be..b7e1106 100644 --- a/include/blt/gp/operations.h +++ b/include/blt/gp/operations.h @@ -197,21 +197,6 @@ namespace blt::gp template operation_t(Return(*)(Args...), std::optional) -> operation_t; - -// templat\e -// operation_t make_operator(Return (Class::*)(Args...) const lambda) -// { -// // https://ventspace.wordpress.com/2022/04/11/quick-snippet-c-type-trait-templates-for-lambda-details/ -// } -// -// template -// operation_t make_operator(Lambda&& lambda) -// { -// return operation_t(std::forward(lambda)); -// } -// -// template -// operation(std::function) -> operation; } #endif //BLT_GP_OPERATIONS_H diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index f723bfb..e461205 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -176,13 +176,14 @@ namespace blt::gp #endif #endif auto diff = head->used_bytes_in_block() - bytes; + BLT_TRACE(diff); // if there is not enough room left to pop completely off the block, then move to the next previous block // and pop from it, update the amount of bytes to reflect the amount removed from the current block - if (diff <= 0) + if (diff < 0) { bytes -= head->used_bytes_in_block(); - if (diff == 0) - break; + // reset this head's buffer. + head->metadata.offset = head->buffer; move_back(); } else { diff --git a/lib/blt b/lib/blt index 4114de7..394dff9 160000 --- a/lib/blt +++ b/lib/blt @@ -1 +1 @@ -Subproject commit 4114de74dbb46b6e8f9663e63c430e31ca2f9b00 +Subproject commit 394dff9cc4c31ea29867c5e2507edc831a34c19b diff --git a/tests/stack_tests.cpp b/tests/stack_tests.cpp index 38a4db1..7af1dac 100644 --- a/tests/stack_tests.cpp +++ b/tests/stack_tests.cpp @@ -23,6 +23,26 @@ #include #include +struct log_box +{ + public: + log_box(const std::string& text, blt::logging::logger logger): text(text), logger(logger) + { + logger << text << '\n'; + } + + ~log_box() + { + for (auto& c : text) + logger << '-'; + logger << '\n'; + } + + private: + std::string text; + blt::logging::logger logger; +}; + template T make_data(T t, Func&& func) { @@ -91,6 +111,7 @@ MAKE_VARIABLE(18290); void test_basic_types() { + log_box box("-----------------------{Stack Testing}-----------------------", BLT_INFO_STREAM); BLT_INFO("Testing pushing types, will transfer and pop off each stack."); blt::gp::stack_allocator stack; stack.push(50.0f); @@ -112,7 +133,7 @@ void test_basic_types() stack.push(base_6123); BLT_TRACE_STREAM << "Pushed 6123: " << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); { BLT_INFO("Popping 6123, int, and bool via transfer"); @@ -128,7 +149,7 @@ void test_basic_types() } BLT_TRACE_STREAM << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); BLT_INFO("Pushing new data onto partially removed stack, this will test re-allocating blocks. We will also push at least one more block."); stack.push(tertiary_256); @@ -143,7 +164,7 @@ void test_basic_types() BLT_TRACE_STREAM << "Pushed 256: " << stack.size() << "\n"; stack.push(base_18290); BLT_TRACE_STREAM << "Pushed 18290: " << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); { BLT_INFO("Popping all data via transfer."); @@ -166,7 +187,7 @@ void test_basic_types() } BLT_TRACE_STREAM << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); BLT_INFO("Now we will test using large values where the unallocated blocks do not have enough storage."); stack.push(secondary_18290); @@ -177,7 +198,7 @@ void test_basic_types() BLT_TRACE_STREAM << "Pushed 18290^: " << stack.size() << "\n"; stack.push(secondary_6123); BLT_TRACE_STREAM << "Pushed 6123*: " << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); { BLT_INFO("Popping values normally."); @@ -187,7 +208,7 @@ void test_basic_types() RUN_TEST_SIZE(secondary_18290, stack); } BLT_TRACE_STREAM << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); BLT_INFO("Some fishy numbers in the last reported size. Let's try modifying the stack."); // fixed by moving back in pop stack.push(88.9f); @@ -199,7 +220,7 @@ void test_basic_types() RUN_TEST_SIZE(secondary_256, stack); } BLT_TRACE_STREAM << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); BLT_INFO("We will now empty the stack and try to reuse it."); { @@ -210,7 +231,7 @@ void test_basic_types() RUN_TEST_TYPE(50.0f, stack); } BLT_TRACE_STREAM << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); stack.push(tertiary_18290); BLT_TRACE_STREAM << "Pushed 18290^: " << stack.size() << "\n"; @@ -218,7 +239,7 @@ void test_basic_types() BLT_TRACE_STREAM << "Pushed 4096: " << stack.size() << "\n"; stack.push(50); BLT_TRACE_STREAM << "Pushed int: " << stack.size() << "\n"; - std::cout << std::endl; + BLT_NEWLINE(); BLT_INFO("Clearing stack one final time"); RUN_TEST_TYPE(50, stack); @@ -228,28 +249,49 @@ void test_basic_types() } blt::gp::operation_t basic_2([](float a, float b) { - + return a + b; }); blt::gp::operation_t basic_mixed_4([](float a, float b, bool i, bool p) { - + return (a * (i ? 1.0f : 0.0f)) + (b * (p ? 1.0f : 0.0f)); }); blt::gp::operation_t large_256_basic_3([](const large_256& l, float a, float b) { - + blt::black_box(a); + blt::black_box(b); + return blt::black_box_ret(l); }); blt::gp::operation_t large_2048_basic_3b([](const large_2048& l, float a, bool b) { - + blt::black_box(a); + blt::black_box(b); + return blt::black_box_ret(l); }); +void test_basic() +{ + BLT_INFO("Testing basic with stack"); + { + blt::gp::stack_allocator stack; + stack.push(50.0f); + stack.push(10.0f); + 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); + BLT_TRACE_STREAM << stack.size() << "\n"; + } +} + void test_operators() { - + log_box box("-----------------------{Operator Testing}-----------------------", BLT_INFO_STREAM); + test_basic(); } int main() { test_basic_types(); + BLT_NEWLINE(); test_operators(); } \ No newline at end of file