From 2c604fc4b0892be0b35738ab1a608578be5996cb Mon Sep 17 00:00:00 2001 From: Paul T Date: Thu, 11 Apr 2024 08:14:44 -0400 Subject: [PATCH] test: add recursive fibonacci test --- test/source/thread_pool.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/source/thread_pool.cpp b/test/source/thread_pool.cpp index 38a31a6..9ae5ea1 100644 --- a/test/source/thread_pool.cpp +++ b/test/source/thread_pool.cpp @@ -346,3 +346,18 @@ TEST_CASE("Recursive parallel sort") { CHECK(std::ranges::is_sorted(data)); } + +// 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); +}