Skip to content

Commit 2c604fc

Browse files
test: add recursive fibonacci test
1 parent 91b2f12 commit 2c604fc

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
@@ -346,3 +346,18 @@ TEST_CASE("Recursive parallel sort") {
346346

347347
CHECK(std::ranges::is_sorted(data));
348348
}
349+
350+
// see
351+
// https://github.com/DevShiftTeam/AppShift-MemoryPool/commit/ea5908cbbd1c9163e9bc700d102e97b53e737fe5
352+
int fib_thread_loop(int n, dp::thread_pool<>& pool) {
353+
if (n <= 1) return n;
354+
auto a = pool.enqueue(fib_thread_loop, n - 1, std::ref(pool));
355+
auto b = pool.enqueue(fib_thread_loop, n - 2, std::ref(pool));
356+
return a.get() + b.get();
357+
}
358+
359+
TEST_CASE("Recursive fibonacci sequence") {
360+
dp::thread_pool pool{};
361+
auto result = fib_thread_loop(6, pool);
362+
CHECK(result == 8);
363+
}

0 commit comments

Comments
 (0)