mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
Added tests
This commit is contained in:
@@ -1250,6 +1250,24 @@ bool <a id="none">none</a>() const
|
||||
returns <tt>false</tt>.<br />
|
||||
<b>Throws:</b> nothing.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
bool <a id="at">at</a>(size_type n) const
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n < this->size()</tt>.<br />
|
||||
<b>Returns:</b> The same as <tt>operator[](n)</tt>.<br />
|
||||
<b>Throws:</b> <tt>std::out_of_range</tt> if that <tt>n</tt> is not within the range of the bitset.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
reference <a id="at">at</a>(size_type n)
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n < this->size()</tt>.<br />
|
||||
<b>Returns:</b> The same as <tt>operator[](n)</tt>.<br />
|
||||
<b>Throws:</b> <tt>std::out_of_range</tt> if that <tt>n</tt> is not within the range of the bitset.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
bool <a id="test">test</a>(size_type n) const
|
||||
|
||||
@@ -1158,6 +1158,65 @@ struct bitset_test {
|
||||
BOOST_TEST((lhs >> pos) == (x >>= pos));
|
||||
}
|
||||
|
||||
static void at(const Bitset& lhs, const std::vector<bool>& bit_vec)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
std::size_t i, j, k;
|
||||
|
||||
// x = b.at(i)
|
||||
// x = ~b.at(i)
|
||||
for (i = 0; i < b.size(); ++i)
|
||||
{
|
||||
bool x = b.at(i);
|
||||
BOOST_TEST(x == bit_vec.at(i));
|
||||
x = ~b.at(i);
|
||||
BOOST_TEST(x == !bit_vec.at(i));
|
||||
}
|
||||
Bitset prev(b);
|
||||
|
||||
// b.at(i) = x
|
||||
for (j = 0; j < b.size(); ++j)
|
||||
{
|
||||
bool x = !prev.at(j);
|
||||
b.at(j) = x;
|
||||
for (k = 0; k < b.size(); ++k)
|
||||
if (j == k)
|
||||
BOOST_TEST(b.at(k) == x);
|
||||
else
|
||||
BOOST_TEST(b.at(k) == prev.at(k));
|
||||
b.at(j) = prev.at(j);
|
||||
}
|
||||
b.flip();
|
||||
|
||||
// b.at(i) = b.at(j)
|
||||
for (i = 0; i < b.size(); ++i)
|
||||
{
|
||||
b.at(i) = prev.at(i);
|
||||
for (j = 0; j < b.size(); ++j)
|
||||
{
|
||||
if (i == j)
|
||||
BOOST_TEST(b.at(j) == prev.at(j));
|
||||
else
|
||||
BOOST_TEST(b.at(j) == !prev.at(j));
|
||||
}
|
||||
b.at(i) = !prev.at(i);
|
||||
}
|
||||
|
||||
// b.at(i).flip()
|
||||
for (i = 0; i < b.size(); ++i)
|
||||
{
|
||||
b.at(i).flip();
|
||||
for (j = 0; j < b.size(); ++j)
|
||||
{
|
||||
if (i == j)
|
||||
BOOST_TEST(b.at(j) == prev.at(j));
|
||||
else
|
||||
BOOST_TEST(b.at(j) == !prev.at(j));
|
||||
}
|
||||
b.at(i).flip();
|
||||
}
|
||||
}
|
||||
|
||||
// operator|
|
||||
static
|
||||
void operator_or(const Bitset& lhs, const Bitset& rhs)
|
||||
|
||||
@@ -509,6 +509,26 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
|
||||
Tests::operator_bracket(b, bit_vec);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test at
|
||||
{
|
||||
boost::dynamic_bitset<Block> b1;
|
||||
std::vector<bool> bitvec1;
|
||||
Tests::at(b1, bitvec1);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("1"));
|
||||
std::vector<bool> bit_vec(1, true);
|
||||
Tests::at(b, bit_vec);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
std::size_t n = long_string.size();
|
||||
std::vector<bool> bit_vec(n);
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1;
|
||||
Tests::at(b, bit_vec);
|
||||
}
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
{
|
||||
typedef boost::dynamic_bitset<Block,
|
||||
|
||||
Reference in New Issue
Block a user