Skip to content

Commit 453ecae

Browse files
test: add recursive fibonacci test
1 parent 9e94e28 commit 453ecae

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/source/thread_pool.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,18 @@ TEST_CASE("Ensure wait_for_tasks() properly blocks current execution.") {
445445

446446
CHECK_EQ(counter.load(), total_tasks);
447447
}
448+
449+
// see
450+
// https://github.com/DevShiftTeam/AppShift-MemoryPool/commit/ea5908cbbd1c9163e9bc700d102e97b53e737fe5
451+
int fib_thread_loop(int n, dp::thread_pool<>& pool) {
452+
if (n <= 1) return n;
453+
auto a = pool.enqueue(fib_thread_loop, n - 1, std::ref(pool));
454+
auto b = pool.enqueue(fib_thread_loop, n - 2, std::ref(pool));
455+
return a.get() + b.get();
456+
}
457+
458+
TEST_CASE("Recursive fibonacci sequence") {
459+
dp::thread_pool pool{};
460+
auto result = fib_thread_loop(6, pool);
461+
CHECK(result == 8);
462+
}

0 commit comments

Comments
 (0)