14 changes: 14 additions & 0 deletions test/common_functors.hpp
Expand Up @@ -66,6 +66,20 @@ class empty_disposer
{}
};

struct any_less
{
template<class T, class U>
bool operator()(const T &t, const U &u) const
{ return t < u; }
};

struct any_greater
{
template<class T, class U>
bool operator()(const T &t, const U &u) const
{ return t > u; }
};

} //namespace test {
} //namespace intrusive {
} //namespace boost {
Expand Down
11 changes: 11 additions & 0 deletions test/generic_multiset_test.hpp
Expand Up @@ -207,6 +207,7 @@ void test_generic_multiset<ContainerDefiner>::test_merge(value_cont_type& values
(&cmp_val)->value_ = 2;

BOOST_TEST (*testset2.find(key_of_value()(cmp_val)) == values[5]);
BOOST_TEST (*testset2.find(2, any_greater()) == values[5]);
BOOST_TEST (&*(++testset2.find(key_of_value()(cmp_val))) == &values[1]);

testset1.merge(testset2);
Expand All @@ -217,6 +218,7 @@ void test_generic_multiset<ContainerDefiner>::test_merge(value_cont_type& values
{ int init_values [] = { 1, 2, 2, 3, 4, 5 };
TEST_INTRUSIVE_SEQUENCE( init_values, testset1.begin() ); }
BOOST_TEST (*testset1.find(key_of_value()(cmp_val)) == values[5]);
BOOST_TEST (*testset1.find(2, any_less()) == values[5]);
BOOST_TEST (&*(++testset1.find(key_of_value()(cmp_val))) == &values[1]);
BOOST_TEST (testset2.empty());
}
Expand All @@ -237,16 +239,19 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
typename value_cont_type::reference cmp_val = cmp_val_cont.front();
(&cmp_val)->value_ = 2;
iterator i = testset.find (key_of_value()(cmp_val));
BOOST_TEST (i == testset.find (2, any_less()));
BOOST_TEST (i->value_ == 2);
BOOST_TEST ((++i)->value_ == 2);
std::pair<iterator,iterator> range = testset.equal_range (key_of_value()(cmp_val));
BOOST_TEST(range == testset.equal_range (2, any_less()));

BOOST_TEST (range.first->value_ == 2);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 2);

(&cmp_val)->value_ = 7;
BOOST_TEST (testset.find(key_of_value()(cmp_val)) == testset.end());
BOOST_TEST (testset.find (7, any_less()) == testset.end());
}
{ //1, 2, 2, 3, 4, 5
const multiset_type &const_testset = testset;
Expand All @@ -260,6 +265,7 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_upper)->value_ = 2;
//left-closed, right-closed
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, true);
BOOST_TEST (range == testset.bounded_range (1, 2, any_less(), true, true));
BOOST_TEST (range.first->value_ == 1);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 3);
Expand All @@ -268,13 +274,15 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (const_range == const_testset.bounded_range (1, 2, any_less(), true, false));
BOOST_TEST (const_range.first->value_ == 1);
BOOST_TEST (const_range.second->value_ == 2);
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 1);

(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 3;
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (range == testset.bounded_range (1, 3, any_less(), true, false));
BOOST_TEST (range.first->value_ == 1);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 3);
Expand All @@ -283,6 +291,7 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), false, true);
BOOST_TEST (const_range == const_testset.bounded_range (1, 2, any_less(), false, true));
BOOST_TEST (const_range.first->value_ == 2);
BOOST_TEST (const_range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 2);
Expand All @@ -291,6 +300,7 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), false, false);
BOOST_TEST (range == testset.bounded_range (1, 2, any_less(), false, false));
BOOST_TEST (range.first->value_ == 2);
BOOST_TEST (range.second->value_ == 2);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 0);
Expand All @@ -299,6 +309,7 @@ void test_generic_multiset<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 5;
(&cmp_val_upper)->value_ = 6;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (const_range == const_testset.bounded_range (5, 6, any_less(), true, false));
BOOST_TEST (const_range.first->value_ == 5);
BOOST_TEST (const_range.second == const_testset.end());
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 1);
Expand Down
21 changes: 15 additions & 6 deletions test/generic_set_test.hpp
Expand Up @@ -197,17 +197,16 @@ void test_generic_set<ContainerDefiner>::test_insert_advanced
typedef typename ContainerDefiner::template container
<>::type set_type;
typedef typename set_type::key_of_value key_of_value;
typedef typename set_type::key_type key_type;
typedef typename set_type::value_type value_type;
typedef priority_compare<key_type> prio_comp_t;
typedef priority_compare<> prio_comp_t;
{
set_type testset;
testset.insert(values.begin(), values.begin() + values.size());
testset.check();
value_type v(1);
typename set_type::insert_commit_data data;
BOOST_TEST ((!testset.insert_check(key_of_value()(v), testset.key_comp(), prio_comp_t(), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), key_of_value()(v), testset.key_comp(), prio_comp_t(), data).second));
BOOST_TEST ((!testset.insert_check(1, any_less(), prio_comp_t(), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), 1, any_less(), prio_comp_t(), data).second));
BOOST_TEST ((!testset.insert_check(key_of_value()(v), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), key_of_value()(v), data).second));
}
Expand All @@ -228,9 +227,9 @@ void test_generic_set<ContainerDefiner>::test_insert_advanced
testset.check();
value_type v(1);
typename set_type::insert_commit_data data;
BOOST_TEST ((!testset.insert_check(key_of_value()(v), testset.key_comp(), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), key_of_value()(v), testset.key_comp(), data).second));
BOOST_TEST ((!testset.insert_check(1, any_less(), data).second));
BOOST_TEST ((!testset.insert_check(key_of_value()(v), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), 1, any_less(), data).second));
BOOST_TEST ((!testset.insert_check(testset.begin(), key_of_value()(v), data).second));
}
}
Expand Down Expand Up @@ -319,16 +318,20 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
reference cmp_val = cmp_val_cont.front();
(&cmp_val)->value_ = 2;
iterator i = testset.find(key_of_value()(cmp_val));
BOOST_TEST (i == testset.find(2, any_less()));
BOOST_TEST (i->value_ == 2);
BOOST_TEST ((++i)->value_ != 2);

std::pair<iterator,iterator> range = testset.equal_range (key_of_value()(cmp_val));
BOOST_TEST(range == testset.equal_range (2, any_less()));

BOOST_TEST (range.first->value_ == 2);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 1);

(&cmp_val)->value_ = 7;
BOOST_TEST (testset.find (key_of_value()(cmp_val)) == testset.end());
BOOST_TEST (testset.find (7, any_less()) == testset.end());
}

{
Expand All @@ -344,6 +347,7 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_upper)->value_ = 2;
//left-closed, right-closed
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, true);
BOOST_TEST (range == testset.bounded_range (1, 2, any_less(), true, true));
BOOST_TEST (range.first->value_ == 1);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 2);
Expand All @@ -352,13 +356,15 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (const_range == const_testset.bounded_range (1, 2, any_less(), true, false));
BOOST_TEST (const_range.first->value_ == 1);
BOOST_TEST (const_range.second->value_ == 2);
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 1);

(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 3;
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (range == testset.bounded_range (1, 3, any_less(), true, false));
BOOST_TEST (range.first->value_ == 1);
BOOST_TEST (range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 2);
Expand All @@ -367,6 +373,7 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), false, true);
BOOST_TEST (const_range == const_testset.bounded_range (1, 2, any_less(), false, true));
BOOST_TEST (const_range.first->value_ == 2);
BOOST_TEST (const_range.second->value_ == 3);
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 1);
Expand All @@ -375,6 +382,7 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 1;
(&cmp_val_upper)->value_ = 2;
range = testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), false, false);
BOOST_TEST (range == testset.bounded_range (1, 2, any_less(), false, false));
BOOST_TEST (range.first->value_ == 2);
BOOST_TEST (range.second->value_ == 2);
BOOST_TEST (boost::intrusive::iterator_distance (range.first, range.second) == 0);
Expand All @@ -383,6 +391,7 @@ void test_generic_set<ContainerDefiner>::test_find(value_cont_type& values)
(&cmp_val_lower)->value_ = 5;
(&cmp_val_upper)->value_ = 6;
const_range = const_testset.bounded_range (key_of_value()(cmp_val_lower), key_of_value()(cmp_val_upper), true, false);
BOOST_TEST (const_range == const_testset.bounded_range (5, 6, any_less(), true, false));
BOOST_TEST (const_range.first->value_ == 5);
BOOST_TEST (const_range.second == const_testset.end());
BOOST_TEST (boost::intrusive::iterator_distance (const_range.first, const_range.second) == 1);
Expand Down
21 changes: 9 additions & 12 deletions test/itestvalue.hpp
Expand Up @@ -136,22 +136,19 @@ struct testvalue
}
};

template<class T>
std::size_t priority_hash(const T &t)
{ return boost::hash<int>()((&t)->int_value()); }

template <class Type>
bool priority_order(const Type& t1, const Type& t2)
{
std::size_t hash1 = boost::hash<int>()((&t1)->int_value());
boost::hash_combine(hash1, -hash1);
std::size_t hash2 = boost::hash<int>()((&t2)->int_value());
boost::hash_combine(hash2, -hash2);
return hash1 < hash2;
}
std::size_t priority_hash(int i)
{ return boost::hash<int>()(i); }

bool priority_order(int t1, int t2)
template <class T, class U>
bool priority_order(const T& t1, const U& t2)
{
std::size_t hash1 = boost::hash<int>()(t1);
std::size_t hash1 = (priority_hash)(t1);
boost::hash_combine(hash1, -hash1);
std::size_t hash2 = boost::hash<int>()(t2);
std::size_t hash2 = (priority_hash)(t2);
boost::hash_combine(hash2, -hash2);
return hash1 < hash2;
}
Expand Down