Skip to content

Commit

Permalink
test: add recursive fibonacci test
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperPaul123 committed Apr 25, 2024
1 parent 9e94e28 commit 453ecae
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/source/thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,18 @@ TEST_CASE("Ensure wait_for_tasks() properly blocks current execution.") {

CHECK_EQ(counter.load(), total_tasks);
}

// see
// https://github.com/DevShiftTeam/AppShift-MemoryPool/commit/ea5908cbbd1c9163e9bc700d102e97b53e737fe5
int fib_thread_loop(int n, dp::thread_pool<>& pool) {
if (n <= 1) return n;
auto a = pool.enqueue(fib_thread_loop, n - 1, std::ref(pool));
auto b = pool.enqueue(fib_thread_loop, n - 2, std::ref(pool));
return a.get() + b.get();
}

TEST_CASE("Recursive fibonacci sequence") {
dp::thread_pool pool{};
auto result = fib_thread_loop(6, pool);
CHECK(result == 8);
}

0 comments on commit 453ecae

Please sign in to comment.