mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-19 04:12:09 +00:00
added tests for subset and proper subset
[SVN r14649]
This commit is contained in:
@@ -323,6 +323,21 @@ struct bitset_test {
|
||||
BOOST_TEST(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
// PRE: b.size() == rhs.size()
|
||||
static void sub_assignment(const Bitset& b, const Bitset& rhs)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
Bitset prev(lhs);
|
||||
lhs -= rhs;
|
||||
// Resets each bit in lhs for which the corresponding bit in rhs is set,
|
||||
// and leaves all other bits unchanged.
|
||||
for (std::size_t I = 0; I < lhs.size(); ++I)
|
||||
if (rhs[I] == 1)
|
||||
BOOST_TEST(lhs[I] == 0);
|
||||
else
|
||||
BOOST_TEST(lhs[I] == prev[I]);
|
||||
}
|
||||
|
||||
static void shift_left_assignment(const Bitset& b, std::size_t pos)
|
||||
{
|
||||
Bitset lhs(b);
|
||||
@@ -538,6 +553,41 @@ struct bitset_test {
|
||||
BOOST_TEST(b.none() == (b.count() == 0));
|
||||
}
|
||||
|
||||
static void subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_TEST(b[I]);
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
is_subset = false;
|
||||
break;
|
||||
}
|
||||
BOOST_TEST(is_subset == false);
|
||||
}
|
||||
}
|
||||
|
||||
static void proper_subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_proper_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_TEST(b[I]);
|
||||
BOOST_TEST(a.count() < b.count());
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
is_subset = false;
|
||||
break;
|
||||
}
|
||||
BOOST_TEST(is_subset == false || a.count() >= b.count());
|
||||
}
|
||||
}
|
||||
|
||||
static void operator_equal(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a == b) {
|
||||
@@ -681,6 +731,14 @@ struct bitset_test {
|
||||
BOOST_TEST((lhs ^ rhs) == (x ^= rhs));
|
||||
}
|
||||
|
||||
// operator-
|
||||
static
|
||||
void operator_sub(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
Bitset x(lhs);
|
||||
BOOST_TEST((lhs - rhs) == (x -= rhs));
|
||||
}
|
||||
|
||||
// operator<<(ostream,
|
||||
// operator>>(istream,
|
||||
|
||||
|
||||
@@ -105,6 +105,62 @@ void run_test_cases()
|
||||
Tests::none(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_subset_of(b)
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::subset(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a.is_proper_subset_of(b)
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
a[long_string.size()/2].flip();
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::proper_subset(a, b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator==
|
||||
{
|
||||
boost::dynamic_bitset<Block> a, b;
|
||||
@@ -427,6 +483,24 @@ void run_test_cases()
|
||||
Tests::operator_xor(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test a-b
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs, rhs;
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
|
||||
Tests::operator_sub(lhs, rhs);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test stream operator<< and operator>>
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
|
||||
Reference in New Issue
Block a user