Skip to content

Commit

Permalink
add exhaustive Bitmask::has_true() test
Browse files Browse the repository at this point in the history
  • Loading branch information
shaomeng committed Mar 20, 2024
1 parent 0d65989 commit 4ba73ac
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test_scripts/bitstream_unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,33 @@ TEST(Bitmask, has_true_remaining)
EXPECT_EQ(mask.has_true(1, 260), true);
}

TEST(Bitmask, has_true_exhaustive)
{
const size_t mask_size = 130;

// Loop over all positions
for (size_t idx = 0; idx < mask_size; idx++) {
auto mask = Mask(mask_size);
mask.wtrue(idx);

// Loop over all starting positions
for (size_t start = 0; start < mask_size; start++) {

// Loop over all range length
for (size_t len = 0; len < mask_size - start; len++) {
bool ans1 = mask.has_true(start, len);
bool ans2 = false;
for (size_t i = start; i < start + len; i++)
if (mask.rbit(i)) {
ans2 = true;
break;
}
EXPECT_EQ(ans1, ans2);
}

}
}
}

#if defined __cpp_lib_three_way_comparison && defined __cpp_impl_three_way_comparison
TEST(Bitmask, spaceship)
Expand Down

0 comments on commit 4ba73ac

Please sign in to comment.