34 lines
1.2 KiB
C++
34 lines
1.2 KiB
C++
// ----------------------------------------------------------------------------
|
|
// Unit test for the file core/math/BitTweak.h
|
|
// ----------------------------------------------------------------------------
|
|
#include "precompiled_unittests_core.h"
|
|
|
|
#include "core/math/BitTweak.h"
|
|
|
|
namespace ITF
|
|
{
|
|
|
|
TEST(BitTweak, test_countLeadingZero)
|
|
{
|
|
EXPECT_EQ(2U, BitTweak::countLeadingZero(0x36A70D03));
|
|
EXPECT_EQ(1U, BitTweak::countLeadingZero(0x5D430A16));
|
|
EXPECT_EQ(4U, BitTweak::countLeadingZero(0x0C5A5D10));
|
|
EXPECT_EQ(0U, BitTweak::countLeadingZero(0x848113FB));
|
|
EXPECT_EQ(1U, BitTweak::countLeadingZero(0x63E19535));
|
|
EXPECT_EQ(0U, BitTweak::countLeadingZero(0xC7F2527A));
|
|
EXPECT_EQ(32U, BitTweak::countLeadingZero(0));
|
|
}
|
|
|
|
|
|
TEST(BitTweak, test_countBits)
|
|
{
|
|
EXPECT_EQ(0U, BitTweak::countBits(0));
|
|
EXPECT_EQ(4U, BitTweak::countBits<i8>(0x1D));
|
|
EXPECT_EQ(16U, BitTweak::countBits<i16>(-1));
|
|
EXPECT_EQ(9U, BitTweak::countBits<u16>(0x36A7));
|
|
EXPECT_EQ(12U, BitTweak::countBits<i32>(0x2D430A16));
|
|
EXPECT_EQ(16U, BitTweak::countBits<u32>(0x63E19535U));
|
|
EXPECT_EQ(26U, BitTweak::countBits<u64>(0x848113FB0C5A5D10));
|
|
}
|
|
|
|
} // namespace ITF
|