Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 63 additions & 13 deletions test/operations-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ TEST_CASE("views swap") {

TEST_CASE("bitset::all/any/count") {
SECTION("empty") {
BitSet bs;
const BitSet bs;
CHECK(bs.all() == true);
CHECK(bs.any() == false);
CHECK(bs.count() == 0);
Expand All @@ -360,7 +360,7 @@ TEST_CASE("bitset::all/any/count") {
CAPTURE(str);

std::size_t ones = std::ranges::count(str, '1');
BitSet bs(str);
const BitSet bs(str);
CHECK(bs.all() == (ones == str.size()));
CHECK(bs.any() == (ones != 0));
CHECK(bs.count() == ones);
Expand All @@ -375,7 +375,7 @@ TEST_CASE("bitset::all/any/count") {
CAPTURE(str);

std::size_t ones = std::ranges::count(str, '1');
BitSet bs(str);
const BitSet bs(str);
CHECK(bs.all() == (ones == str.size()));
CHECK(bs.any() == (ones != 0));
CHECK(bs.count() == ones);
Expand Down Expand Up @@ -437,24 +437,34 @@ TEST_CASE("bitset comparison") {
TEST_CASE("view operations") {
BitSet bs("1110010101");

BitSet::ConstView bs_view_1 = bs.subview(0, 5);
BitSet::ConstView bs_view_2 = bs.subview(5);

CHECK((bs_view_1 & bs_view_2) == BitSet("10100"));
CHECK((bs_view_1 | bs_view_2) == BitSet("11101"));
const BitSet::ConstView bs_const_view_1 = bs.subview(0, 5);
const BitSet::ConstView bs_const_view_2 = bs.subview(5);
const BitSet::View bs_view_1 = bs.subview(0, 5);
const BitSet::View bs_view_2 = bs.subview(5);

CHECK((bs_const_view_1.subview() & bs_const_view_2) == BitSet("10100"));
CHECK((bs_const_view_1 | bs_const_view_2.subview()) == BitSet("11101"));
CHECK((bs_const_view_1 ^ bs_const_view_2) == BitSet("01001"));
CHECK((bs_const_view_2 << 2) == BitSet("1010100"));
CHECK((bs_const_view_1 >> 3) == BitSet("11"));
CHECK(~bs_const_view_1 == BitSet("00011"));
CHECK(bs_const_view_1.count() == 3);

CHECK((bs_view_1.subview() & bs_view_2) == BitSet("10100"));
CHECK((bs_view_1 | bs_view_2.subview()) == BitSet("11101"));
CHECK((bs_view_1 ^ bs_view_2) == BitSet("01001"));
CHECK((bs_view_2 << 2) == BitSet("1010100"));
CHECK((bs_view_1 >> 3) == BitSet("11"));
CHECK(~bs_view_1 == BitSet("00011"));
CHECK(bs_view_1.count() == 3);

bs.subview()[0] = false;
bs_view_1[0] = false;
CHECK(bs == BitSet("0110010101"));

bs.subview(5).flip();
bs_view_2.flip();
CHECK(bs == BitSet("0110001010"));

const BitSet::View bs_view_3 = bs.subview(2, 3);
const BitSet::View bs_view_3 = bs_view_1.subview(2, 3);
bs_view_3.set();
CHECK(bs == BitSet("0111101010"));

Expand All @@ -469,8 +479,8 @@ TEST_CASE("chained view operations") {
BitSet bs_1("0011000011");
BitSet bs_2("1110010101");

BitSet::View bs_view_1 = bs_1.subview();
BitSet::View bs_view_2 = bs_2.subview();
const BitSet::View bs_view_1 = bs_1.subview();
const BitSet::View bs_view_2 = bs_2.subview();

bs_view_1 |= bs_view_2.flip();
CHECK(bs_1 == BitSet("0011101011"));
Expand All @@ -489,4 +499,44 @@ TEST_CASE("chained view operations") {
CHECK(bs_2 == BitSet("1110010101"));
}

TEST_CASE("iterators with different constness operations") {
BitSet bs("110101");
std::ptrdiff_t i = GENERATE(0, 1, 6);
BitSet::Iterator it = bs.begin() + i;
BitSet::ConstIterator cit = bs.begin() + i;
REQUIRE(cit == it);
REQUIRE(it == cit);
REQUIRE_FALSE(cit != it);
REQUIRE_FALSE(it != cit);

std::ptrdiff_t j = GENERATE(0, 1, 6);
BitSet::Iterator it2 = bs.begin() + j;
BitSet::ConstIterator cit2 = it2;
REQUIRE(cit2 - it == j - i);
REQUIRE(it2 - cit == j - i);
}

TEST_CASE("reference with different constness operations") {
BitSet bs("110101");
std::size_t i = GENERATE(0, 1, 5);
const BitSet::Reference ref1 = bs[i];
const BitSet::ConstReference ref2 = bs[i];
REQUIRE(ref1 == ref2);
REQUIRE(ref2 == ref1);
REQUIRE_FALSE(ref1 != ref2);
REQUIRE_FALSE(ref2 != ref1);
}

TEST_CASE("view with different constness operations") {
BitSet bs("110101");
std::size_t i = GENERATE(0, 1, 4);
std::size_t len = GENERATE(0, 1);
const BitSet::View view1 = bs.subview(i, len);
const BitSet::ConstView view2 = bs.subview(i, len);
REQUIRE(view1 == view2);
REQUIRE_FALSE(view1 != view2);
REQUIRE(view2 == view1);
REQUIRE_FALSE(view2 != view1);
}

} // namespace ct::test
9 changes: 9 additions & 0 deletions test/traits-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ TEST_CASE("member types") {
STATIC_CHECK(std::is_same_v<BitSet::View::ConstReference, BitSet::ConstReference>);
STATIC_CHECK(std::is_same_v<BitSet::ConstView::Reference, BitSet::ConstReference>);
STATIC_CHECK(std::is_same_v<BitSet::ConstView::ConstReference, BitSet::ConstReference>);

STATIC_CHECK(std::is_same_v<BitSet::ConstView::Iterator, BitSet::Iterator>);
STATIC_CHECK(std::is_same_v<BitSet::ConstView::ConstIterator, BitSet::ConstIterator>);
}
}

TEST_CASE("concepts") {
STATIC_CHECK(std::random_access_iterator<BitSet::ConstIterator>);
STATIC_CHECK(std::random_access_iterator<BitSet::Iterator>);
STATIC_CHECK(std::output_iterator<BitSet::Iterator, bool>);
}

} // namespace ct::test
Loading