Commit 4b679c07 authored by Thomas Schlichter's avatar Thomas Schlichter Committed by francescomani

add test for log2_approx64()

parent 58a29664
......@@ -10,12 +10,28 @@ uint8_t log2_approx_ref(uint32_t x)
return std::round(std::log2(x));
}
TEST(log2_approx_ref, complete)
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_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));
}
}
}
int main(int argc, char **argv)
{
logInit();
......
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