Commit c2535df3 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/fix_log2_approx_tests' into integration_2024_w40

parents 5ed1dcd2 28656a1a
......@@ -14,4 +14,4 @@ add_executable(test_log2_approx test_log2_approx.cpp ../log2_approx.c)
target_link_libraries(test_log2_approx PRIVATE GTest::gtest LOG minimal_lib)
add_dependencies(tests test_log2_approx)
add_test(NAME test_log2_approx
COMMAND ./test_log2_approx)
COMMAND ./test_log2_approx --gtest_filter=-log2_approx.complete)
......@@ -10,25 +10,27 @@ uint8_t log2_approx_ref(uint32_t x)
return std::round(std::log2(x));
}
uint8_t log2_approx64_ref(unsigned long long int x)
{
return std::round(std::log2(static_cast<long double>(x)));
}
TEST(log2_approx, complete)
{
for (uint32_t i = 0; i < UINT32_MAX; i++)
EXPECT_EQ(log2_approx(i), log2_approx_ref(i));
}
TEST(log2_approx, boundaries)
{
for (int i = 0; i < 32; i++) {
uint32_t i2 = std::pow(2.0, i + 0.5);
EXPECT_EQ(log2_approx(i2), i) << "log2(" << i2 << ")";
EXPECT_EQ(log2_approx(i2 + 1), i + 1) << "log2(" << i2 + 1 << ")";
}
}
TEST(log2_approx64, boundaries)
{
for (long double i = 0; i < 64; i++) {
unsigned long long i2 = std::pow(2.0L, i + 0.5L);
for (unsigned long long j = -10; j <= 10; j++) {
unsigned long long x = i2 + j;
EXPECT_EQ(log2_approx64(x), log2_approx64_ref(x));
}
for (int i = 0; i < 64; i++) {
unsigned long long int i2 = std::pow(2.0L, i + 0.5L);
EXPECT_EQ(log2_approx64(i2), i) << "log2(" << i2 << ")";
EXPECT_EQ(log2_approx64(i2 + 1), i + 1) << "log2(" << i2 + 1 << ")";
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment