From 449a89eff2d4c78e719e54f406f715309b096891 Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Fri, 14 Jun 2019 14:49:06 +0200 Subject: [PATCH] Add test for invoke. --- test/algorithm_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/algorithm_test.cpp b/test/algorithm_test.cpp index 702901a..498e169 100644 --- a/test/algorithm_test.cpp +++ b/test/algorithm_test.cpp @@ -61,3 +61,28 @@ TEST_CASE("scan functions correctly", "[algorithms/scan.h]") { REQUIRE (all_correct); }); } + +long fib(long n) { + if (n <= 2) { + return 1; + } + + long a, b; + + pls::invoke( + [&a, n]() { a = fib(n - 1); }, + [&b, n]() { b = fib(n - 2); } + ); + + return a + b; +} + +TEST_CASE("invoke functions correctly", "[algorithms/invoke.h]") { + constexpr long fib_40 = 102334155; + + malloc_scheduler_memory my_scheduler_memory{8, 2 << 12}; + scheduler my_scheduler{&my_scheduler_memory, 2}; + my_scheduler.perform_work([=]() { + REQUIRE(fib(40) == fib_40); + }); +} -- libgit2 0.26.0