From 232d5fe4cdbeac724bbbd730eb6f6ed518052b44 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 5 Mar 2024 00:45:52 -0500 Subject: [PATCH] really broken --- tests/src/tests2.cpp | 50 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/src/tests2.cpp b/tests/src/tests2.cpp index dcd75d5..c88c7c0 100644 --- a/tests/src/tests2.cpp +++ b/tests/src/tests2.cpp @@ -117,17 +117,52 @@ namespace fb for (blt::i32 i = 0; i < arg_c[static_cast(info.back().type)]; i++) { if (depth >= size) + { break; - if (choice()) - stack.emplace(construct_info{random_type()}, depth + 1); - else - stack.emplace(construct_info{random_type_sub()}, depth + 1); + } else if (depth == size - 1) + { + stack.emplace(construct_info{type_t::VALUE}, depth + 1); + } else + { + if (choice()) + stack.emplace(construct_info{random_type()}, depth + 1); + else + stack.emplace(construct_info{random_type_sub()}, depth + 1); + } } } return info; } + void type_stats(const std::vector& info) + { + blt::size_t add = 0; + blt::size_t sub = 0; + blt::size_t mul = 0; + blt::size_t val = 0; + + for (const auto& v : info) + { + switch (v.type) + { + case type_t::ADD: + add++; + break; + case type_t::SUB: + sub++; + break; + case type_t::MUL: + mul++; + break; + case type_t::VALUE: + val++; + break; + } + } + BLT_INFO("We have %ld adds, %ld subs, %ld mul, %ld val", add, sub, mul, val); + } + class tree1 { public: @@ -136,7 +171,7 @@ namespace fb struct node_t { blt::bump_allocator& alloc; - std::array children{}; + std::array children{nullptr}; double value = 0; blt::i32 argc; type_t type; @@ -167,6 +202,7 @@ namespace fb { std::stack nodes; std::stack node_stack; + blt::size_t evals = 0; nodes.push(this); @@ -183,8 +219,10 @@ namespace fb { node_stack.top()->evaluate(); BLT_DEBUG(node_stack.top()->value); + evals++; node_stack.pop(); } + BLT_INFO("Evaluated %ld times", evals); return value; } @@ -381,6 +419,8 @@ namespace fb void funny() { auto info = create_info(17); + type_stats(info); + tree1 love; love.create(info); BLT_TRACE(love.evaluate());