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.
This commit is contained in:
Martin Hořeňovský 2022-10-18 10:44:10 +02:00
parent be060cde44
commit 77f7c0104d
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A

View File

@ -16,20 +16,22 @@
namespace { namespace {
std::uint64_t Fibonacci(std::uint64_t number) { 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]") { TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
CHECK(Fibonacci(0) == 1); CHECK(Fibonacci(0) == 0);
// some more asserts.. // some more asserts..
CHECK(Fibonacci(5) == 8); CHECK(Fibonacci(5) == 5);
// some more asserts.. // some more asserts..
REQUIRE( Fibonacci( 20 ) == 6'765 );
BENCHMARK( "Fibonacci 20" ) { BENCHMARK( "Fibonacci 20" ) {
return Fibonacci(20); return Fibonacci(20);
}; };
REQUIRE( Fibonacci( 25 ) == 75'025 );
BENCHMARK( "Fibonacci 25" ) { BENCHMARK( "Fibonacci 25" ) {
return Fibonacci(25); return Fibonacci(25);
}; };