Skip to content

Commit

Permalink
Fix fibonacci impl in benchmark tests
Browse files Browse the repository at this point in the history
The previous implementation was always 1 number ahead. Fixing this
is not important at all, but it was bugging me.
  • Loading branch information
horenmar committed Oct 18, 2022
1 parent be060cd commit 77f7c01
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/SelfTest/UsageTests/Benchmark.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down

0 comments on commit 77f7c01

Please sign in to comment.