[boost][range] - Improved the tests by implementing outside of the boost namespace to better simulate real world usage.

[SVN r67602]
This commit is contained in:
Neil Groves
2011-01-03 01:33:04 +00:00
parent a5d94bbe21
commit 2da424d940
11 changed files with 1177 additions and 1212 deletions

View File

@ -22,85 +22,82 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_find
{ {
namespace class find_test_policy
{ {
class find_test_policy public:
template<class Container>
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template<class Container> iter_t result = boost::find(cont, 3);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t result2 = boost::find(boost::make_iterator_range(cont), 3);
test_iter(Container& cont) BOOST_CHECK( result == result2 );
return result;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::find(cont, 3); result_t result = boost::find<return_type>(cont, 3);
iter_t result2 = boost::find(boost::make_iterator_range(cont), 3); result_t result2 = boost::find<return_type>(boost::make_iterator_range(cont), 3);
BOOST_CHECK( result == result2 ); BOOST_CHECK( result == result2 );
return result; return result;
} }
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find<return_type>(cont, 3);
result_t result2 = boost::find<return_type>(boost::make_iterator_range(cont), 3);
BOOST_CHECK( result == result2 );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find(cont.begin(), cont.end(), 3);
}
}; };
template<class Container> template<class Container>
void test_find_container() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::find(cont.begin(), cont.end(), 3);
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, find_test_policy());
mcont.clear();
mcont += 1;
test_driver(cont, find_test_policy());
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
test_driver(cont, find_test_policy());
} }
};
void test_find() template<class Container>
{ void test_find_container()
test_find_container< std::vector<int> >(); {
test_find_container< std::list<int> >(); using namespace boost::assign;
test_find_container< std::deque<int> >();
test_find_container< const std::vector<int> >(); typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
test_find_container< const std::list<int> >();
test_find_container< const std::deque<int> >();
std::vector<int> vi; boost::range_test::range_return_test_driver test_driver;
const std::vector<int>& cvi = vi;
std::vector<int>::const_iterator it = boost::find(vi, 0); container_t mcont;
std::vector<int>::const_iterator it2 = boost::find(cvi, 0); Container& cont = mcont;
BOOST_CHECK( it == it2 ); test_driver(cont, find_test_policy());
}
mcont.clear();
mcont += 1;
test_driver(cont, find_test_policy());
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
test_driver(cont, find_test_policy());
}
void test_find()
{
test_find_container< std::vector<int> >();
test_find_container< std::list<int> >();
test_find_container< std::deque<int> >();
test_find_container< const std::vector<int> >();
test_find_container< const std::list<int> >();
test_find_container< const std::deque<int> >();
std::vector<int> vi;
const std::vector<int>& cvi = vi;
std::vector<int>::const_iterator it = boost::find(vi, 0);
std::vector<int>::const_iterator it2 = boost::find(cvi, 0);
BOOST_CHECK( it == it2 );
} }
} }
@ -110,7 +107,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" );
test->add( BOOST_TEST_CASE( &boost::test_find ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find::test_find ) );
return test; return test;
} }

View File

@ -21,173 +21,170 @@
#include <set> #include <set>
#include <list> #include <list>
namespace boost namespace boost_range_test_algorithm_find_end
{ {
namespace template<class Container2>
class find_end_test_policy
{ {
template<class Container2> typedef Container2 container2_t;
class find_end_test_policy public:
explicit find_end_test_policy(const Container2& cont)
: m_cont(cont)
{ {
typedef Container2 container2_t; }
public:
explicit find_end_test_policy(const Container2& cont)
: m_cont(cont)
{
}
container2_t cont() { return m_cont; } container2_t cont() { return m_cont; }
template<class Container> template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont) test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::find_end(cont, m_cont);
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) );
BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) );
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
return result;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::find_end(cont, m_cont); result_t result = boost::find_end<return_type>(cont, policy.cont());
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) ); BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont()) );
BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) ); BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont())) );
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
boost::make_iterator_range(policy.cont())) );
return result; return result;
} }
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find_end<return_type>(cont, policy.cont());
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont()) );
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont())) );
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
boost::make_iterator_range(policy.cont())) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find_end(cont.begin(), cont.end(),
m_cont.begin(), m_cont.end());
}
private:
Container2 m_cont;
}; };
template<class Container2, class BinaryPredicate> template<class Container>
class find_end_pred_test_policy BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
typedef Container2 container2_t; return std::find_end(cont.begin(), cont.end(),
public: m_cont.begin(), m_cont.end());
explicit find_end_pred_test_policy(const Container2& cont) }
: m_cont(cont)
private:
Container2 m_cont;
};
template<class Container2, class BinaryPredicate>
class find_end_pred_test_policy
{
typedef Container2 container2_t;
public:
explicit find_end_pred_test_policy(const Container2& cont)
: m_cont(cont)
{
}
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
template<class Container>
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t it = boost::find_end(cont, m_cont, m_pred);
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) );
BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) );
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
return it;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
result_t result = boost::find_end<return_type>(cont, policy.cont(), policy.pred());
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
boost::make_iterator_range(policy.cont()), policy.pred()) );
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
} }
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t it = boost::find_end(cont, m_cont, m_pred);
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) );
BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) );
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
return it;
}
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find_end<return_type>(cont, policy.cont(), policy.pred());
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
boost::make_iterator_range(policy.cont()), policy.pred()) );
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find_end(cont.begin(), cont.end(),
m_cont.begin(), m_cont.end(),
m_pred);
}
private:
Container2 m_cont;
BinaryPredicate m_pred;
}; };
template<class Container1, class Container2> template<class Container>
void run_tests(Container1& cont1, Container2& cont2) BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
range_test::range_return_test_driver test_driver; return std::find_end(cont.begin(), cont.end(),
test_driver(cont1, find_end_test_policy<Container2>(cont2)); m_cont.begin(), m_cont.end(),
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2)); m_pred);
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
} }
template<class Container1, class Container2> private:
void test_find_end_impl() Container2 m_cont;
{ BinaryPredicate m_pred;
using namespace boost::assign; };
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t; template<class Container1, class Container2>
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t; void run_tests(Container1& cont1, Container2& cont2)
{
boost::range_test::range_return_test_driver test_driver;
test_driver(cont1, find_end_test_policy<Container2>(cont2));
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2));
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
}
container1_t mcont1; template<class Container1, class Container2>
Container1& cont1 = mcont1; void test_find_end_impl()
container2_t mcont2; {
Container2& cont2 = mcont2; using namespace boost::assign;
run_tests(cont1, cont2); typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
mcont1 += 1; container1_t mcont1;
run_tests(cont1, cont2); Container1& cont1 = mcont1;
container2_t mcont2;
Container2& cont2 = mcont2;
mcont2 += 1; run_tests(cont1, cont2);
run_tests(cont1, cont2);
mcont1 += 2,3,4,5,6,7,8,9; mcont1 += 1;
mcont2 += 2,3,4; run_tests(cont1, cont2);
run_tests(cont1, cont2);
mcont2.clear(); mcont2 += 1;
mcont2 += 7,8,9; run_tests(cont1, cont2);
run_tests(cont1, cont2);
}
void test_find_end() mcont1 += 2,3,4,5,6,7,8,9;
{ mcont2 += 2,3,4;
test_find_end_impl< std::vector<int>, std::vector<int> >(); run_tests(cont1, cont2);
test_find_end_impl< std::list<int>, std::list<int> >();
test_find_end_impl< std::deque<int>, std::deque<int> >(); mcont2.clear();
test_find_end_impl< const std::vector<int>, const std::vector<int> >(); mcont2 += 7,8,9;
test_find_end_impl< const std::list<int>, const std::list<int> >(); run_tests(cont1, cont2);
test_find_end_impl< const std::deque<int>, const std::deque<int> >(); }
test_find_end_impl< const std::vector<int>, const std::list<int> >();
test_find_end_impl< const std::list<int>, const std::vector<int> >(); void test_find_end()
test_find_end_impl< const std::vector<int>, std::list<int> >(); {
test_find_end_impl< const std::list<int>, std::vector<int> >(); test_find_end_impl< std::vector<int>, std::vector<int> >();
test_find_end_impl< std::vector<int>, std::list<int> >(); test_find_end_impl< std::list<int>, std::list<int> >();
test_find_end_impl< std::list<int>, std::vector<int> >(); test_find_end_impl< std::deque<int>, std::deque<int> >();
} test_find_end_impl< const std::vector<int>, const std::vector<int> >();
test_find_end_impl< const std::list<int>, const std::list<int> >();
test_find_end_impl< const std::deque<int>, const std::deque<int> >();
test_find_end_impl< const std::vector<int>, const std::list<int> >();
test_find_end_impl< const std::list<int>, const std::vector<int> >();
test_find_end_impl< const std::vector<int>, std::list<int> >();
test_find_end_impl< const std::list<int>, std::vector<int> >();
test_find_end_impl< std::vector<int>, std::list<int> >();
test_find_end_impl< std::list<int>, std::vector<int> >();
} }
} }
@ -197,7 +194,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" );
test->add( BOOST_TEST_CASE( &boost::test_find_end ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_end::test_find_end ) );
return test; return test;
} }

View File

@ -21,171 +21,168 @@
#include <set> #include <set>
#include <list> #include <list>
namespace boost namespace boost_range_test_algorithm_find_first_of
{ {
namespace template<class Container2>
class find_first_of_test_policy
{ {
template<class Container2> typedef Container2 container2_t;
class find_first_of_test_policy public:
explicit find_first_of_test_policy(const Container2& cont)
: m_cont(cont)
{ {
typedef Container2 container2_t; }
public:
explicit find_first_of_test_policy(const Container2& cont)
: m_cont(cont)
{
}
container2_t& cont() { return m_cont; } container2_t& cont() { return m_cont; }
template<class Container> template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont) test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::find_first_of(cont, m_cont);
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) );
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) );
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
return result;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::find_first_of(cont, m_cont); result_t result = boost::find_first_of<return_type>(cont, policy.cont());
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) ); BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont()) );
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) ); BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont())) );
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) );
return result; return result;
} }
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find_first_of<return_type>(cont, policy.cont());
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont()) );
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont())) );
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find_first_of(cont.begin(), cont.end(),
m_cont.begin(), m_cont.end());
}
private:
Container2 m_cont;
}; };
template<class Container2, class BinaryPredicate> template<class Container>
class find_first_of_pred_test_policy BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
typedef Container2 container2_t; return std::find_first_of(cont.begin(), cont.end(),
public: m_cont.begin(), m_cont.end());
explicit find_first_of_pred_test_policy(const Container2& cont) }
: m_cont(cont)
{
}
container2_t& cont() { return m_cont; } private:
BinaryPredicate& pred() { return m_pred; } Container2 m_cont;
};
template<class Container> template<class Container2, class BinaryPredicate>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type class find_first_of_pred_test_policy
test_iter(Container& cont) {
typedef Container2 container2_t;
public:
explicit find_first_of_pred_test_policy(const Container2& cont)
: m_cont(cont)
{
}
container2_t& cont() { return m_cont; }
BinaryPredicate& pred() { return m_pred; }
template<class Container>
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::find_first_of(cont, m_cont, m_pred);
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) );
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) );
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
return result;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::find_first_of(cont, m_cont, m_pred); result_t result = boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) ); BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) ); BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) ); BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) );
return result; return result;
} }
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find_first_of(cont.begin(), cont.end(),
m_cont.begin(), m_cont.end(),
m_pred);
}
private:
Container2 m_cont;
BinaryPredicate m_pred;
}; };
template<class Container1, class Container2> template<class Container>
void run_tests(Container1& cont1, Container2& cont2) BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
range_test::range_return_test_driver test_driver; return std::find_first_of(cont.begin(), cont.end(),
test_driver(cont1, find_first_of_test_policy<Container2>(cont2)); m_cont.begin(), m_cont.end(),
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2)); m_pred);
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
} }
template<class Container1, class Container2> private:
void test_find_first_of_impl() Container2 m_cont;
{ BinaryPredicate m_pred;
using namespace boost::assign; };
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t; template<class Container1, class Container2>
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t; void run_tests(Container1& cont1, Container2& cont2)
{
boost::range_test::range_return_test_driver test_driver;
test_driver(cont1, find_first_of_test_policy<Container2>(cont2));
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2));
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
}
container1_t mcont1; template<class Container1, class Container2>
Container1& cont1 = mcont1; void test_find_first_of_impl()
container2_t mcont2; {
Container2& cont2 = mcont2; using namespace boost::assign;
run_tests(cont1, cont2); typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
mcont1 += 1; container1_t mcont1;
run_tests(cont1, cont2); Container1& cont1 = mcont1;
container2_t mcont2;
Container2& cont2 = mcont2;
mcont2 += 1; run_tests(cont1, cont2);
run_tests(cont1, cont2);
mcont1 += 2,3,4,5,6,7,8,9; mcont1 += 1;
mcont2 += 2,3,4; run_tests(cont1, cont2);
run_tests(cont1, cont2);
mcont2.clear(); mcont2 += 1;
mcont2 += 7,8,9; run_tests(cont1, cont2);
run_tests(cont1, cont2);
}
void test_find_first_of() mcont1 += 2,3,4,5,6,7,8,9;
{ mcont2 += 2,3,4;
test_find_first_of_impl< std::vector<int>, std::vector<int> >(); run_tests(cont1, cont2);
test_find_first_of_impl< std::list<int>, std::list<int> >();
test_find_first_of_impl< std::deque<int>, std::deque<int> >(); mcont2.clear();
test_find_first_of_impl< const std::vector<int>, const std::vector<int> >(); mcont2 += 7,8,9;
test_find_first_of_impl< const std::list<int>, const std::list<int> >(); run_tests(cont1, cont2);
test_find_first_of_impl< const std::deque<int>, const std::deque<int> >(); }
test_find_first_of_impl< const std::vector<int>, const std::list<int> >();
test_find_first_of_impl< const std::list<int>, const std::vector<int> >(); void test_find_first_of()
test_find_first_of_impl< const std::vector<int>, std::list<int> >(); {
test_find_first_of_impl< const std::list<int>, std::vector<int> >(); test_find_first_of_impl< std::vector<int>, std::vector<int> >();
test_find_first_of_impl< std::vector<int>, std::list<int> >(); test_find_first_of_impl< std::list<int>, std::list<int> >();
test_find_first_of_impl< std::list<int>, std::vector<int> >(); test_find_first_of_impl< std::deque<int>, std::deque<int> >();
} test_find_first_of_impl< const std::vector<int>, const std::vector<int> >();
test_find_first_of_impl< const std::list<int>, const std::list<int> >();
test_find_first_of_impl< const std::deque<int>, const std::deque<int> >();
test_find_first_of_impl< const std::vector<int>, const std::list<int> >();
test_find_first_of_impl< const std::list<int>, const std::vector<int> >();
test_find_first_of_impl< const std::vector<int>, std::list<int> >();
test_find_first_of_impl< const std::list<int>, std::vector<int> >();
test_find_first_of_impl< std::vector<int>, std::list<int> >();
test_find_first_of_impl< std::list<int>, std::vector<int> >();
} }
} }
@ -195,7 +192,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" );
test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_first_of::test_find_first_of ) );
return test; return test;
} }

View File

@ -23,97 +23,94 @@
#include <list> #include <list>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_find_if
{ {
namespace template<class UnaryPredicate>
class find_if_test_policy
{ {
template<class UnaryPredicate> public:
class find_if_test_policy explicit find_if_test_policy(UnaryPredicate pred)
{ : m_pred(pred) {}
public:
explicit find_if_test_policy(UnaryPredicate pred)
: m_pred(pred) {}
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::find_if(cont, m_pred);
BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) );
return result;
}
template<range_return_value return_type>
struct test_range
{
template<class Container>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(find_if_test_policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::find_if<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::find_if<return_type>(boost::make_iterator_range(cont), policy.pred()) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::find_if(cont.begin(), cont.end(), m_pred);
}
UnaryPredicate& pred() { return m_pred; }
private:
UnaryPredicate m_pred;
};
template<class UnaryPredicate>
find_if_test_policy<UnaryPredicate>
make_policy(UnaryPredicate pred)
{
return find_if_test_policy<UnaryPredicate>(pred);
}
template<class Container> template<class Container>
void test_find_if_container() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
using namespace boost::assign; typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
using namespace boost::range_test_function; iter_t result = boost::find_if(cont, m_pred);
BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) );
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t; return result;
range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
mcont.clear();
mcont += 1;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
} }
void test_find_if() template<boost::range_return_value return_type>
struct test_range
{ {
test_find_if_container< std::vector<int> >(); template<class Container>
test_find_if_container< std::list<int> >(); BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
test_find_if_container< std::deque<int> >(); operator()(find_if_test_policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
result_t result = boost::find_if<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::find_if<return_type>(boost::make_iterator_range(cont), policy.pred()) );
return result;
}
};
test_find_if_container< const std::vector<int> >(); template<class Container>
test_find_if_container< const std::list<int> >(); BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_find_if_container< const std::deque<int> >(); reference(Container& cont)
{
return std::find_if(cont.begin(), cont.end(), m_pred);
} }
UnaryPredicate& pred() { return m_pred; }
private:
UnaryPredicate m_pred;
};
template<class UnaryPredicate>
find_if_test_policy<UnaryPredicate>
make_policy(UnaryPredicate pred)
{
return find_if_test_policy<UnaryPredicate>(pred);
}
template<class Container>
void test_find_if_container()
{
using namespace boost::assign;
using namespace boost::range_test_function;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
boost::range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
mcont.clear();
mcont += 1;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
test_driver(cont, make_policy(greater_than_x<int>(5)));
test_driver(cont, make_policy(false_predicate()));
}
void test_find_if()
{
test_find_if_container< std::vector<int> >();
test_find_if_container< std::list<int> >();
test_find_if_container< std::deque<int> >();
test_find_if_container< const std::vector<int> >();
test_find_if_container< const std::list<int> >();
test_find_if_container< const std::deque<int> >();
} }
} }
@ -123,7 +120,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" );
test->add( BOOST_TEST_CASE( &boost::test_find_if ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_if::test_find_if ) );
return test; return test;
} }

View File

@ -22,164 +22,160 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_lower_bound
{ {
namespace class lower_bound_policy
{ {
class lower_bound_policy public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template< class Container > iter_t result = boost::lower_bound(cont, 5);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) );
test_iter(Container& cont) return result;
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::lower_bound(cont, 5);
BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) );
return result;
}
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::lower_bound<return_type>(cont, 5);
BOOST_CHECK( result == boost::lower_bound<return_type>(boost::make_iterator_range(cont), 5) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::lower_bound(cont.begin(), cont.end(), 5);
}
};
template< class BinaryPredicate >
struct lower_bound_pred_policy
{
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::lower_bound(cont, 5, m_pred);
BOOST_CHECK( result == boost::lower_bound(
boost::make_iterator_range(cont), 5, m_pred) );
return result;
}
template< range_return_value return_type >
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::lower_bound<return_type>(cont, 5, policy.pred());
BOOST_CHECK( result == boost::lower_bound<return_type>(
boost::make_iterator_range(cont), 5, policy.pred()) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::lower_bound(
cont.begin(), cont.end(), 5, m_pred);
}
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
};
template<class Container,
class TestPolicy,
class BinaryPredicate>
void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred)
{
using namespace boost::assign;
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, policy);
mcont.clear();
mcont += 1;
std::vector<value_t> temp(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
temp.assign(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
} }
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
result_t result = boost::lower_bound<return_type>(cont, 5);
BOOST_CHECK( result == boost::lower_bound<return_type>(boost::make_iterator_range(cont), 5) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{
return std::lower_bound(cont.begin(), cont.end(), 5);
}
};
template< class BinaryPredicate >
struct lower_bound_pred_policy
{
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::lower_bound(cont, 5, m_pred);
BOOST_CHECK( result == boost::lower_bound(
boost::make_iterator_range(cont), 5, m_pred) );
return result;
}
template< boost::range_return_value return_type >
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
result_t result = boost::lower_bound<return_type>(cont, 5, policy.pred());
BOOST_CHECK( result == boost::lower_bound<return_type>(
boost::make_iterator_range(cont), 5, policy.pred()) );
return result;
}
};
template<class Container> template<class Container>
void test_lower_bound_impl() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
test_lower_bound_impl<Container>( return std::lower_bound(
lower_bound_policy(), cont.begin(), cont.end(), 5, m_pred);
std::less<int>()
);
test_lower_bound_impl<Container>(
lower_bound_pred_policy<std::less<int> >(),
std::less<int>()
);
test_lower_bound_impl<Container>(
lower_bound_pred_policy<std::greater<int> >(),
std::greater<int>()
);
} }
void test_lower_bound() BinaryPredicate& pred() { return m_pred; }
{
test_lower_bound_impl< std::vector<int> >();
test_lower_bound_impl< std::list<int> >();
test_lower_bound_impl< std::deque<int> >();
test_lower_bound_impl< const std::vector<int> >(); private:
test_lower_bound_impl< const std::list<int> >(); BinaryPredicate m_pred;
test_lower_bound_impl< const std::deque<int> >(); };
}
template<class Container,
class TestPolicy,
class BinaryPredicate>
void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred)
{
using namespace boost::assign;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
boost::range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, policy);
mcont.clear();
mcont += 1;
std::vector<value_t> temp(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
temp.assign(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
}
template<class Container>
void test_lower_bound_impl()
{
test_lower_bound_impl<Container>(
lower_bound_policy(),
std::less<int>()
);
test_lower_bound_impl<Container>(
lower_bound_pred_policy<std::less<int> >(),
std::less<int>()
);
test_lower_bound_impl<Container>(
lower_bound_pred_policy<std::greater<int> >(),
std::greater<int>()
);
}
void test_lower_bound()
{
test_lower_bound_impl< std::vector<int> >();
test_lower_bound_impl< std::list<int> >();
test_lower_bound_impl< std::deque<int> >();
test_lower_bound_impl< const std::vector<int> >();
test_lower_bound_impl< const std::list<int> >();
test_lower_bound_impl< const std::deque<int> >();
} }
} }
boost::unit_test::test_suite* boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[]) init_unit_test_suite(int argc, char* argv[])
{ {
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" );
test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_lower_bound::test_lower_bound ) );
return test; return test;
} }

View File

@ -22,134 +22,131 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_max_element
{ {
namespace class max_element_test_policy
{ {
class max_element_test_policy public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template< class Container > iter_t result = boost::max_element(cont);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_CHECK( result == boost::max_element(
test_iter(Container& cont) boost::make_iterator_range(cont)) );
return result;
}
template<boost::range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::max_element(cont); result_t result = boost::max_element<return_type>(cont);
BOOST_CHECK( result == boost::max_element( BOOST_CHECK( result == boost::max_element<return_type>(
boost::make_iterator_range(cont)) ); boost::make_iterator_range(cont)) );
return result; return result;
} }
template<range_return_value return_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::max_element<return_type>(cont);
BOOST_CHECK( result == boost::max_element<return_type>(
boost::make_iterator_range(cont)) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::max_element(cont.begin(), cont.end());
}
}; };
template<class Pred> template< class Container >
class max_element_pred_test_policy BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
public: return std::max_element(cont.begin(), cont.end());
template< class Container > }
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type };
test_iter(Container& cont)
template<class Pred>
class max_element_pred_test_policy
{
public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::max_element(cont, Pred());
BOOST_CHECK( result == boost::max_element(
boost::make_iterator_range(cont), Pred()) );
return result;
}
Pred pred() const { return Pred(); }
template< boost::range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::max_element(cont, Pred()); result_t result = boost::max_element<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::max_element( BOOST_CHECK( result == boost::max_element<return_type>(
boost::make_iterator_range(cont), Pred()) ); boost::make_iterator_range(cont), policy.pred()) );
return result; return result;
} }
Pred pred() const { return Pred(); }
template< range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::max_element<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::max_element<return_type>(
boost::make_iterator_range(cont), policy.pred()) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::max_element(cont.begin(), cont.end(), Pred());
}
}; };
template<class Container, class TestPolicy> template< class Container >
void test_max_element_impl(TestPolicy policy) BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::max_element(cont.begin(), cont.end(), Pred());
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
range_test::range_return_test_driver test_driver;
container_t cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
} }
};
template<class Container> template<class Container, class TestPolicy>
void test_max_element_impl() void test_max_element_impl(TestPolicy policy)
{ {
test_max_element_impl<Container>(max_element_test_policy()); using namespace boost::assign;
test_max_element_impl<Container>(
max_element_pred_test_policy<std::less<int> >());
test_max_element_impl<Container>( typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
max_element_pred_test_policy<std::greater<int> >()); typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
}
void test_max_element() boost::range_test::range_return_test_driver test_driver;
{
test_max_element_impl< const std::vector<int> >();
test_max_element_impl< const std::deque<int> >();
test_max_element_impl< const std::list<int> >();
test_max_element_impl< std::vector<int> >(); container_t cont;
test_max_element_impl< std::deque<int> >();
test_max_element_impl< std::list<int> >(); test_driver(cont, policy);
}
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
}
template<class Container>
void test_max_element_impl()
{
test_max_element_impl<Container>(max_element_test_policy());
test_max_element_impl<Container>(
max_element_pred_test_policy<std::less<int> >());
test_max_element_impl<Container>(
max_element_pred_test_policy<std::greater<int> >());
}
void test_max_element()
{
test_max_element_impl< const std::vector<int> >();
test_max_element_impl< const std::deque<int> >();
test_max_element_impl< const std::list<int> >();
test_max_element_impl< std::vector<int> >();
test_max_element_impl< std::deque<int> >();
test_max_element_impl< std::list<int> >();
} }
} }
@ -159,7 +156,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" );
test->add( BOOST_TEST_CASE( &boost::test_max_element ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_max_element::test_max_element ) );
return test; return test;
} }

View File

@ -22,132 +22,129 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_min_element
{ {
namespace class min_element_test_policy
{ {
class min_element_test_policy public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template< class Container > iter_t result = boost::min_element(cont);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) );
test_iter(Container& cont) return result;
}
template< boost::range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::min_element(cont); result_t result = boost::min_element<return_type>(cont);
BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) ); BOOST_CHECK( result == boost::min_element<return_type>(boost::make_iterator_range(cont)) );
return result; return result;
} }
template< range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::min_element<return_type>(cont);
BOOST_CHECK( result == boost::min_element<return_type>(boost::make_iterator_range(cont)) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::min_element(cont.begin(), cont.end());
}
}; };
template<class Pred> template< class Container >
class min_element_pred_test_policy BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
public: return std::min_element(cont.begin(), cont.end());
template< class Container > }
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type };
test_iter(Container& cont)
template<class Pred>
class min_element_pred_test_policy
{
public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::min_element(cont, Pred());
BOOST_CHECK( result == boost::min_element(
boost::make_iterator_range(cont), Pred()) );
return result;
}
Pred pred() const { return Pred(); }
template< boost::range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
iter_t result = boost::min_element(cont, Pred()); result_t result = boost::min_element<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::min_element( BOOST_CHECK( result == boost::min_element<return_type>(
boost::make_iterator_range(cont), Pred()) ); boost::make_iterator_range(cont), policy.pred()) );
return result; return result;
} }
Pred pred() const { return Pred(); }
template< range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
result_t result = boost::min_element<return_type>(cont, policy.pred());
BOOST_CHECK( result == boost::min_element<return_type>(
boost::make_iterator_range(cont), policy.pred()) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::min_element(cont.begin(), cont.end(), Pred());
}
}; };
template<class Container, class TestPolicy> template< class Container >
void test_min_element_impl(TestPolicy policy) BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::min_element(cont.begin(), cont.end(), Pred());
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
range_test::range_return_test_driver test_driver;
container_t cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
} }
};
template<class Container> template<class Container, class TestPolicy>
void test_min_element_impl() void test_min_element_impl(TestPolicy policy)
{ {
test_min_element_impl<Container>(min_element_test_policy()); using namespace boost::assign;
test_min_element_impl<Container>(
min_element_pred_test_policy<std::less<int> >());
test_min_element_impl<Container>( typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
min_element_pred_test_policy<std::greater<int> >()); typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
}
void test_min_element() boost::range_test::range_return_test_driver test_driver;
{
test_min_element_impl< const std::vector<int> >();
test_min_element_impl< const std::deque<int> >();
test_min_element_impl< const std::list<int> >();
test_min_element_impl< std::vector<int> >(); container_t cont;
test_min_element_impl< std::deque<int> >();
test_min_element_impl< std::list<int> >(); test_driver(cont, policy);
}
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
}
template<class Container>
void test_min_element_impl()
{
test_min_element_impl<Container>(min_element_test_policy());
test_min_element_impl<Container>(
min_element_pred_test_policy<std::less<int> >());
test_min_element_impl<Container>(
min_element_pred_test_policy<std::greater<int> >());
}
void test_min_element()
{
test_min_element_impl< const std::vector<int> >();
test_min_element_impl< const std::deque<int> >();
test_min_element_impl< const std::list<int> >();
test_min_element_impl< std::vector<int> >();
test_min_element_impl< std::deque<int> >();
test_min_element_impl< std::list<int> >();
} }
} }
@ -157,7 +154,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" );
test->add( BOOST_TEST_CASE( &boost::test_min_element ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_min_element::test_min_element ) );
return test; return test;
} }

View File

@ -21,109 +21,106 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_partition
{ {
namespace struct equal_to_5
{ {
struct equal_to_5 typedef bool result_type;
{ typedef int argument_type;
typedef bool result_type; bool operator()(int x) const { return x == 5; }
typedef int argument_type; };
bool operator()(int x) const { return x == 5; }
};
// test the 'partition' algorithm // test the 'partition' algorithm
template<class UnaryPredicate> template<class UnaryPredicate>
class partition_test_policy class partition_test_policy
{
public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type const Container old_cont(cont);
test_iter(Container& cont) Container cont2(old_cont);
iter_t result = boost::partition(cont, UnaryPredicate());
boost::partition(cont2, UnaryPredicate());
cont2 = old_cont;
boost::partition(
boost::make_iterator_range(cont2), UnaryPredicate());
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
}
UnaryPredicate pred() const { return UnaryPredicate(); }
template< boost::range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t; typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
const Container old_cont(cont); const Container old_cont(cont);
Container cont2(old_cont); Container cont2(old_cont);
iter_t result = boost::partition(cont, UnaryPredicate()); result_t result = boost::partition<return_type>(cont, policy.pred());
boost::partition(cont2, UnaryPredicate()); // Test that operation a temporary created by using
cont2 = old_cont; // make_iterator_range.
boost::partition( boost::partition<return_type>(
boost::make_iterator_range(cont2), UnaryPredicate()); boost::make_iterator_range(cont2), policy.pred());
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() ); cont2.begin(), cont2.end() );
return result; return result;
} }
UnaryPredicate pred() const { return UnaryPredicate(); }
template< range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
const Container old_cont(cont);
Container cont2(old_cont);
result_t result = boost::partition<return_type>(cont, policy.pred());
// Test that operation a temporary created by using
// make_iterator_range.
boost::partition<return_type>(
boost::make_iterator_range(cont2), policy.pred());
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::partition(cont.begin(), cont.end(), UnaryPredicate());
}
}; };
template<class Container> template< class Container >
void test_partition_impl() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::partition(cont.begin(), cont.end(), UnaryPredicate());
range_test::range_return_test_driver test_driver;
partition_test_policy< equal_to_5 > policy;
Container cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
test_driver(cont, policy);
} }
};
void test_partition() template<class Container>
{ void test_partition_impl()
test_partition_impl< std::vector<int> >(); {
test_partition_impl< std::list<int> >(); using namespace boost::assign;
test_partition_impl< std::deque<int> >();
} boost::range_test::range_return_test_driver test_driver;
partition_test_policy< equal_to_5 > policy;
Container cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
test_driver(cont, policy);
}
void test_partition()
{
test_partition_impl< std::vector<int> >();
test_partition_impl< std::list<int> >();
test_partition_impl< std::deque<int> >();
} }
} }
@ -133,7 +130,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" );
test->add( BOOST_TEST_CASE( &boost::test_partition ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_partition::test_partition ) );
return test; return test;
} }

View File

@ -21,116 +21,112 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_stable_partition
{ {
namespace struct equal_to_5
{ {
struct equal_to_5 typedef bool result_type;
{ typedef int argument_type;
typedef bool result_type; bool operator()(int x) const { return x == 5; }
typedef int argument_type; };
bool operator()(int x) const { return x == 5; }
};
// test the 'partition' algorithm // test the 'partition' algorithm
template<class UnaryPredicate> template<class UnaryPredicate>
class stable_partition_test_policy class stable_partition_test_policy
{
public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: Container cont2(cont);
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
test_iter(Container& cont) iter_t result = boost::stable_partition(cont, UnaryPredicate());
iter_t temp_result = boost::stable_partition(
boost::make_iterator_range(cont2), UnaryPredicate());
BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
std::distance(cont2.begin(), temp_result) );
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
}
UnaryPredicate pred() const { return UnaryPredicate(); }
template< boost::range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
Container cont2(cont); Container cont2(cont);
result_t result = boost::stable_partition<return_type>(cont, policy.pred());
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::stable_partition(cont, UnaryPredicate()); result_t result2 = boost::stable_partition<return_type>(
boost::make_iterator_range(cont2), policy.pred());
iter_t temp_result = boost::stable_partition(
boost::make_iterator_range(cont2), UnaryPredicate()); BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
cont.begin(), cont.end() );
BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
std::distance(cont2.begin(), temp_result) );
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result; return result;
} }
UnaryPredicate pred() const { return UnaryPredicate(); }
template< range_return_value return_type >
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
Container cont2(cont);
result_t result = boost::stable_partition<return_type>(cont, policy.pred());
result_t result2 = boost::stable_partition<return_type>(
boost::make_iterator_range(cont2), policy.pred());
BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
cont.begin(), cont.end() );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
}
}; };
template<class Container> template< class Container >
void test_stable_partition_impl() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
range_test::range_return_test_driver test_driver;
stable_partition_test_policy< equal_to_5 > policy;
Container cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
test_driver(cont, policy);
} }
};
void test_stable_partition() template<class Container>
{ void test_stable_partition_impl()
test_stable_partition_impl< std::vector<int> >(); {
test_stable_partition_impl< std::list<int> >(); using namespace boost::assign;
test_stable_partition_impl< std::deque<int> >();
} boost::range_test::range_return_test_driver test_driver;
stable_partition_test_policy< equal_to_5 > policy;
Container cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
test_driver(cont, policy);
}
void test_stable_partition()
{
test_stable_partition_impl< std::vector<int> >();
test_stable_partition_impl< std::list<int> >();
test_stable_partition_impl< std::deque<int> >();
} }
} }
boost::unit_test::test_suite* boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[]) init_unit_test_suite(int argc, char* argv[])
{ {
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" );
test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_stable_partition::test_stable_partition ) );
return test; return test;
} }

View File

@ -23,156 +23,153 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_unique
{ {
namespace // test the 'unique' algorithm without a predicate
class unique_test_policy
{ {
// test the 'unique' algorithm without a predicate public:
class unique_test_policy template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: // There isn't an iterator return version of boost::unique, so just
template< class Container > // perform the standard algorithm
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type return std::unique(cont.begin(), cont.end());
test_iter(Container& cont) }
{
// There isn't an iterator return version of boost::unique, so just
// perform the standard algorithm
return std::unique(cont.begin(), cont.end());
}
template< range_return_value return_type > template< boost::range_return_value return_type >
struct test_range struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{ {
template< class Container, class Policy > typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
Container cont2(cont);
result_t result = boost::unique<return_type>(cont);
boost::unique<return_type>(boost::make_iterator_range(cont2));
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
}
};
template< class Container > Container cont2(cont);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont) result_t result = boost::unique<return_type>(cont);
{
return std::unique(cont.begin(), cont.end()); boost::unique<return_type>(boost::make_iterator_range(cont2));
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
} }
}; };
// test the 'unique' algorithm with a predicate template< class Container >
template<class Pred> BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
class unique_pred_test_policy reference(Container& cont)
{ {
public: return std::unique(cont.begin(), cont.end());
template< class Container > }
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type };
test_iter(Container& cont)
{
// There isn't an iterator return version of boost::unique, so just
// perform the standard algorithm
return std::unique(cont.begin(), cont.end(), Pred());
}
Pred pred() const { return Pred(); } // test the 'unique' algorithm with a predicate
template<class Pred>
class unique_pred_test_policy
{
public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
// There isn't an iterator return version of boost::unique, so just
// perform the standard algorithm
return std::unique(cont.begin(), cont.end(), Pred());
}
template< range_return_value return_type > Pred pred() const { return Pred(); }
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type result_t;
Container cont2(cont);
result_t result = boost::unique<return_type>(cont, policy.pred());
boost::unique<return_type>(boost::make_iterator_range(cont2), policy.pred());
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
}
};
template< class Container > template< boost::range_return_value return_type >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type struct test_range
reference(Container& cont) {
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
operator()(Policy& policy, Container& cont)
{ {
return std::unique(cont.begin(), cont.end(), Pred()); typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
Container cont2(cont);
result_t result = boost::unique<return_type>(cont, policy.pred());
boost::unique<return_type>(boost::make_iterator_range(cont2), policy.pred());
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
cont2.begin(), cont2.end() );
return result;
} }
}; };
template<class Container, class TestPolicy, class Pred> template< class Container >
void test_unique_impl(TestPolicy policy, Pred pred) BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
using namespace boost::assign; return std::unique(cont.begin(), cont.end(), Pred());
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
range_test::range_return_test_driver test_driver;
Container cont;
test_driver(cont, policy);
cont.clear();
cont += 1;
std::vector<value_t> temp(cont.begin(), cont.end());
std::sort(temp.begin(), temp.end(), pred);
cont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,3,4,5,6,7,8,9;
temp.assign(cont.begin(), cont.end());
std::sort(temp.begin(), temp.end(), pred);
cont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
} }
};
template<class Container> template<class Container, class TestPolicy, class Pred>
void test_unique_impl() void test_unique_impl(TestPolicy policy, Pred pred)
{ {
test_unique_impl<Container>( using namespace boost::assign;
unique_test_policy(),
std::less<int>()
);
test_unique_impl<Container>( typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
unique_pred_test_policy<std::less<int> >(),
std::less<int>()
);
test_unique_impl<Container>(
unique_pred_test_policy<std::greater<int> >(),
std::greater<int>()
);
}
void test_unique() boost::range_test::range_return_test_driver test_driver;
{
test_unique_impl< std::vector<int> >(); Container cont;
test_unique_impl< std::list<int> >();
test_unique_impl< std::deque<int> >(); test_driver(cont, policy);
}
cont.clear();
cont += 1;
std::vector<value_t> temp(cont.begin(), cont.end());
std::sort(temp.begin(), temp.end(), pred);
cont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
cont.clear();
cont += 1,2,2,2,2,3,4,5,6,7,8,9;
temp.assign(cont.begin(), cont.end());
std::sort(temp.begin(), temp.end(), pred);
cont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
}
template<class Container>
void test_unique_impl()
{
test_unique_impl<Container>(
unique_test_policy(),
std::less<int>()
);
test_unique_impl<Container>(
unique_pred_test_policy<std::less<int> >(),
std::less<int>()
);
test_unique_impl<Container>(
unique_pred_test_policy<std::greater<int> >(),
std::greater<int>()
);
}
void test_unique()
{
test_unique_impl< std::vector<int> >();
test_unique_impl< std::list<int> >();
test_unique_impl< std::deque<int> >();
} }
} }
@ -182,7 +179,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" );
test->add( BOOST_TEST_CASE( &boost::test_unique ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_unique::test_unique ) );
return test; return test;
} }

View File

@ -21,144 +21,141 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
namespace boost namespace boost_range_test_algorithm_upper_bound
{ {
namespace class upper_bound_policy
{ {
class upper_bound_policy public:
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{ {
public: typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
template< class Container > iter_t result = boost::upper_bound(cont, 5);
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) );
test_iter(Container& cont) return result;
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::upper_bound(cont, 5);
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) );
return result;
}
template<range_return_value result_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type result_t;
result_t result = boost::upper_bound<result_type>(cont, 5);
BOOST_CHECK( result == boost::upper_bound<result_type>(boost::make_iterator_range(cont), 5) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::upper_bound(cont.begin(), cont.end(), 5);
}
};
template< class BinaryPredicate >
struct upper_bound_pred_policy
{
template< class Container >
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iter_t;
iter_t result = boost::upper_bound(cont, 5, BinaryPredicate());
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) );
return result;
}
template< range_return_value result_type>
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type result_t;
result_t result = boost::upper_bound<result_type>(cont, 5, policy.pred());
BOOST_CHECK( result == boost::upper_bound<result_type>(
boost::make_iterator_range(cont), 5, policy.pred()) );
return result;
}
};
template<class Container>
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
reference(Container& cont)
{
return std::upper_bound(
cont.begin(), cont.end(), 5, BinaryPredicate());
}
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
};
template<class Container,
class TestPolicy,
class BinaryPredicate>
void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred)
{
using namespace boost::assign;
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, policy);
mcont.clear();
mcont += 1;
std::vector<value_t> temp(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
temp.assign(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
} }
template<boost::range_return_value result_type>
struct test_range
{
template<class Container, class Policy>
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
operator()(Policy&, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
result_t result = boost::upper_bound<result_type>(cont, 5);
BOOST_CHECK( result == boost::upper_bound<result_type>(boost::make_iterator_range(cont), 5) );
return result;
}
};
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{
return std::upper_bound(cont.begin(), cont.end(), 5);
}
};
template< class BinaryPredicate >
struct upper_bound_pred_policy
{
template< class Container >
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
test_iter(Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
iter_t result = boost::upper_bound(cont, 5, BinaryPredicate());
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) );
return result;
}
template< boost::range_return_value result_type>
struct test_range
{
template< class Container, class Policy >
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
operator()(Policy& policy, Container& cont)
{
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
result_t result = boost::upper_bound<result_type>(cont, 5, policy.pred());
BOOST_CHECK( result == boost::upper_bound<result_type>(
boost::make_iterator_range(cont), 5, policy.pred()) );
return result;
}
};
template<class Container> template<class Container>
void test_upper_bound_impl() BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
reference(Container& cont)
{ {
test_upper_bound_impl<Container>( return std::upper_bound(
upper_bound_policy(), cont.begin(), cont.end(), 5, BinaryPredicate());
std::less<int>()
);
test_upper_bound_impl<Container>(
upper_bound_pred_policy<std::less<int> >(),
std::less<int>()
);
test_upper_bound_impl<Container>(
upper_bound_pred_policy<std::greater<int> >(),
std::greater<int>()
);
} }
BinaryPredicate& pred() { return m_pred; }
private:
BinaryPredicate m_pred;
};
template<class Container,
class TestPolicy,
class BinaryPredicate>
void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred)
{
using namespace boost::assign;
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
boost::range_test::range_return_test_driver test_driver;
container_t mcont;
Container& cont = mcont;
test_driver(cont, policy);
mcont.clear();
mcont += 1;
std::vector<value_t> temp(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
mcont.clear();
mcont += 1,2,3,4,5,6,7,8,9;
temp.assign(mcont.begin(), mcont.end());
std::sort(temp.begin(), temp.end(), pred);
mcont.assign(temp.begin(), temp.end());
test_driver(cont, policy);
}
template<class Container>
void test_upper_bound_impl()
{
test_upper_bound_impl<Container>(
upper_bound_policy(),
std::less<int>()
);
test_upper_bound_impl<Container>(
upper_bound_pred_policy<std::less<int> >(),
std::less<int>()
);
test_upper_bound_impl<Container>(
upper_bound_pred_policy<std::greater<int> >(),
std::greater<int>()
);
} }
void test_upper_bound() void test_upper_bound()
@ -179,7 +176,7 @@ init_unit_test_suite(int argc, char* argv[])
boost::unit_test::test_suite* test boost::unit_test::test_suite* test
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" ); = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" );
test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) ); test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_upper_bound::test_upper_bound ) );
return test; return test;
} }