Skip to content

Commit

Permalink
🛠 Make all conversions explicit in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Jul 17, 2022
1 parent 3670c44 commit 22bf549
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 18 deletions.
38 changes: 38 additions & 0 deletions include/itsy/detail/bit_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
::ztd::ranges::ranges_adl::adl_swap(__left.__bval, __right.__bval);
}

// comparison operators
friend constexpr bool
operator==(const __bit_value& __left, const __bit_value& __right) noexcept
{
Expand Down Expand Up @@ -360,6 +361,43 @@ namespace ITSY_BITSY_SOURCE_NAMESPACE
__right.flip();
}

// comparison operators
constexpr friend bool
operator==(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() == __right.value();
}

constexpr friend bool
operator!=(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() != __right.value();
}

constexpr friend bool
operator<(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() < __right.value();
}

constexpr friend bool
operator>(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() > __right.value();
}

constexpr friend bool
operator<=(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() <= __right.value();
}

constexpr friend bool
operator>=(const __bit_reference& __left, const __bit_reference& __right) noexcept
{
return __left.value() >= __right.value();
}

private:
_WordRef _M_word;
mask_type _M_mask;
Expand Down
4 changes: 2 additions & 2 deletions tests/include/itsy/tests/shared_allocator_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace bitsy::tests
{
const auto& expected_val = *source_first;
const auto& val = *first;
REQUIRE(val == expected_val);
REQUIRE(val.value() == expected_val);
}
}
else
Expand All @@ -120,7 +120,7 @@ namespace bitsy::tests
{
const auto& expected_val = *source_first;
const auto& val = *first;
REQUIRE(val == expected_val);
REQUIRE(val.value() == expected_val.value());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/include/itsy/tests/shared_insert_erase_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ bit_sequence_insert_erase_test(BitSequence& bs)
REQUIRE(bs.size() == pre_insert_size);
{
auto bs_it = bs.begin();
REQUIRE(*bs_it == false);
REQUIRE(*bs_it == bitsy::bit0);
++bs_it;
REQUIRE(*bs_it == false);
REQUIRE(*bs_it == bitsy::bit0);
++bs_it;
REQUIRE(bs_it == bs.cend());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/include/itsy/tests/shared_insert_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace bitsy::tests
std::size_t seq_size = sequence.size();
for (std::size_t i = 0; i < source.size(); ++i)
{
bool val = source[i];
bool bool_val = source[i];
const bitsy::bit_value val = bool_val;
if constexpr (action == insert_action::push_front)
{
sequence.push_front(val);
Expand Down
26 changes: 13 additions & 13 deletions tests/include/itsy/tests/shared_tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto flip_index_bit = span_bits[flip_index];
REQUIRE(flip_index_bit);
REQUIRE(flip_index_bit == span_bits.test(flip_index));
REQUIRE(flip_index_bit.value() == span_bits.test(flip_index));
span_bits.flip(flip_index);
REQUIRE_FALSE(flip_index_bit);
REQUIRE(flip_index_bit == span_bits.test(flip_index));
REQUIRE(flip_index_bit.value() == span_bits.test(flip_index));
}

REQUIRE(span_bits.one_count() == post_expected_on_bits);
Expand All @@ -163,10 +163,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto flip_index_bit = span_bits[flip_index];
REQUIRE_FALSE(flip_index_bit);
REQUIRE(flip_index_bit == span_bits.test(flip_index));
REQUIRE(flip_index_bit.value() == span_bits.test(flip_index));
flip_index_bit = !static_cast<bool>(flip_index_bit);
REQUIRE(flip_index_bit);
REQUIRE(flip_index_bit == span_bits.test(flip_index));
REQUIRE(flip_index_bit.value());
REQUIRE(flip_index_bit.value() == span_bits.test(flip_index));
}

REQUIRE(span_bits.one_count() == initial_expected_on_bits);
Expand All @@ -177,10 +177,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto set_index_bit = span_bits[set_index];
REQUIRE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
span_bits.set(set_index, false);
REQUIRE_FALSE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
}

REQUIRE(span_bits.one_count() == post_expected_on_bits);
Expand All @@ -191,10 +191,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto set_index_bit = span_bits[set_index];
REQUIRE_FALSE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
span_bits.set(set_index, true);
REQUIRE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
}

REQUIRE(span_bits.one_count() == initial_expected_on_bits);
Expand All @@ -205,10 +205,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto set_index_bit = span_bits[set_index];
REQUIRE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
span_bits[set_index] = false;
REQUIRE_FALSE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
}

REQUIRE(span_bits.one_count() == post_expected_on_bits);
Expand All @@ -219,10 +219,10 @@ bit_view_test_writability(BitSpan& span_bits, On& on_indices,
{
auto set_index_bit = span_bits[set_index];
REQUIRE_FALSE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
span_bits[set_index] = true;
REQUIRE(set_index_bit);
REQUIRE(set_index_bit == span_bits.test(set_index));
REQUIRE(set_index_bit.value() == span_bits.test(set_index));
}

REQUIRE(span_bits.popcount() == initial_expected_on_bits);
Expand Down

0 comments on commit 22bf549

Please sign in to comment.