UnitTests: Add basic tests for RotateRight() and RotateLeft()

This commit is contained in:
Lioncash 2018-03-31 17:30:00 -04:00
parent c3483a1823
commit 136f16599f
1 changed files with 38 additions and 0 deletions

View File

@ -58,6 +58,44 @@ TEST(BitUtils, ExtractBits)
EXPECT_EQ((Common::ExtractBits<0, 31, s32, s32>(negative_one)), -1); EXPECT_EQ((Common::ExtractBits<0, 31, s32, s32>(negative_one)), -1);
} }
TEST(BitUtils, RotateLeft)
{
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 0), 0xF0F0F0F0);
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 4), 0x0F0F0F0F);
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0, 8), 0xF0F0F0F0);
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0);
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0F);
EXPECT_EQ(Common::RotateLeft(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 1), 0xE3E3E3E3);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 2), 0xC7C7C7C7);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 3), 0x8F8F8F8F);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1, 4), 0x1F1F1F1F);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 1), 0xE3E3E3E3E3E3E3E3);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 2), 0xC7C7C7C7C7C7C7C7);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 3), 0x8F8F8F8F8F8F8F8F);
EXPECT_EQ(Common::RotateLeft(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1F);
}
TEST(BitUtils, RotateRight)
{
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 0), 0xF0F0F0F0);
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 4), 0x0F0F0F0F);
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0, 8), 0xF0F0F0F0);
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 0), 0xF0F0F0F0F0F0F0F0);
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 4), 0x0F0F0F0F0F0F0F0F);
EXPECT_EQ(Common::RotateRight(0xF0F0F0F0F0F0F0F0, 8), 0xF0F0F0F0F0F0F0F0);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 1), 0xF8F8F8F8);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 2), 0x7C7C7C7C);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 3), 0x3E3E3E3E);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1, 4), 0x1F1F1F1F);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 1), 0xF8F8F8F8F8F8F8F8);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 2), 0x7C7C7C7C7C7C7C7C);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 3), 0x3E3E3E3E3E3E3E3E);
EXPECT_EQ(Common::RotateRight(0xF1F1F1F1F1F1F1F1, 4), 0x1F1F1F1F1F1F1F1F);
}
TEST(BitUtils, IsValidLowMask) TEST(BitUtils, IsValidLowMask)
{ {
EXPECT_TRUE(Common::IsValidLowMask(0b0u)); EXPECT_TRUE(Common::IsValidLowMask(0b0u));