forked from boostorg/range
Boost.RangeEx merged into Boost.Range
[SVN r60897]
This commit is contained in:
89
test/algorithm_test/adjacent_find.cpp
Normal file
89
test/algorithm_test/adjacent_find.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/adjacent_find.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_adjacent_find_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator const_iterator_t;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
std::equal_to<int> pred;
|
||||
|
||||
BOOST_CHECK( boost::adjacent_find(cont) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK( boost::adjacent_find(cont) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
|
||||
cont += 2,3,4,5,5,5,6,7,8,9;
|
||||
iterator_t it = boost::adjacent_find(cont);
|
||||
iterator_t it_pred = boost::adjacent_find(cont, pred);
|
||||
BOOST_CHECK( it == it_pred );
|
||||
BOOST_CHECK( it != cont.end() );
|
||||
BOOST_CHECK( it == std::adjacent_find(cont.begin(), cont.end()) );
|
||||
if (it != cont.end())
|
||||
{
|
||||
BOOST_CHECK( *it == 5 );
|
||||
}
|
||||
const_iterator_t cit = boost::adjacent_find(cref_cont);
|
||||
const_iterator_t cit_pred = boost::adjacent_find(cref_cont, pred);
|
||||
BOOST_CHECK( cit == cit_pred );
|
||||
BOOST_CHECK( cit != cref_cont.end() );
|
||||
BOOST_CHECK( cit == std::adjacent_find(cref_cont.begin(), cref_cont.end()) );
|
||||
if (cit != cref_cont.end())
|
||||
{
|
||||
BOOST_CHECK( *cit == 5 );
|
||||
}
|
||||
}
|
||||
|
||||
void test_adjacent_find()
|
||||
{
|
||||
test_adjacent_find_impl< std::vector<int> >();
|
||||
test_adjacent_find_impl< std::list<int> >();
|
||||
test_adjacent_find_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.adjacent_find" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_adjacent_find ) );
|
||||
|
||||
return test;
|
||||
}
|
122
test/algorithm_test/binary_search.cpp
Normal file
122
test/algorithm_test/binary_search.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/binary_search.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
bool reference_result
|
||||
= std::binary_search(reference.begin(), reference.end(), 5);
|
||||
|
||||
bool test_result = boost::binary_search(test, 5);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
sort_container(reference, pred);
|
||||
sort_container(test, pred);
|
||||
|
||||
bool reference_result
|
||||
= std::binary_search(reference.begin(), reference.end(), 5,
|
||||
pred);
|
||||
|
||||
bool test_result = boost::binary_search(test, 5, pred);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_binary_search_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_binary_search()
|
||||
{
|
||||
test_binary_search_impl< std::vector<int> >();
|
||||
test_binary_search_impl< std::list<int> >();
|
||||
test_binary_search_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.binary_search" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_binary_search ) );
|
||||
|
||||
return test;
|
||||
}
|
67
test/algorithm_test/copy.cpp
Normal file
67
test/algorithm_test/copy.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_copy_impl()
|
||||
{
|
||||
Container source;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target;
|
||||
target.resize(source.size());
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t;
|
||||
iterator_t it = boost::copy(source, target.begin());
|
||||
|
||||
BOOST_CHECK( it == target.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
target.begin(), target.end(),
|
||||
source.begin(), source.end()
|
||||
);
|
||||
}
|
||||
|
||||
void test_copy()
|
||||
{
|
||||
test_copy_impl< std::vector<int> >();
|
||||
test_copy_impl< std::list<int> >();
|
||||
test_copy_impl< std::set<int> >();
|
||||
test_copy_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
64
test/algorithm_test/copy_backward.cpp
Normal file
64
test/algorithm_test/copy_backward.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/copy_backward.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_copy_backward_impl()
|
||||
{
|
||||
Container source;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target;
|
||||
target.resize(source.size());
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t;
|
||||
iterator_t it = boost::copy_backward(source, target.begin());
|
||||
|
||||
BOOST_CHECK( it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( target.begin(), target.end(),
|
||||
source.rbegin(), source.rend() );
|
||||
}
|
||||
|
||||
void test_copy_backward()
|
||||
{
|
||||
test_copy_backward_impl< std::vector<int> >();
|
||||
test_copy_backward_impl< std::list<int> >();
|
||||
test_copy_backward_impl< std::set<int> >();
|
||||
test_copy_backward_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy_backward" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_copy_backward ) );
|
||||
|
||||
return test;
|
||||
}
|
77
test/algorithm_test/count.cpp
Normal file
77
test/algorithm_test/count.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/count.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_count_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
|
||||
cont += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
|
||||
cont += 2;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cont, 2) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cref_cont, 2) );
|
||||
}
|
||||
|
||||
void test_count()
|
||||
{
|
||||
test_count_impl< std::vector<int> >();
|
||||
test_count_impl< std::list<int> >();
|
||||
test_count_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_count ) );
|
||||
|
||||
return test;
|
||||
}
|
85
test/algorithm_test/count_if.cpp
Normal file
85
test/algorithm_test/count_if.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/count_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_function/false_predicate.hpp"
|
||||
#include "../test_function/equal_to_x.hpp"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_count_if_impl()
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef equal_to_x<int> pred_t;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
|
||||
cont += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
|
||||
cont += 2;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count_if(cont, pred_t(2)) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count_if(cref_cont, pred_t(2)) );
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, false_predicate()) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, false_predicate()) );
|
||||
}
|
||||
|
||||
void test_count_if()
|
||||
{
|
||||
test_count_if_impl< std::vector<int> >();
|
||||
test_count_if_impl< std::list<int> >();
|
||||
test_count_if_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_count_if ) );
|
||||
|
||||
return test;
|
||||
}
|
103
test/algorithm_test/equal.cpp
Normal file
103
test/algorithm_test/equal.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/equal.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_equal_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
container2_t mcont2;
|
||||
|
||||
Container1& cont1 = mcont1;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1.clear();
|
||||
mcont2 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_driver()
|
||||
{
|
||||
typedef Container1 container1_t;
|
||||
typedef Container2 container2_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container1>::type const_container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container2>::type const_container2_t;
|
||||
|
||||
test_equal_impl< const_container1_t, const_container2_t >();
|
||||
test_equal_impl< const_container1_t, container2_t >();
|
||||
test_equal_impl< container1_t, const_container2_t >();
|
||||
test_equal_impl< container1_t, container2_t >();
|
||||
}
|
||||
|
||||
void test_equal()
|
||||
{
|
||||
test_driver< std::list<int>, std::list<int> >();
|
||||
test_driver< std::vector<int>, std::vector<int> >();
|
||||
test_driver< std::set<int>, std::set<int> >();
|
||||
test_driver< std::multiset<int>, std::multiset<int> >();
|
||||
test_driver< std::list<int>, std::vector<int> >();
|
||||
test_driver< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_equal ) );
|
||||
|
||||
return test;
|
||||
}
|
175
test/algorithm_test/equal_range.cpp
Normal file
175
test/algorithm_test/equal_range.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/equal_range.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container, class Pair>
|
||||
void check_result(
|
||||
const Container& reference,
|
||||
Pair reference_pair,
|
||||
const Container& test,
|
||||
Pair test_pair
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<const Container>::type
|
||||
const_iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<const_iterator_t>(reference.begin(), reference_pair.first),
|
||||
std::distance<const_iterator_t>(test.begin(), test_pair.first)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<const_iterator_t>(reference.begin(), reference_pair.second),
|
||||
std::distance<const_iterator_t>(test.begin(), test_pair.second)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_pair.first, reference_pair.second,
|
||||
test_pair.first, test_pair.second
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
typedef std::pair<iterator_t, iterator_t> pair_t;
|
||||
|
||||
pair_t reference_result
|
||||
= std::equal_range(reference.begin(), reference.end(), 5);
|
||||
|
||||
pair_t test_result = boost::equal_range(test, 5);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
container_t reference_temp(cont);
|
||||
container_t test_temp(cont);
|
||||
|
||||
sort_container(reference_temp, pred);
|
||||
sort_container(test_temp, pred);
|
||||
|
||||
Container reference(reference_temp);
|
||||
Container test(test_temp);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
typedef std::pair<iterator_t, iterator_t> pair_t;
|
||||
|
||||
pair_t reference_result
|
||||
= std::equal_range(reference.begin(), reference.end(), 5,
|
||||
BinaryPredicate());
|
||||
|
||||
pair_t test_result = boost::equal_range(test, 5, BinaryPredicate());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test, test_result);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_driver(const Container& cont)
|
||||
{
|
||||
Container mutable_cont(cont);
|
||||
test(mutable_cont);
|
||||
|
||||
test(cont);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred_driver(const Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container mutable_cont(cont);
|
||||
test_pred(mutable_cont, pred);
|
||||
|
||||
test_pred(cont, pred);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_equal_range_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_equal_range()
|
||||
{
|
||||
test_equal_range_impl< std::vector<int> >();
|
||||
test_equal_range_impl< std::list<int> >();
|
||||
test_equal_range_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal_range" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_equal_range ) );
|
||||
|
||||
return test;
|
||||
}
|
80
test/algorithm_test/fill.cpp
Normal file
80
test/algorithm_test/fill.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/fill.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_fill_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
std::fill(reference.begin(), reference.end(), 1);
|
||||
|
||||
Container target(cont);
|
||||
boost::fill(target, 1);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_fill_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 2;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_fill_impl(cont);
|
||||
}
|
||||
|
||||
void test_fill()
|
||||
{
|
||||
test_fill_impl< std::vector<int> >();
|
||||
test_fill_impl< std::list<int> >();
|
||||
test_fill_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.fill" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_fill ) );
|
||||
|
||||
return test;
|
||||
}
|
102
test/algorithm_test/find.cpp
Normal file
102
test/algorithm_test/find.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class find_test_policy
|
||||
{
|
||||
public:
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find(cont, 3);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::find<return_type>(cont, 3);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find(cont.begin(), cont.end(), 3);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_find_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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()
|
||||
{
|
||||
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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find ) );
|
||||
|
||||
return test;
|
||||
}
|
181
test/algorithm_test/find_end.cpp
Normal file
181
test/algorithm_test/find_end.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_end.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container2>
|
||||
class find_end_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_end(cont, m_cont);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::find_end<return_type>(cont, policy.cont());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
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 range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_end(cont, m_cont, m_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)
|
||||
{
|
||||
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>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_end_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_end()
|
||||
{
|
||||
test_find_end_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::list<int>, std::list<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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_end ) );
|
||||
|
||||
return test;
|
||||
}
|
181
test/algorithm_test/find_first_of.cpp
Normal file
181
test/algorithm_test/find_first_of.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_first_of.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container2>
|
||||
class find_first_of_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_first_of(cont, m_cont);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::find_first_of<return_type>(cont, policy.cont());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
class find_first_of_pred_test_policy
|
||||
{
|
||||
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 range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_first_of(cont, m_cont, m_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)
|
||||
{
|
||||
return boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_first_of_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_first_of()
|
||||
{
|
||||
test_find_first_of_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::list<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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) );
|
||||
|
||||
return test;
|
||||
}
|
123
test/algorithm_test/find_if.cpp
Normal file
123
test/algorithm_test/find_if.cpp
Normal file
@ -0,0 +1,123 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include "../test_function/greater_than_x.hpp"
|
||||
#include "../test_function/false_predicate.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class UnaryPredicate>
|
||||
class find_if_test_policy
|
||||
{
|
||||
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)
|
||||
{
|
||||
return boost::find_if(cont, m_pred);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::find_if<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
void test_find_if_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
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, 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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_if ) );
|
||||
|
||||
return test;
|
||||
}
|
86
test/algorithm_test/for_each.cpp
Normal file
86
test/algorithm_test/for_each.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/for_each.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "../test_function/check_equal_fn.hpp"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class SinglePassRange >
|
||||
void test_for_each_impl( SinglePassRange rng )
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
typedef check_equal_fn< SinglePassRange > fn_t;
|
||||
|
||||
// Test the mutable version
|
||||
fn_t result_fn = boost::for_each(rng, fn_t(rng));
|
||||
BOOST_CHECK_EQUAL( boost::distance(rng), result_fn.invocation_count() );
|
||||
|
||||
// Test the constant version
|
||||
const SinglePassRange& cref_rng = rng;
|
||||
result_fn = boost::for_each(cref_rng, fn_t(cref_rng));
|
||||
BOOST_CHECK_EQUAL( boost::distance(cref_rng), result_fn.invocation_count() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_for_each_t()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
// Test empty
|
||||
Container cont;
|
||||
test_for_each_impl(cont);
|
||||
|
||||
// Test one element
|
||||
cont += 0;
|
||||
test_for_each_impl(cont);
|
||||
|
||||
// Test many elements
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_for_each_impl(cont);
|
||||
}
|
||||
|
||||
void test_for_each()
|
||||
{
|
||||
boost::array<int, 10> a = { 0,1,2,3,4,5,6,7,8,9 };
|
||||
test_for_each_impl(a);
|
||||
|
||||
test_for_each_t< std::vector<int> >();
|
||||
test_for_each_t< std::list<int> >();
|
||||
test_for_each_t< std::set<int> >();
|
||||
test_for_each_t< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.for_each" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_for_each ) );
|
||||
|
||||
return test;
|
||||
}
|
90
test/algorithm_test/generate.cpp
Normal file
90
test/algorithm_test/generate.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/generate.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class generator_fn
|
||||
{
|
||||
public:
|
||||
typedef int result_type;
|
||||
|
||||
generator_fn() : m_count(0) {}
|
||||
int operator()() { return ++m_count; }
|
||||
|
||||
private:
|
||||
int m_count;
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
void test_generate_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
std::generate(reference.begin(), reference.end(), generator_fn());
|
||||
|
||||
Container test(cont);
|
||||
boost::generate(test, generator_fn());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_generate_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_generate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 9;
|
||||
test_generate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 9,8,7,6,5,4,3,2,1;
|
||||
test_generate_impl(cont);
|
||||
}
|
||||
|
||||
void test_generate()
|
||||
{
|
||||
test_generate_impl< std::vector<int> >();
|
||||
test_generate_impl< std::list<int> >();
|
||||
test_generate_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.generate" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_generate ) );
|
||||
|
||||
return test;
|
||||
}
|
122
test/algorithm_test/heap.cpp
Normal file
122
test/algorithm_test/heap.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/heap_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void check_equal(const Container1& cont1, const Container2& cont2)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
std::vector<int> test_cont(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::push_heap(reference.begin(), reference.end());
|
||||
boost::push_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end());
|
||||
boost::sort_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end());
|
||||
boost::pop_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
}
|
||||
|
||||
template<class BinaryPredicate>
|
||||
void test_pred(BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6,7,8,9;
|
||||
std::sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
std::vector<int> test_cont(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
reference.push_back(5);
|
||||
test_cont.push_back(5);
|
||||
std::push_heap(reference.begin(), reference.end(), pred);
|
||||
boost::push_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end(), pred);
|
||||
boost::sort_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end(), pred);
|
||||
boost::pop_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
}
|
||||
|
||||
void test_heap()
|
||||
{
|
||||
test();
|
||||
test_pred(std::less<int>());
|
||||
test_pred(std::greater<int>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.heap" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_heap ) );
|
||||
|
||||
return test;
|
||||
}
|
157
test/algorithm_test/includes.cpp
Normal file
157
test/algorithm_test/includes.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
Container1 old_cont1(cont1);
|
||||
Container2 old_cont2(cont2);
|
||||
|
||||
bool reference_result
|
||||
= std::includes(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
bool test_result = boost::includes(cont1, cont2);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont1.begin(), old_cont1.end(),
|
||||
cont1.begin(), cont1.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont2.begin(), old_cont2.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
Container1 old_cont1(cont1);
|
||||
Container2 old_cont2(cont2);
|
||||
|
||||
bool reference_result
|
||||
= std::includes(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
pred);
|
||||
|
||||
bool test_result = boost::includes(cont1, cont2, pred);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont1.begin(), old_cont1.end(),
|
||||
cont1.begin(), cont1.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont2.begin(), old_cont2.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_includes_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_includes_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_includes_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_includes()
|
||||
{
|
||||
test_includes_impl< std::vector<int>, std::vector<int> >();
|
||||
test_includes_impl< std::list<int>, std::list<int> >();
|
||||
test_includes_impl< std::deque<int>, std::deque<int> >();
|
||||
test_includes_impl< std::vector<int>, std::list<int> >();
|
||||
test_includes_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.includes" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_includes ) );
|
||||
|
||||
return test;
|
||||
}
|
145
test/algorithm_test/inplace_merge.cpp
Normal file
145
test/algorithm_test/inplace_merge.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/inplace_merge.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference_target(cont1.begin(), cont1.end());
|
||||
reference_target.insert(reference_target.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
std::vector<value_t> test_target(reference_target);
|
||||
|
||||
std::inplace_merge(reference_target.begin(),
|
||||
reference_target.begin() + cont1.size(),
|
||||
reference_target.end());
|
||||
|
||||
boost::inplace_merge(test_target,
|
||||
test_target.begin() + cont1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference_target(cont1.begin(), cont1.end());
|
||||
reference_target.insert(reference_target.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
std::vector<value_t> test_target(reference_target);
|
||||
|
||||
std::inplace_merge(reference_target.begin(),
|
||||
reference_target.begin() + cont1.size(),
|
||||
reference_target.end(), pred);
|
||||
|
||||
boost::inplace_merge(test_target,
|
||||
test_target.begin() + cont1.size(),
|
||||
pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_inplace_merge_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_inplace_merge_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,3,5,7,9,11,13,15,17,19;
|
||||
cont2 += 2,4,6,8,10,12,14,16,18,20;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_inplace_merge()
|
||||
{
|
||||
test_inplace_merge_impl< std::vector<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.inplace_merge" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_inplace_merge ) );
|
||||
|
||||
return test;
|
||||
}
|
151
test/algorithm_test/lexicographical_compare.cpp
Normal file
151
test/algorithm_test/lexicographical_compare.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/lexicographical_compare.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class ForwardRange1, class ForwardRange2>
|
||||
void test_lexicographical_compare_impl_nopred(ForwardRange1& rng1,
|
||||
ForwardRange2& rng2)
|
||||
{
|
||||
bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2));
|
||||
|
||||
bool test = boost::lexicographical_compare(rng1, rng2);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
}
|
||||
|
||||
template<class ForwardRange1, class ForwardRange2,
|
||||
class BinaryPredicate>
|
||||
void test_lexicographical_compare_impl_pred(ForwardRange1& rng1,
|
||||
ForwardRange2& rng2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2),
|
||||
pred);
|
||||
|
||||
bool test = boost::lexicographical_compare(rng1, rng2, pred);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_lexicographical_compare_impl(Container1& cont1,
|
||||
Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container1>::type value_t;
|
||||
|
||||
test_lexicographical_compare_impl_nopred(cont1, cont2);
|
||||
test_lexicographical_compare_impl_pred(cont1, cont2, std::less<value_t>());
|
||||
test_lexicographical_compare_impl_pred(cont1, cont2, std::greater<value_t>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_lexicographical_compare_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t cont1;
|
||||
container2_t cont2;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1.push_back(1);
|
||||
cont2.push_back(1);
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2;
|
||||
cont2 += 1;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
cont2 += 2;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7;
|
||||
cont2 += 1,2,3,4,5,6,7;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7;
|
||||
cont2 += 1,2,3,4,5,6;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6;
|
||||
cont2 += 1,2,3,4,5,6,7;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
}
|
||||
|
||||
template<class Container1>
|
||||
void test_lexicographical_compare_rhs()
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_value<Container1>::type value_t;
|
||||
|
||||
test_lexicographical_compare_impl<Container1, const std::vector<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, const std::deque<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, const std::list<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::vector<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::deque<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::list<value_t> >();
|
||||
}
|
||||
|
||||
void test_lexicographical_compare()
|
||||
{
|
||||
test_lexicographical_compare_rhs< const std::vector<int> >();
|
||||
test_lexicographical_compare_rhs< const std::deque<int> >();
|
||||
test_lexicographical_compare_rhs< const std::list<int> >();
|
||||
test_lexicographical_compare_rhs< std::vector<int> >();
|
||||
test_lexicographical_compare_rhs< std::deque<int> >();
|
||||
test_lexicographical_compare_rhs< std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lexicographical_compare" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_lexicographical_compare ) );
|
||||
|
||||
return test;
|
||||
}
|
172
test/algorithm_test/lower_bound.cpp
Normal file
172
test/algorithm_test/lower_bound.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/lower_bound.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/algorithm/lower_bound.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class lower_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::lower_bound(cont, 5);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::lower_bound<return_type>(cont, 5);
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::lower_bound(cont, 5, m_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)
|
||||
{
|
||||
return boost::lower_bound<return_type>(
|
||||
cont, 5, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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<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*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
149
test/algorithm_test/max_element.cpp
Normal file
149
test/algorithm_test/max_element.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/max_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class max_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::max_element(cont);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::max_element<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::max_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class max_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::max_element(cont, Pred());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::max_element<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
void test_max_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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>
|
||||
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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_max_element ) );
|
||||
|
||||
return test;
|
||||
}
|
157
test/algorithm_test/merge.cpp
Normal file
157
test/algorithm_test/merge.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/merge.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t reference_it
|
||||
= std::merge(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference_target.begin());
|
||||
|
||||
std::vector<value_t> test_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t test_it
|
||||
= boost::merge(cont1, cont2, test_target.begin());
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<iterator_t>(reference_target.begin(), reference_it),
|
||||
std::distance<iterator_t>(test_target.begin(), test_it)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t reference_it
|
||||
= std::merge(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference_target.begin(), pred);
|
||||
|
||||
std::vector<value_t> test_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t test_it
|
||||
= boost::merge(cont1, cont2, test_target.begin(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance(reference_target.begin(), reference_it),
|
||||
std::distance(test_target.begin(), test_it)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_merge_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_merge_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,3,5,7,9,11,13,15,17,19;
|
||||
cont2 += 2,4,6,8,10,12,14,16,18,20;
|
||||
test_merge_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_merge()
|
||||
{
|
||||
test_merge_impl< std::vector<int>, std::vector<int> >();
|
||||
test_merge_impl< std::list<int>, std::list<int> >();
|
||||
test_merge_impl< std::deque<int>, std::deque<int> >();
|
||||
|
||||
test_merge_impl< std::list<int>, std::vector<int> >();
|
||||
test_merge_impl< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.merge" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_merge ) );
|
||||
|
||||
return test;
|
||||
}
|
149
test/algorithm_test/min_element.cpp
Normal file
149
test/algorithm_test/min_element.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/min_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class min_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::min_element(cont);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::min_element<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::min_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class min_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::min_element(cont, Pred());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::min_element<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
void test_min_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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>
|
||||
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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_min_element ) );
|
||||
|
||||
return test;
|
||||
}
|
181
test/algorithm_test/mismatch.cpp
Normal file
181
test/algorithm_test/mismatch.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/mismatch.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_mismatch_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type MutableContainer1;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type MutableContainer2;
|
||||
|
||||
MutableContainer1 cont1;
|
||||
const Container1& cref_cont1 = cont1;
|
||||
MutableContainer2 cont2;
|
||||
const Container2& cref_cont2 = cont2;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::iterator iterator2_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::const_iterator const_iterator2_t;
|
||||
|
||||
typedef std::pair<iterator1_t, iterator2_t> pair_mmit_t;
|
||||
typedef std::pair<const_iterator1_t, iterator2_t> pair_cmit_t;
|
||||
typedef std::pair<iterator1_t, const_iterator2_t> pair_mcit_t;
|
||||
typedef std::pair<const_iterator1_t, const_iterator2_t> pair_ccit_t;
|
||||
|
||||
pair_mmit_t pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
|
||||
pair_cmit_t pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
|
||||
pair_mcit_t pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
|
||||
pair_ccit_t pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,3,4;
|
||||
pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,5,4;
|
||||
pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 );
|
||||
BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 );
|
||||
BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.begin() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.begin() );
|
||||
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 );
|
||||
BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 );
|
||||
BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.begin() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.begin() );
|
||||
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 );
|
||||
BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 );
|
||||
BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.begin() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.begin() );
|
||||
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 );
|
||||
BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 );
|
||||
BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.begin() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.begin() );
|
||||
}
|
||||
|
||||
void test_mismatch()
|
||||
{
|
||||
test_mismatch_impl< std::list<int>, std::list<int> >();
|
||||
test_mismatch_impl< const std::list<int>, std::list<int> >();
|
||||
test_mismatch_impl< std::list<int>, const std::list<int> >();
|
||||
test_mismatch_impl< const std::list<int>, const std::list<int> >();
|
||||
|
||||
test_mismatch_impl< std::vector<int>, std::list<int> >();
|
||||
test_mismatch_impl< const std::vector<int>, std::list<int> >();
|
||||
test_mismatch_impl< std::vector<int>, const std::list<int> >();
|
||||
test_mismatch_impl< const std::vector<int>, const std::list<int> >();
|
||||
|
||||
test_mismatch_impl< std::list<int>, std::vector<int> >();
|
||||
test_mismatch_impl< const std::list<int>, std::vector<int> >();
|
||||
test_mismatch_impl< std::list<int>, const std::vector<int> >();
|
||||
test_mismatch_impl< const std::list<int>, const std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.mismatch" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_mismatch ) );
|
||||
|
||||
return test;
|
||||
}
|
108
test/algorithm_test/next_permutation.cpp
Normal file
108
test/algorithm_test/next_permutation.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm/permutation.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_next_permutation_impl(const Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::next_permutation(reference.begin(), reference.end());
|
||||
|
||||
const bool test_ret
|
||||
= boost::next_permutation(test);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_next_permutation_pred_impl(const Container& cont,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::next_permutation(reference.begin(), reference.end(),
|
||||
pred);
|
||||
|
||||
const bool test_ret
|
||||
= boost::next_permutation(test, pred);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_next_permutation_(const Container& cont)
|
||||
{
|
||||
test_next_permutation_impl(cont);
|
||||
test_next_permutation_pred_impl(cont, std::less<int>());
|
||||
test_next_permutation_pred_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_next_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_next_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_next_permutation_(cont);
|
||||
}
|
||||
|
||||
void test_next_permutation()
|
||||
{
|
||||
run_tests< std::vector<int> >();
|
||||
run_tests< std::list<int> >();
|
||||
run_tests< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.next_permutation" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_next_permutation ) );
|
||||
|
||||
return test;
|
||||
}
|
149
test/algorithm_test/nth_element.cpp
Normal file
149
test/algorithm_test/nth_element.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/nth_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct nth_element_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::nth_element(cont, mid);
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
std::nth_element(cont.begin(), mid, cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class BinaryPredicate>
|
||||
struct nth_element_pred_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::nth_element(cont, mid, BinaryPredicate());
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
std::nth_element(cont.begin(), mid, cont.end(), BinaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_nth_element_tp_impl(Container& cont, TestPolicy policy)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL( reference.size(), test.size() );
|
||||
if (reference.size() != test.size())
|
||||
return;
|
||||
|
||||
iterator_t reference_mid = reference.begin();
|
||||
iterator_t test_mid = test.begin();
|
||||
|
||||
bool complete = false;
|
||||
while (!complete)
|
||||
{
|
||||
if (reference_mid == reference.end())
|
||||
complete = true;
|
||||
|
||||
policy.test_nth_element(test, test_mid);
|
||||
policy.reference_nth_element(reference, reference_mid);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
if (reference_mid != reference.end())
|
||||
{
|
||||
++reference_mid;
|
||||
++test_mid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_nth_element_impl(Container& cont)
|
||||
{
|
||||
test_nth_element_tp_impl(cont, nth_element_policy());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_nth_element_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
test_nth_element_tp_impl(cont, nth_element_pred_policy<BinaryPredicate>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests(Container& cont)
|
||||
{
|
||||
test_nth_element_impl(cont);
|
||||
test_nth_element_impl(cont, std::less<int>());
|
||||
test_nth_element_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_nth_element_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
run_tests(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
run_tests(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
run_tests(cont);
|
||||
}
|
||||
|
||||
void test_nth_element()
|
||||
{
|
||||
test_nth_element_impl< std::vector<int> >();
|
||||
test_nth_element_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.nth_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_nth_element ) );
|
||||
|
||||
return test;
|
||||
}
|
149
test/algorithm_test/partial_sort.cpp
Normal file
149
test/algorithm_test/partial_sort.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/partial_sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct partial_sort_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::partial_sort(cont, mid);
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
std::partial_sort(cont.begin(), mid, cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class BinaryPredicate>
|
||||
struct partial_sort_pred_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::partial_sort(cont, mid, BinaryPredicate());
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
std::partial_sort(cont.begin(), mid, cont.end(), BinaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_partial_sort_tp_impl(Container& cont, TestPolicy policy)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL( reference.size(), test.size() );
|
||||
if (reference.size() != test.size())
|
||||
return;
|
||||
|
||||
iterator_t reference_mid = reference.begin();
|
||||
iterator_t test_mid = test.begin();
|
||||
|
||||
bool complete = false;
|
||||
while (!complete)
|
||||
{
|
||||
if (reference_mid == reference.end())
|
||||
complete = true;
|
||||
|
||||
policy.test_partial_sort(test, test_mid);
|
||||
policy.reference_partial_sort(reference, reference_mid);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
if (reference_mid != reference.end())
|
||||
{
|
||||
++reference_mid;
|
||||
++test_mid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_partial_sort_impl(Container& cont)
|
||||
{
|
||||
test_partial_sort_tp_impl(cont, partial_sort_policy());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_partial_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
test_partial_sort_tp_impl(cont, partial_sort_pred_policy<BinaryPredicate>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_partial_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_partial_sort()
|
||||
{
|
||||
test_partial_sort_impl< std::vector<int> >();
|
||||
test_partial_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partial_sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_partial_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
111
test/algorithm_test/partition.cpp
Normal file
111
test/algorithm_test/partition.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/partition.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::partition(cont, UnaryPredicate());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::partition<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
108
test/algorithm_test/prev_permutation.cpp
Normal file
108
test/algorithm_test/prev_permutation.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm/permutation.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_prev_permutation_impl(const Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::prev_permutation(reference.begin(), reference.end());
|
||||
|
||||
const bool test_ret
|
||||
= boost::prev_permutation(test);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_prev_permutation_pred_impl(const Container& cont,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::prev_permutation(reference.begin(), reference.end(),
|
||||
pred);
|
||||
|
||||
const bool test_ret
|
||||
= boost::prev_permutation(test, pred);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_prev_permutation_(const Container& cont)
|
||||
{
|
||||
test_prev_permutation_impl(cont);
|
||||
test_prev_permutation_pred_impl(cont, std::less<int>());
|
||||
test_prev_permutation_pred_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_prev_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_prev_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_prev_permutation_(cont);
|
||||
}
|
||||
|
||||
void test_prev_permutation()
|
||||
{
|
||||
run_tests< std::vector<int> >();
|
||||
run_tests< std::list<int> >();
|
||||
run_tests< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.prev_permutation" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_prev_permutation ) );
|
||||
|
||||
return test;
|
||||
}
|
178
test/algorithm_test/random_shuffle.cpp
Normal file
178
test/algorithm_test/random_shuffle.cpp
Normal file
@ -0,0 +1,178 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/random_shuffle.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_function/counted_function.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Int>
|
||||
class counted_generator
|
||||
: private range_test_function::counted_function
|
||||
{
|
||||
public:
|
||||
typedef Int result_type;
|
||||
typedef Int argument_type;
|
||||
|
||||
using range_test_function::counted_function::invocation_count;
|
||||
|
||||
result_type operator()(argument_type modulo_value)
|
||||
{
|
||||
invoked();
|
||||
return static_cast<result_type>(std::rand() % modulo_value);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
bool test_shuffle_result(
|
||||
const Container& old_cont,
|
||||
const Container& new_cont
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<const Container>::type iterator_t;
|
||||
|
||||
// The size must remain equal
|
||||
BOOST_CHECK_EQUAL( old_cont.size(), new_cont.size() );
|
||||
if (old_cont.size() != new_cont.size())
|
||||
return false;
|
||||
|
||||
if (new_cont.size() < 2)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont.begin(), old_cont.end(),
|
||||
new_cont.begin(), new_cont.end()
|
||||
);
|
||||
|
||||
return std::equal(old_cont.begin(), old_cont.end(),
|
||||
new_cont.begin());
|
||||
}
|
||||
|
||||
// Elements must only be moved around. This is tested by
|
||||
// ensuring the count of each element remains the
|
||||
// same.
|
||||
bool failed = false;
|
||||
iterator_t last = old_cont.end();
|
||||
for (iterator_t it = old_cont.begin(); !failed && (it != last); ++it)
|
||||
{
|
||||
const std::size_t old_count
|
||||
= std::count(old_cont.begin(), old_cont.end(), *it);
|
||||
|
||||
const std::size_t new_count
|
||||
= std::count(new_cont.begin(), new_cont.end(), *it);
|
||||
|
||||
BOOST_CHECK_EQUAL( old_count, new_count );
|
||||
|
||||
failed = (old_count != new_count);
|
||||
}
|
||||
|
||||
return !failed;
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_nogen_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
const int MAX_RETRIES = 10000;
|
||||
|
||||
bool shuffled = false;
|
||||
for (int attempt = 0; !shuffled && (attempt < MAX_RETRIES); ++attempt)
|
||||
{
|
||||
Container test(cont);
|
||||
boost::random_shuffle(test);
|
||||
bool ok = test_shuffle_result(cont, test);
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
// Since the counts are equal, then if they are
|
||||
// not equal the contents must have been shuffled
|
||||
if (cont.size() == test.size()
|
||||
&& !std::equal(cont.begin(), cont.end(), test.begin()))
|
||||
{
|
||||
shuffled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandomGenerator, class Container>
|
||||
void test_random_shuffle_gen_impl(Container& cont)
|
||||
{
|
||||
RandomGenerator gen;
|
||||
Container old_cont(cont);
|
||||
boost::random_shuffle(cont, gen);
|
||||
test_shuffle_result(cont, old_cont);
|
||||
if (cont.size() > 2)
|
||||
{
|
||||
BOOST_CHECK( gen.invocation_count() > 0 );
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_impl(Container& cont)
|
||||
{
|
||||
Container old_cont(cont);
|
||||
boost::random_shuffle(cont);
|
||||
test_shuffle_result(cont, old_cont);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef counted_generator<
|
||||
BOOST_DEDUCED_TYPENAME range_difference<Container>::type > generator_t;
|
||||
|
||||
Container cont;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
}
|
||||
|
||||
void test_random_shuffle()
|
||||
{
|
||||
test_random_shuffle_impl< std::vector<int> >();
|
||||
test_random_shuffle_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.random_shuffle" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_random_shuffle ) );
|
||||
|
||||
return test;
|
||||
}
|
92
test/algorithm_test/remove.cpp
Normal file
92
test/algorithm_test/remove.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/remove.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class Value >
|
||||
void test_remove_impl( const Container& c, Value to_remove )
|
||||
{
|
||||
Container reference(c);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::remove(reference.begin(), reference.end(), to_remove);
|
||||
|
||||
Container test(c);
|
||||
iterator_t test_it = boost::remove(test, to_remove);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_impl(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_impl(cont, 0);
|
||||
test_remove_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_impl(cont, 0);
|
||||
test_remove_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_impl(cont, 1);
|
||||
test_remove_impl(cont, 9);
|
||||
test_remove_impl(cont, 4);
|
||||
}
|
||||
|
||||
void test_remove()
|
||||
{
|
||||
test_remove_impl< std::vector<int> >();
|
||||
test_remove_impl< std::list<int> >();
|
||||
test_remove_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_remove ) );
|
||||
|
||||
return test;
|
||||
}
|
99
test/algorithm_test/remove_if.cpp
Normal file
99
test/algorithm_test/remove_if.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/remove_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_remove_if_impl( const Container& c, UnaryPredicate pred )
|
||||
{
|
||||
Container reference(c);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::remove_if(reference.begin(), reference.end(), pred);
|
||||
|
||||
Container test(c);
|
||||
iterator_t test_it = boost::remove_if(test, pred);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_if_( const Container& c, int to_remove )
|
||||
{
|
||||
test_remove_if_impl(c, boost::bind(std::equal_to<int>(), _1, to_remove));
|
||||
test_remove_if_impl(c, boost::bind(std::not_equal_to<int>(), _1, to_remove));
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_if_(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_if_(cont, 0);
|
||||
test_remove_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_if_(cont, 0);
|
||||
test_remove_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_if_(cont, 1);
|
||||
test_remove_if_(cont, 9);
|
||||
test_remove_if_(cont, 4);
|
||||
}
|
||||
|
||||
inline void test_remove_if()
|
||||
{
|
||||
test_remove_if_impl< std::vector<int> >();
|
||||
test_remove_if_impl< std::list<int> >();
|
||||
test_remove_if_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_remove_if ) );
|
||||
|
||||
return test;
|
||||
}
|
79
test/algorithm_test/replace.cpp
Normal file
79
test/algorithm_test/replace.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/replace.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_replace_impl(Container& cont)
|
||||
{
|
||||
const int what = 2;
|
||||
const int with_what = 5;
|
||||
|
||||
std::vector<int> reference(cont.begin(), cont.end());
|
||||
std::replace(reference.begin(), reference.end(), what, with_what);
|
||||
|
||||
std::vector<int> target(cont.begin(), cont.end());
|
||||
boost::replace(target, what, with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_impl(cont);
|
||||
}
|
||||
|
||||
void test_replace()
|
||||
{
|
||||
test_replace_impl< std::vector<int> >();
|
||||
test_replace_impl< std::list<int> >();
|
||||
test_replace_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_replace ) );
|
||||
|
||||
return test;
|
||||
}
|
90
test/algorithm_test/replace_if.cpp
Normal file
90
test/algorithm_test/replace_if.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/replace_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_replace_if_impl(Container& cont, UnaryPredicate pred)
|
||||
{
|
||||
const int what = 2;
|
||||
const int with_what = 5;
|
||||
|
||||
std::vector<int> reference(cont.begin(), cont.end());
|
||||
std::replace_if(reference.begin(), reference.end(),
|
||||
boost::bind(pred, _1, what), with_what);
|
||||
|
||||
std::vector<int> target(cont.begin(), cont.end());
|
||||
boost::replace_if(target, boost::bind(pred, _1, what), with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_if_impl(Container& cont)
|
||||
{
|
||||
test_replace_if_impl(cont, std::equal_to<int>());
|
||||
test_replace_if_impl(cont, std::not_equal_to<int>());
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_if_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_if_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_if_impl(cont);
|
||||
}
|
||||
|
||||
void test_replace_if()
|
||||
{
|
||||
test_replace_if_impl< std::vector<int> >();
|
||||
test_replace_if_impl< std::list<int> >();
|
||||
test_replace_if_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_replace_if ) );
|
||||
|
||||
return test;
|
||||
}
|
78
test/algorithm_test/reverse.cpp
Normal file
78
test/algorithm_test/reverse.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/reverse.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_reverse_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::reverse(test);
|
||||
std::reverse(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_reverse_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_reverse_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_reverse_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_reverse_impl(cont);
|
||||
}
|
||||
|
||||
void test_reverse()
|
||||
{
|
||||
test_reverse_impl< std::vector<int> >();
|
||||
test_reverse_impl< std::list<int> >();
|
||||
test_reverse_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.reverse" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_reverse ) );
|
||||
|
||||
return test;
|
||||
}
|
99
test/algorithm_test/rotate.cpp
Normal file
99
test/algorithm_test/rotate.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/rotate.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_rotate_impl(Container& cont, Iterator where_it)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
Iterator reference_where_it = reference.begin();
|
||||
std::advance(reference_where_it,
|
||||
std::distance(cont.begin(), where_it));
|
||||
|
||||
std::rotate(reference.begin(), reference_where_it, reference.end());
|
||||
|
||||
Iterator test_where_it = test.begin();
|
||||
std::advance(test_where_it,
|
||||
std::distance(cont.begin(), where_it));
|
||||
|
||||
boost::rotate(test, test_where_it);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
iterator_t last = cont.end();
|
||||
for (iterator_t it = cont.begin(); it != last; ++it)
|
||||
{
|
||||
test_rotate_impl(cont, it);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_rotate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_rotate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_rotate_impl(cont);
|
||||
}
|
||||
|
||||
void test_rotate()
|
||||
{
|
||||
test_rotate_impl< std::vector<int> >();
|
||||
test_rotate_impl< std::list<int> >();
|
||||
test_rotate_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_rotate ) );
|
||||
|
||||
return test;
|
||||
}
|
97
test/algorithm_test/search.cpp
Normal file
97
test/algorithm_test/search.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/search.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_search_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
|
||||
const Container1& ccont1 = cont1;
|
||||
const Container2& ccont2 = cont2;
|
||||
|
||||
iterator1_t it = boost::search(cont1, cont2);
|
||||
iterator1_t it2 = boost::search(cont1, ccont2);
|
||||
const_iterator1_t cit = boost::search(ccont1, cont2);
|
||||
const_iterator1_t cit2 = boost::search(ccont1, ccont2);
|
||||
|
||||
BOOST_CHECK( it == std::search(cont1.begin(), cont1.end(), cont2.begin(), cont2.end()) );
|
||||
BOOST_CHECK( it2 == std::search(cont1.begin(), cont1.end(), ccont2.begin(), ccont2.end()) );
|
||||
BOOST_CHECK( cit == std::search(ccont1.begin(), ccont1.end(), cont2.begin(), cont2.end()) );
|
||||
BOOST_CHECK( cit2 == std::search(ccont1.begin(), ccont1.end(), ccont2.begin(), ccont2.end()) );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_search_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 10,11,12;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont2.clear();
|
||||
cont2 += 4,5,6;
|
||||
test_search_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_search()
|
||||
{
|
||||
test_search_impl< std::list<int>, std::list<int> >();
|
||||
test_search_impl< std::vector<int>, std::vector<int> >();
|
||||
test_search_impl< std::set<int>, std::set<int> >();
|
||||
test_search_impl< std::list<int>, std::vector<int> >();
|
||||
test_search_impl< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.search" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_search ) );
|
||||
|
||||
return test;
|
||||
}
|
170
test/algorithm_test/set_difference.cpp
Normal file
170
test/algorithm_test/set_difference.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_difference(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_difference(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_difference_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_difference_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_difference()
|
||||
{
|
||||
test_set_difference_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_difference_impl< std::list<int>, std::list<int> >();
|
||||
test_set_difference_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_difference_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_difference_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_difference" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_difference ) );
|
||||
|
||||
return test;
|
||||
}
|
170
test/algorithm_test/set_intersection.cpp
Normal file
170
test/algorithm_test/set_intersection.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_intersection(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_intersection(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_intersection(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_intersection(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_intersection_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_intersection_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_intersection()
|
||||
{
|
||||
test_set_intersection_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_intersection_impl< std::list<int>, std::list<int> >();
|
||||
test_set_intersection_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_intersection_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_intersection_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_intersection" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_intersection ) );
|
||||
|
||||
return test;
|
||||
}
|
172
test/algorithm_test/set_symmetric_difference.cpp
Normal file
172
test/algorithm_test/set_symmetric_difference.cpp
Normal file
@ -0,0 +1,172 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_symmetric_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_symmetric_difference(cont1, cont2,
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_symmetric_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_symmetric_difference(cont1, cont2,
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_symmetric_difference_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_symmetric_difference_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_symmetric_difference()
|
||||
{
|
||||
test_set_symmetric_difference_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_symmetric_difference_impl< std::list<int>, std::list<int> >();
|
||||
test_set_symmetric_difference_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_symmetric_difference_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_symmetric_difference_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_symmetric_difference" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_symmetric_difference ) );
|
||||
|
||||
return test;
|
||||
}
|
170
test/algorithm_test/set_union.cpp
Normal file
170
test/algorithm_test/set_union.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_union(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_union(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_union(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_union(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_union_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_union_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_union()
|
||||
{
|
||||
test_set_union_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_union_impl< std::list<int>, std::list<int> >();
|
||||
test_set_union_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_union_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_union_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_union" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_union ) );
|
||||
|
||||
return test;
|
||||
}
|
97
test/algorithm_test/sort.cpp
Normal file
97
test/algorithm_test/sort.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_sort_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::sort(test);
|
||||
std::sort(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::sort(test, pred);
|
||||
std::sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_sort()
|
||||
{
|
||||
test_sort_impl< std::vector<int> >();
|
||||
test_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
112
test/algorithm_test/stable_partition.cpp
Normal file
112
test/algorithm_test/stable_partition.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/stable_partition.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class stable_partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::stable_partition(cont, UnaryPredicate());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::stable_partition<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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>
|
||||
void test_stable_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
97
test/algorithm_test/stable_sort.cpp
Normal file
97
test/algorithm_test/stable_sort.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/stable_sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_stable_sort_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::stable_sort(test);
|
||||
std::stable_sort(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_stable_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::stable_sort(test, pred);
|
||||
std::stable_sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_stable_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_stable_sort()
|
||||
{
|
||||
test_stable_sort_impl< std::vector<int> >();
|
||||
test_stable_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_stable_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
158
test/algorithm_test/transform.cpp
Normal file
158
test/algorithm_test/transform.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/transform.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_function/multiply_by_x.hpp"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_transform_impl1(Container& cont)
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
const Container& ccont = cont;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target(cont.size());
|
||||
std::vector<value_t> reference(cont.size());
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
multiply_by_x<int> fn(2);
|
||||
|
||||
iterator_t reference_it
|
||||
= std::transform(cont.begin(), cont.end(), reference.begin(), fn);
|
||||
|
||||
iterator_t test_it
|
||||
= boost::transform(cont, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
target.clear();
|
||||
target.resize(ccont.size());
|
||||
|
||||
test_it = boost::transform(ccont, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_transform_impl1()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_transform_impl1(cont);
|
||||
|
||||
cont += 1;
|
||||
test_transform_impl1(cont);
|
||||
|
||||
cont += 2,3,4,5,6,7;
|
||||
test_transform_impl1(cont);
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_transform_impl2(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
const Container1& ccont1 = cont1;
|
||||
const Container2& ccont2 = cont2;
|
||||
|
||||
BOOST_CHECK_EQUAL( cont1.size(), cont2.size() );
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
|
||||
std::vector<value_t> target(cont1.size());
|
||||
std::vector<value_t> reference(cont1.size());
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::multiplies<int> fn;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::transform(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), reference.begin(), fn);
|
||||
|
||||
iterator_t test_it
|
||||
= boost::transform(cont1, cont2, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
target.clear();
|
||||
target.resize(ccont1.size());
|
||||
|
||||
test_it = boost::transform(ccont1, ccont2, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_transform_impl2()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_transform_impl2(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
cont2 += 2;
|
||||
test_transform_impl2(cont1, cont2);
|
||||
|
||||
cont1 += 2,3,4,5,6,7;
|
||||
cont2 += 4,6,8,10,12,14;
|
||||
test_transform_impl2(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_transform()
|
||||
{
|
||||
test_transform_impl1< std::vector<int> >();
|
||||
test_transform_impl1< std::list<int> >();
|
||||
test_transform_impl1< std::set<int> >();
|
||||
test_transform_impl1< std::multiset<int> >();
|
||||
|
||||
test_transform_impl2< std::vector<int>, std::list<int> >();
|
||||
test_transform_impl2< std::list<int>, std::vector<int> >();
|
||||
test_transform_impl2< std::set<int>, std::set<int> >();
|
||||
test_transform_impl2< std::multiset<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.transform" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_transform ) );
|
||||
|
||||
return test;
|
||||
}
|
166
test/algorithm_test/unique.cpp
Normal file
166
test/algorithm_test/unique.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/unique.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// test the 'unique' algorithm without a predicate
|
||||
class unique_test_policy
|
||||
{
|
||||
public:
|
||||
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());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::unique<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
// test the 'unique' algorithm with a predicate
|
||||
template<class Pred>
|
||||
class unique_pred_test_policy
|
||||
{
|
||||
public:
|
||||
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(); }
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::unique<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy, class Pred>
|
||||
void test_unique_impl(TestPolicy policy, Pred pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
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>
|
||||
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> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_unique ) );
|
||||
|
||||
return test;
|
||||
}
|
170
test/algorithm_test/upper_bound.cpp
Normal file
170
test/algorithm_test/upper_bound.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/upper_bound.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class upper_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::upper_bound(cont, 5);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::upper_bound<result_type>(cont, 5);
|
||||
}
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::upper_bound(cont, 5, BinaryPredicate());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return boost::upper_bound<result_type>(
|
||||
cont, 5, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
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<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()
|
||||
{
|
||||
test_upper_bound_impl< std::vector<int> >();
|
||||
test_upper_bound_impl< std::list<int> >();
|
||||
test_upper_bound_impl< std::deque<int> >();
|
||||
|
||||
test_upper_bound_impl< const std::vector<int> >();
|
||||
test_upper_bound_impl< const std::list<int> >();
|
||||
test_upper_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
Reference in New Issue
Block a user