Unconditionally use FindFirstBit in SetBitIterator
Add simple tests
This commit is contained in:
@@ -51,3 +51,22 @@ TEST_CASE("FindLastBit tests")
|
||||
CHECK(FindLastBit(0x42U) == FindLastBit(0x40U));
|
||||
CHECK(FindLastBit(0xAAAAU) == FindLastBit(0x8000U));
|
||||
}
|
||||
|
||||
TEST_CASE("SetBitIterator tests")
|
||||
{
|
||||
auto test_case = [&](auto input, std::initializer_list<uint> expected) {
|
||||
auto iter = expected.begin();
|
||||
for (auto bit : SetBitIterator(input)) {
|
||||
if (iter == expected.end()) return false;
|
||||
if (bit != *iter) return false;
|
||||
++iter;
|
||||
}
|
||||
return iter == expected.end();
|
||||
};
|
||||
CHECK(test_case(0, {}));
|
||||
CHECK(test_case(1, { 0 }));
|
||||
CHECK(test_case(42, { 1, 3, 5 }));
|
||||
CHECK(test_case(0x8080FFFFU, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 23, 31 }));
|
||||
CHECK(test_case(INT32_MIN, { 31 }));
|
||||
CHECK(test_case(INT64_MIN, { 63 }));
|
||||
}
|
||||
|
Reference in New Issue
Block a user