diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-05-13 20:04:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-17 09:08:53 +0200 |
commit | d194011570cca93324137e3c697e7f95f2638fe6 (patch) | |
tree | a342be523b1219245148a4f4aeeb719726bdee9d /Tests | |
parent | 8434d7602786dd7752124f4f2649ff4990759177 (diff) | |
download | serenity-d194011570cca93324137e3c697e7f95f2638fe6.zip |
AK: Add `count_required_bits`
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/TestBuiltinWrappers.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Tests/AK/TestBuiltinWrappers.cpp b/Tests/AK/TestBuiltinWrappers.cpp index 87b0769b7c..f630e007ea 100644 --- a/Tests/AK/TestBuiltinWrappers.cpp +++ b/Tests/AK/TestBuiltinWrappers.cpp @@ -52,3 +52,16 @@ TEST_CASE(wrapped_count_trailing_zeroes) EXPECT_EQ(count_trailing_zeroes(static_cast<u64>(1)), 0); EXPECT_EQ(count_trailing_zeroes(static_cast<u64>(2)), 1); } + +TEST_CASE(wrapped_count_required_bits) +{ + EXPECT_EQ(count_required_bits(0b0u), 1ul); + EXPECT_EQ(count_required_bits(0b1u), 1ul); + EXPECT_EQ(count_required_bits(0b10u), 2ul); + EXPECT_EQ(count_required_bits(0b11u), 2ul); + EXPECT_EQ(count_required_bits(0b100u), 3ul); + EXPECT_EQ(count_required_bits(0b111u), 3ul); + EXPECT_EQ(count_required_bits(0b1000u), 4ul); + EXPECT_EQ(count_required_bits(0b1111u), 4ul); + EXPECT_EQ(count_required_bits(NumericLimits<u32>::max()), sizeof(u32) * 8); +} |