Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Fix fibonacci impl in benchmark tests

The previous implementation was always 1 number ahead. Fixing this
is not important at all, but it was bugging me.
Commit
77f7c0104dbaa43c31e75147cfdbd4142484914b
Author
Martin Hořeňovský ·
Parents
be060cde446d

Files · Download .tar.gz

Changes

 tests/SelfTest/UsageTests/Benchmark.tests.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/SelfTest/UsageTests/Benchmark.tests.cpp b/tests/SelfTest/UsageTests/Benchmark.tests.cpp
index ffedc9a2..275611fd 100644
--- a/tests/SelfTest/UsageTests/Benchmark.tests.cpp
+++ b/tests/SelfTest/UsageTests/Benchmark.tests.cpp
@@ -16,21 +16,23 @@
 
 namespace {
     std::uint64_t Fibonacci(std::uint64_t number) {
-        return number < 2 ? 1 : Fibonacci(number - 1) + Fibonacci(number - 2);
+        return number < 2 ? number : Fibonacci(number - 1) + Fibonacci(number - 2);
     }
 }
 
 TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
-    CHECK(Fibonacci(0) == 1);
+    CHECK(Fibonacci(0) == 0);
     // some more asserts..
-    CHECK(Fibonacci(5) == 8);
+    CHECK(Fibonacci(5) == 5);
     // some more asserts..
 
-    BENCHMARK("Fibonacci 20") {
+    REQUIRE( Fibonacci( 20 ) == 6'765 );
+    BENCHMARK( "Fibonacci 20" ) {
         return Fibonacci(20);
     };
 
-    BENCHMARK("Fibonacci 25") {
+    REQUIRE( Fibonacci( 25 ) == 75'025 );
+    BENCHMARK( "Fibonacci 25" ) {
         return Fibonacci(25);
     };