mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Merge 5d75d6603701b2d4bc3a45095201f4d6ebe77119 into 60ba92928e8af3441f2a4eea5f18fd2563d98ad0
This commit is contained in:
commit
4ae3eced70
@ -554,17 +554,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Flip all of the bits.
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t /*number_of_elements*/, element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
*pbuffer = ~*pbuffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Flip some of the bits.
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void flip_bits(pointer pbuffer, element_type mask = etl::integral_limits<element_type>::max) ETL_NOEXCEPT
|
||||
{
|
||||
*pbuffer ^= mask;
|
||||
*pbuffer = (~*pbuffer) & top_mask;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -673,19 +665,11 @@ namespace etl
|
||||
*lhs_pbuffer ^= *rhs_pbuffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// operator ~
|
||||
/// NOT the value in the buffer
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t /*number_of_elements*/) ETL_NOEXCEPT
|
||||
{
|
||||
*pbuffer = ~*pbuffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// operator_shift_left
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t /*number_of_elements*/, size_t active_bits, size_t shift,
|
||||
element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
if (shift >= active_bits)
|
||||
{
|
||||
@ -694,6 +678,7 @@ namespace etl
|
||||
else
|
||||
{
|
||||
*pbuffer <<= shift;
|
||||
*pbuffer &= top_mask;
|
||||
}
|
||||
}
|
||||
|
||||
@ -724,9 +709,10 @@ namespace etl
|
||||
/// Initialise from an unsigned long long.
|
||||
//*************************************************************************
|
||||
template <typename TElementType>
|
||||
static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t /*number_of_elements*/, unsigned long long value) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void initialise(pointer pbuffer, size_t /*number_of_elements*/, unsigned long long value, TElementType top_mask)
|
||||
ETL_NOEXCEPT
|
||||
{
|
||||
*pbuffer = static_cast<TElementType>(value);
|
||||
*pbuffer = static_cast<TElementType>(value) & top_mask;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1253,9 +1239,9 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Flip all of the bits.
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void flip_all(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
operator_not(pbuffer, number_of_elements);
|
||||
operator_not(pbuffer, number_of_elements, top_mask);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1398,19 +1384,23 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// operator not
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void operator_not(pointer pbuffer, size_t number_of_elements, element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
while (number_of_elements-- != 0)
|
||||
{
|
||||
*pbuffer = ~*pbuffer;
|
||||
++pbuffer;
|
||||
}
|
||||
|
||||
--pbuffer; // Step back to the last element.
|
||||
*pbuffer &= top_mask; // Clear unused bits.
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// operator_shift_left
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift) ETL_NOEXCEPT
|
||||
static ETL_CONSTEXPR14 void operator_shift_left(pointer pbuffer, size_t number_of_elements, size_t active_bits, size_t shift,
|
||||
element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
if (shift >= active_bits)
|
||||
{
|
||||
@ -1463,6 +1453,8 @@ namespace etl
|
||||
{
|
||||
pbuffer[i] = 0;
|
||||
}
|
||||
|
||||
pbuffer[(number_of_elements - 1U)] &= top_mask;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1543,7 +1535,7 @@ namespace etl
|
||||
template <typename TElementType>
|
||||
static
|
||||
ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits == etl::integral_limits<unsigned long long>::bits, void>::type
|
||||
initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
|
||||
initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value, TElementType top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
size_t i = 0UL;
|
||||
|
||||
@ -1555,6 +1547,8 @@ namespace etl
|
||||
{
|
||||
pbuffer[i++] = All_Clear_Element;
|
||||
}
|
||||
|
||||
pbuffer[number_of_elements - 1] &= top_mask;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1565,7 +1559,7 @@ namespace etl
|
||||
template <typename TElementType>
|
||||
static
|
||||
ETL_CONSTEXPR14 typename etl::enable_if< etl::integral_limits<TElementType>::bits != etl::integral_limits<unsigned long long>::bits, void>::type
|
||||
initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value) ETL_NOEXCEPT
|
||||
initialise(pointer pbuffer, size_t number_of_elements, unsigned long long value, element_type top_mask) ETL_NOEXCEPT
|
||||
{
|
||||
size_t i = 0UL;
|
||||
|
||||
@ -1583,6 +1577,8 @@ namespace etl
|
||||
{
|
||||
pbuffer[i++] = All_Clear_Element;
|
||||
}
|
||||
|
||||
pbuffer[number_of_elements - 1] &= top_mask;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -1815,7 +1811,7 @@ namespace etl
|
||||
ETL_CONSTEXPR14 bitset(TValue value, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
|
||||
: buffer()
|
||||
{
|
||||
implementation::template initialise<element_type>(buffer, Number_Of_Elements, static_cast<unsigned long long>(value));
|
||||
implementation::template initialise<element_type>(buffer, Number_Of_Elements, static_cast<unsigned long long>(value), Top_Mask);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2248,7 +2244,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 bitset<Active_Bits, TElement>& flip() ETL_NOEXCEPT
|
||||
{
|
||||
implementation::flip_all(buffer, Number_Of_Elements);
|
||||
implementation::flip_all(buffer, Number_Of_Elements, Top_Mask);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -2389,7 +2385,7 @@ namespace etl
|
||||
{
|
||||
etl::bitset<Active_Bits, TElement> temp(*this);
|
||||
|
||||
implementation::flip_all(temp.buffer, Number_Of_Elements);
|
||||
implementation::flip_all(temp.buffer, Number_Of_Elements, Top_Mask);
|
||||
|
||||
return temp;
|
||||
}
|
||||
@ -2401,7 +2397,7 @@ namespace etl
|
||||
{
|
||||
etl::bitset<Active_Bits, TElement> temp(*this);
|
||||
|
||||
implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift);
|
||||
implementation::operator_shift_left(temp.buffer, Number_Of_Elements, Active_Bits, shift, Top_Mask);
|
||||
|
||||
return temp;
|
||||
}
|
||||
@ -2417,7 +2413,7 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift);
|
||||
implementation::operator_shift_left(buffer, Number_Of_Elements, Active_Bits, shift, Top_Mask);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -2754,7 +2750,7 @@ namespace etl
|
||||
: pbuffer(pbuffer_)
|
||||
{
|
||||
ETL_ASSERT(pbuffer != ETL_NULLPTR, ETL_ERROR(etl::bitset_invalid_buffer));
|
||||
implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value);
|
||||
implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, value, Top_Mask);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2764,7 +2760,7 @@ namespace etl
|
||||
ETL_CONSTEXPR14 bitset_ext(TValue value, buffer_type& buffer, typename etl::enable_if<is_integral<TValue>::value>::type* = 0) ETL_NOEXCEPT
|
||||
: pbuffer(buffer.data())
|
||||
{
|
||||
implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, static_cast<unsigned long long>(value));
|
||||
implementation::template initialise<element_type>(pbuffer, Number_Of_Elements, static_cast<unsigned long long>(value), Top_Mask);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -3245,7 +3241,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& flip() ETL_NOEXCEPT
|
||||
{
|
||||
implementation::flip_all(pbuffer, Number_Of_Elements);
|
||||
implementation::flip_all(pbuffer, Number_Of_Elements, Top_Mask);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -3348,7 +3344,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 bitset_ext<Active_Bits, TElement>& operator<<=(size_t shift) ETL_NOEXCEPT
|
||||
{
|
||||
implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift);
|
||||
implementation::operator_shift_left(pbuffer, Number_Of_Elements, Active_Bits, shift, Top_Mask);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -1505,13 +1505,13 @@ namespace
|
||||
{
|
||||
etl::bitset<5U> bits;
|
||||
std::bitset<5U> stdbits;
|
||||
etl::bitset<5U> negbits = ~bits;
|
||||
std::bitset<5U> stdnegbits = ~stdbits;
|
||||
etl::bitset<5U> negated_bits = ~bits;
|
||||
std::bitset<5U> stdnegbits = ~stdbits;
|
||||
|
||||
CHECK_EQUAL(stdbits.count(), bits.count());
|
||||
CHECK_EQUAL(stdbits.all(), bits.all());
|
||||
CHECK_EQUAL(stdnegbits.count(), negbits.count());
|
||||
CHECK_EQUAL(stdnegbits.all(), negbits.all());
|
||||
CHECK_EQUAL(stdnegbits.count(), negated_bits.count());
|
||||
CHECK_EQUAL(stdnegbits.all(), negated_bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -310,6 +310,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -325,6 +327,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -340,6 +344,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -355,17 +361,59 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_nullptr_char_string)
|
||||
TEST(test_construct_from_64_bit_char_string_where_the_bitset_size_is_60)
|
||||
{
|
||||
const char* s = nullptr;
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset<60> data("110001001000110100010101100111001100010010001101000101011001");
|
||||
|
||||
etl::bitset<60> data(s);
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_69_bit_char_string_where_the_bitset_size_is_64)
|
||||
{
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset<64> data("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_64_bit_char_string_where_the_bitset_size_is_60)
|
||||
{
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset<60> data("110001001000110100010101100111001100010010001101000101011001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
CHECK_EQUAL(60, data.size());
|
||||
CHECK_EQUAL(0, data.count());
|
||||
CHECK_EQUAL(0, data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -377,6 +425,7 @@ namespace
|
||||
|
||||
CHECK_EQUAL(60, data.size());
|
||||
CHECK_EQUAL(0, data.count());
|
||||
CHECK_EQUAL(0, data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -388,6 +437,7 @@ namespace
|
||||
|
||||
CHECK_EQUAL(60, data.size());
|
||||
CHECK_EQUAL(0, data.count());
|
||||
CHECK_EQUAL(0, data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -399,26 +449,7 @@ namespace
|
||||
|
||||
CHECK_EQUAL(60, data.size());
|
||||
CHECK_EQUAL(0, data.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset<64> data("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
CHECK_EQUAL(0, data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2710,5 +2741,110 @@ namespace
|
||||
|
||||
CHECK_EQUAL(32, ETL_OR_STD17::size(b));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_flip)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint8_t>;
|
||||
|
||||
Bitset bits;
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(0, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
|
||||
// Copy flipped bits to a new bitset.
|
||||
Bitset negated_bits = ~bits;
|
||||
|
||||
CHECK_EQUAL(Size, negated_bits.count());
|
||||
CHECK_TRUE(negated_bits.all());
|
||||
|
||||
// Flip the bits in the original bitset.
|
||||
bits.flip();
|
||||
|
||||
CHECK_EQUAL(11, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint8_t>;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = Bitset::Allocated_Bits - Size;
|
||||
|
||||
bits = bits << shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift_equals)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint8_t>;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(bits.Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = bits.Allocated_Bits - Size;
|
||||
|
||||
bits <<= shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_initial_value)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint8_t>;
|
||||
|
||||
const unsigned long long Initial = std::numeric_limits<uint16_t>::max();
|
||||
const unsigned long long Expected = ((1ULL << Size) - 1);
|
||||
|
||||
// Create a bitset from a value larger than the bitset size.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Expected, bits.to_ullong());
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -307,6 +307,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -322,6 +324,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -337,6 +341,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -352,6 +358,47 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_64_bit_char_string_where_the_bitset_size_is_60)
|
||||
{
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset<60, uint64_t> data("110001001000110100010101100111001100010010001101000101011001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_69_bit_char_string_where_the_bitset_size_is_64)
|
||||
{
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset<64, uint64_t> data("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -412,26 +459,11 @@ namespace
|
||||
CHECK_EQUAL(0U, data_wchar.count());
|
||||
CHECK_EQUAL(0U, data_u16.count());
|
||||
CHECK_EQUAL(0U, data_u32.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset<64, uint64_t> data("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
CHECK_EQUAL(0U, data_char.to_ullong());
|
||||
CHECK_EQUAL(0U, data_wchar.to_ullong());
|
||||
CHECK_EQUAL(0U, data_u16.to_ullong());
|
||||
CHECK_EQUAL(0U, data_u32.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2840,5 +2872,110 @@ namespace
|
||||
|
||||
CHECK_EQUAL(32, ETL_OR_STD17::size(b));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_flip)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint16_t>;
|
||||
|
||||
Bitset bits;
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(0, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
|
||||
// Copy flipped bits to a new bitset.
|
||||
Bitset negated_bits = ~bits;
|
||||
|
||||
CHECK_EQUAL(Size, negated_bits.count());
|
||||
CHECK_TRUE(negated_bits.all());
|
||||
|
||||
// Flip the bits in the original bitset.
|
||||
bits.flip();
|
||||
|
||||
CHECK_EQUAL(11, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint16_t>;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = Bitset::Allocated_Bits - Size;
|
||||
|
||||
bits = bits << shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift_equals)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint16_t>;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(bits.Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = bits.Allocated_Bits - Size;
|
||||
|
||||
bits <<= shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_initial_value)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset<Size, uint16_t>;
|
||||
|
||||
const unsigned long long Initial = std::numeric_limits<uint16_t>::max();
|
||||
const unsigned long long Expected = ((1ULL << Size) - 1);
|
||||
|
||||
// Create a bitset from a value larger than the bitset size.
|
||||
Bitset bits(Initial);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Expected, bits.to_ullong());
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -251,6 +251,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -267,6 +269,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -283,6 +287,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -299,6 +305,49 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_64_bit_char_string_where_the_bitset_size_is_60)
|
||||
{
|
||||
etl::bitset_ext<64>::buffer_type buffer;
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset_ext<60> data("110001001000110100010101100111001100010010001101000101011001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_69_bit_char_string_where_the_bitset_size_is_64)
|
||||
{
|
||||
etl::bitset_ext<64>::buffer_type buffer;
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset_ext<64> data("110001001000110100010101100111001100010010001101000101011001111100001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -349,27 +398,6 @@ namespace
|
||||
CHECK_EQUAL(0, data.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
etl::bitset_ext<64>::buffer_type buffer;
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset_ext<64> data("110001001000110100010101100111001100010010001101000101011001111100001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_set)
|
||||
{
|
||||
@ -2460,5 +2488,85 @@ namespace
|
||||
|
||||
CHECK_EQUAL(32, ETL_OR_STD17::size(b));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_flip)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint8_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
Buffer buffer1;
|
||||
Bitset bits(buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(0, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
|
||||
// Copy flipped bits to a new bitset.
|
||||
// Copy flipped bits to a new bitset.
|
||||
Buffer buffer2;
|
||||
Bitset negated_bits(bits.flip(), buffer2);
|
||||
|
||||
CHECK_EQUAL(Size, negated_bits.count());
|
||||
CHECK_TRUE(negated_bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift_equals)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint8_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Buffer buffer1;
|
||||
Bitset bits(Initial, buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(bits.Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = bits.Allocated_Bits - Size;
|
||||
|
||||
bits <<= shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_initial_value)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint8_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
const unsigned long long Initial = std::numeric_limits<uint16_t>::max();
|
||||
const unsigned long long Expected = ((1ULL << Size) - 1);
|
||||
|
||||
// Create a bitset from a value larger than the bitset size.
|
||||
Buffer buffer1;
|
||||
Bitset bits(Initial, buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements > 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Expected, bits.to_ullong());
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -279,6 +279,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -295,6 +297,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -311,6 +315,8 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -327,6 +333,47 @@ namespace
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_64_bit_char_string_where_the_bitset_size_is_60)
|
||||
{
|
||||
etl::bitset_ext<64, uint64_t>::buffer_type buffer;
|
||||
std::bitset<60> compare("110001001000110100010101100111001100010010001101000101011001");
|
||||
etl::bitset_ext<60, uint64_t> data("110001001000110100010101100111001100010010001101000101011001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_69_bit_char_string_where_the_bitset_size_is_64)
|
||||
{
|
||||
etl::bitset_ext<64, uint64_t>::buffer_type buffer;
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset_ext<64, uint64_t> data("110001001000110100010101100111001100010010001101000101011001111100001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -377,27 +424,6 @@ namespace
|
||||
CHECK_EQUAL(0, data.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
etl::bitset_ext<64, uint64_t>::buffer_type buffer;
|
||||
std::bitset<64> compare("110001001000110100010101100111001100010010001101000101011001111100001");
|
||||
etl::bitset_ext<64, uint64_t> data("110001001000110100010101100111001100010010001101000101011001111100001", buffer);
|
||||
|
||||
CHECK_EQUAL(compare.size(), data.size());
|
||||
CHECK_EQUAL(compare.count(), data.count());
|
||||
CHECK_EQUAL(compare.none(), data.none());
|
||||
CHECK_EQUAL(compare.any(), data.any());
|
||||
CHECK_EQUAL(compare.all(), data.all());
|
||||
|
||||
CHECK_EQUAL_HEX(compare.to_ullong(), data.to_ullong());
|
||||
|
||||
for (size_t i = 0UL; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(compare.test(i), data.test(i));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_set)
|
||||
{
|
||||
@ -2628,5 +2654,85 @@ namespace
|
||||
|
||||
CHECK_EQUAL(32, ETL_OR_STD17::size(b));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_flip)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint16_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
Buffer buffer1;
|
||||
Bitset bits(buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(0, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
|
||||
// Copy flipped bits to a new bitset.
|
||||
// Copy flipped bits to a new bitset.
|
||||
Buffer buffer2;
|
||||
Bitset negated_bits(bits.flip(), buffer2);
|
||||
|
||||
CHECK_EQUAL(Size, negated_bits.count());
|
||||
CHECK_TRUE(negated_bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_left_shift_equals)
|
||||
{
|
||||
const int Size = 11;
|
||||
const unsigned long long Initial = (1ULL << Size) - 1;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint16_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
// Create a bitset with all bits set to 1.
|
||||
Buffer buffer1;
|
||||
Bitset bits(Initial, buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(bits.Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
|
||||
// The amount to shift so that the value is moved to the msb of the storage.
|
||||
size_t shift_amount = bits.Allocated_Bits - Size;
|
||||
|
||||
bits <<= shift_amount;
|
||||
|
||||
CHECK_EQUAL(Size - shift_amount, bits.count());
|
||||
CHECK_FALSE(bits.all());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_497_for_initial_value)
|
||||
{
|
||||
const int Size = 11;
|
||||
|
||||
using Bitset = etl::bitset_ext<Size, uint16_t>;
|
||||
using Buffer = Bitset::buffer_type;
|
||||
|
||||
const unsigned long long Initial = std::numeric_limits<uint16_t>::max();
|
||||
const unsigned long long Expected = ((1ULL << Size) - 1);
|
||||
|
||||
// Create a bitset from a value larger than the bitset size.
|
||||
Buffer buffer1;
|
||||
Bitset bits(Initial, buffer1);
|
||||
|
||||
// Ensure that we are using multiple elements for the bitset.
|
||||
CHECK_TRUE(Bitset::Number_Of_Elements == 1);
|
||||
|
||||
// Check the initial state of the bitset.
|
||||
CHECK_EQUAL(Expected, bits.to_ullong());
|
||||
CHECK_EQUAL(Size, bits.count());
|
||||
CHECK_TRUE(bits.all());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user