mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-06-02 05:54:41 -04:00
Squashed 'boost/' content from commit b4feb19f2
git-subtree-dir: boost git-subtree-split: b4feb19f287ee92d87a9624b5d36b7cf46aeadeb
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
// 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/range/iterator_range.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(boost::make_iterator_range(cont)) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont), pred) == 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(boost::make_iterator_range(cont)) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(boost::make_iterator_range(cont), pred) == 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 );
|
||||
}
|
||||
BOOST_CHECK( it == boost::adjacent_find(boost::make_iterator_range(cont)) );
|
||||
BOOST_CHECK( it_pred == boost::adjacent_find(boost::make_iterator_range(cont), pred) );
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// 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( test_result == boost::binary_search(boost::make_iterator_range(test), 5) );
|
||||
|
||||
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( test_result == boost::binary_search(boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// 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()
|
||||
);
|
||||
|
||||
it = boost::copy(boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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/
|
||||
//
|
||||
// Credits:
|
||||
// awulkiew highlighted that this test was not successfully testing the
|
||||
// algorithm.
|
||||
//
|
||||
#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 <vector>
|
||||
|
||||
namespace boost_range_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<typename Container>
|
||||
void test_copy_backward_impl(std::size_t n)
|
||||
{
|
||||
Container source;
|
||||
typedef typename Container::value_type value_t;
|
||||
for (std::size_t i = 0; i < n; ++i)
|
||||
source.push_back(static_cast<value_t>(i));
|
||||
|
||||
std::vector<value_t> target(n);
|
||||
|
||||
typedef typename boost::range_iterator<
|
||||
std::vector<value_t>
|
||||
>::type iterator_t;
|
||||
|
||||
iterator_t it = boost::copy_backward(source, target.end());
|
||||
|
||||
BOOST_CHECK(it == target.begin());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
|
||||
source.begin(), source.end());
|
||||
|
||||
BOOST_CHECK(it == boost::copy_backward(
|
||||
boost::make_iterator_range(source), target.end()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
|
||||
source.begin(), source.end());
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
void test_copy_backward_impl()
|
||||
{
|
||||
test_copy_backward_impl<Container>(0u);
|
||||
test_copy_backward_impl<Container>(1u);
|
||||
test_copy_backward_impl<Container>(100u);
|
||||
}
|
||||
|
||||
void test_copy_backward()
|
||||
{
|
||||
test_copy_backward_impl<std::vector<int> >();
|
||||
test_copy_backward_impl<std::list<int> >();
|
||||
}
|
||||
} // anonymous namespace
|
||||
} // namespace boost_range_test
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int, char*[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE("RangeTestSuite.algorithm.copy_backward");
|
||||
|
||||
test->add(BOOST_TEST_CASE(&boost_range_test::test_copy_backward));
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// 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_n.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
|
||||
{
|
||||
template< class Container >
|
||||
void test_copy_n_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()
|
||||
);
|
||||
|
||||
it = boost::copy(boost::make_iterator_range(source), target.begin());
|
||||
|
||||
BOOST_CHECK( it == target.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
|
||||
source.begin(), source.end());
|
||||
}
|
||||
|
||||
void test_copy_n()
|
||||
{
|
||||
test_copy_n_impl< std::vector<int> >();
|
||||
test_copy_n_impl< std::list<int> >();
|
||||
test_copy_n_impl< std::set<int> >();
|
||||
test_copy_n_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_n" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &::test_copy_n ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -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.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, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(boost::make_iterator_range(cont), 0u) );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(boost::make_iterator_range(cont), 0u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(boost::make_iterator_range(cont), 1u) );
|
||||
|
||||
cont += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(boost::make_iterator_range(cont), 0u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(boost::make_iterator_range(cont), 1u) );
|
||||
|
||||
cont += 2;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0u) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(boost::make_iterator_range(cont), 0u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1u) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(boost::make_iterator_range(cont), 1u) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cont, 2u) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cref_cont, 2u) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(boost::make_iterator_range(cont), 2u) );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// 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/true_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;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<BOOST_DEDUCED_TYPENAME Container::iterator>::difference_type diff_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)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(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( 0u, boost::count_if(boost::make_iterator_range(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( 1u, boost::count_if(boost::make_iterator_range(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( 0u, boost::count_if(boost::make_iterator_range(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( 1u, boost::count_if(boost::make_iterator_range(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( 0u, boost::count_if(boost::make_iterator_range(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( 1u, boost::count_if(boost::make_iterator_range(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( 2u, boost::count_if(boost::make_iterator_range(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()) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(boost::make_iterator_range(cont), false_predicate()) );
|
||||
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(cref_cont, true_predicate()) );
|
||||
BOOST_CHECK_EQUAL( static_cast<diff_t>(cont.size()), boost::count_if(boost::make_iterator_range(cont), true_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;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// 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(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
|
||||
|
||||
mcont1.clear();
|
||||
mcont2 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(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(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), cont2, std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, boost::make_iterator_range(cont2), std::not_equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(boost::make_iterator_range(cont1), boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// 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);
|
||||
|
||||
pair_t test_result2 = boost::equal_range(boost::make_iterator_range(test), 5);
|
||||
|
||||
check_result(reference, reference_result, test, test_result2);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
pair_t test_result2 = boost::equal_range(boost::make_iterator_range(test), 5, BinaryPredicate());
|
||||
|
||||
check_result(reference, reference_result, test, test_result2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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/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() );
|
||||
|
||||
Container target2(cont);
|
||||
boost::fill(boost::make_iterator_range(target2), 1);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target2.begin(), target2.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;
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// 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_range_test_algorithm_find
|
||||
{
|
||||
class find_test_policy
|
||||
{
|
||||
public:
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find(cont, 3);
|
||||
iter_t result2 = boost::find(boost::make_iterator_range(cont), 3);
|
||||
BOOST_CHECK( result == result2 );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find<return_type>(cont, 3);
|
||||
result_t result2 = boost::find<return_type>(boost::make_iterator_range(cont), 3);
|
||||
BOOST_CHECK( result == result2 );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::remove_const<Container>::type container_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, find_test_policy());
|
||||
}
|
||||
|
||||
void test_find()
|
||||
{
|
||||
test_find_container< std::vector<int> >();
|
||||
test_find_container< std::list<int> >();
|
||||
test_find_container< std::deque<int> >();
|
||||
|
||||
test_find_container< const std::vector<int> >();
|
||||
test_find_container< const std::list<int> >();
|
||||
test_find_container< const std::deque<int> >();
|
||||
|
||||
std::vector<int> vi;
|
||||
const std::vector<int>& cvi = vi;
|
||||
std::vector<int>::const_iterator it = boost::find(vi, 0);
|
||||
std::vector<int>::const_iterator it2 = boost::find(cvi, 0);
|
||||
BOOST_CHECK( it == it2 );
|
||||
}
|
||||
|
||||
// The find algorithm can be used like a "contains" algorithm
|
||||
// since the returned iterator_range is convertible to bool.
|
||||
// Therefore if the return value is an empty range it will
|
||||
// convert to the equivalent to "false" whereas a range that
|
||||
// is not empty will convert to "true". Therefore one can
|
||||
// use the syntax boost::find<boost::return_found_end>(rng, x)
|
||||
// as a contains function.
|
||||
void test_find_as_contains()
|
||||
{
|
||||
std::list<int> l;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
l.push_back(i);
|
||||
|
||||
BOOST_CHECK(boost::find<boost::return_found_end>(l, 3));
|
||||
BOOST_CHECK(!boost::find<boost::return_found_end>(l, 10));
|
||||
}
|
||||
}
|
||||
|
||||
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_range_test_algorithm_find::test_find ) );
|
||||
test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find::test_find_as_contains ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
// 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_range_test_algorithm_find_end
|
||||
{
|
||||
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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_end(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t it = boost::find_end(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
return it;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_end<return_type>(boost::make_iterator_range(cont),
|
||||
boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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)
|
||||
{
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_end_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_end_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;
|
||||
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_range_test_algorithm_find_end::test_find_end ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// 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_range_test_algorithm_find_first_of
|
||||
{
|
||||
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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont())) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_first_of(cont, m_cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) );
|
||||
BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), policy.cont(), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(cont, boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
BOOST_CHECK( result == boost::find_first_of<return_type>(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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)
|
||||
{
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_first_of_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_first_of_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;
|
||||
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_range_test_algorithm_find_first_of::test_find_first_of ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// 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_range_test_algorithm_find_if
|
||||
{
|
||||
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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::find_if(cont, m_pred);
|
||||
BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(find_if_test_policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::find_if<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::find_if<return_type>(boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::remove_const<Container>::type container_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
}
|
||||
|
||||
void test_find_if()
|
||||
{
|
||||
test_find_if_container< std::vector<int> >();
|
||||
test_find_if_container< std::list<int> >();
|
||||
test_find_if_container< std::deque<int> >();
|
||||
|
||||
test_find_if_container< const std::vector<int> >();
|
||||
test_find_if_container< const std::list<int> >();
|
||||
test_find_if_container< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
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_range_test_algorithm_find_if::test_find_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// 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 Range >
|
||||
unsigned int udistance(Range& rng)
|
||||
{
|
||||
return static_cast<unsigned int>(boost::distance(rng));
|
||||
}
|
||||
|
||||
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::udistance(rng), result_fn.invocation_count() );
|
||||
|
||||
fn_t result_fn2 = boost::for_each(boost::make_iterator_range(rng), fn_t(rng));
|
||||
BOOST_CHECK_EQUAL( boost::udistance(rng), result_fn2.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::udistance(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;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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() );
|
||||
|
||||
Container test2(cont);
|
||||
boost::generate(boost::make_iterator_range(test2), generator_fn());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -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/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::vector<int> test_cont2(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2));
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
std::push_heap(reference.begin(), reference.end());
|
||||
boost::push_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
boost::push_heap(boost::make_iterator_range(test_cont2));
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2));
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end());
|
||||
boost::sort_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
boost::sort_heap(boost::make_iterator_range(test_cont2));
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2));
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end());
|
||||
boost::pop_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
boost::pop_heap(boost::make_iterator_range(test_cont2));
|
||||
check_equal(reference, test_cont2);
|
||||
}
|
||||
|
||||
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::vector<int> test_cont2(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
reference.push_back(5);
|
||||
test_cont.push_back(5);
|
||||
test_cont2.push_back(5);
|
||||
std::push_heap(reference.begin(), reference.end(), pred);
|
||||
boost::push_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
boost::push_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end(), pred);
|
||||
boost::sort_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
boost::sort_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
check_equal(reference, test_cont2);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
boost::make_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end(), pred);
|
||||
boost::pop_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
boost::pop_heap(boost::make_iterator_range(test_cont2), pred);
|
||||
check_equal(reference, test_cont2);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
// 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()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( test_result == boost::includes(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2)) );
|
||||
}
|
||||
|
||||
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()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), cont2, pred) );
|
||||
BOOST_CHECK( test_result == boost::includes(cont1, boost::make_iterator_range(cont2), pred) );
|
||||
BOOST_CHECK( test_result == boost::includes(boost::make_iterator_range(cont1), boost::make_iterator_range(cont2), pred) );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
// 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 BOOST_RANGE_UNUSED;
|
||||
|
||||
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::vector<value_t> test_target2(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()
|
||||
);
|
||||
|
||||
boost::inplace_merge(boost::make_iterator_range(test_target2),
|
||||
test_target2.begin() + cont1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target2.begin(), test_target2.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 BOOST_RANGE_UNUSED;
|
||||
|
||||
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::vector<value_t> test_target2(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()
|
||||
);
|
||||
|
||||
boost::inplace_merge(boost::make_iterator_range(test_target2),
|
||||
test_target2.begin() + cont1.size(),
|
||||
pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target2.begin(), test_target2.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;
|
||||
}
|
||||
@@ -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/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)
|
||||
{
|
||||
const bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2));
|
||||
|
||||
const bool test = boost::lexicographical_compare(rng1, rng2);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), rng2) );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(rng1, boost::make_iterator_range(rng2)) );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), boost::make_iterator_range(rng2)) );
|
||||
}
|
||||
|
||||
template<class ForwardRange1, class ForwardRange2,
|
||||
class BinaryPredicate>
|
||||
void test_lexicographical_compare_impl_pred(ForwardRange1& rng1,
|
||||
ForwardRange2& rng2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
const bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2),
|
||||
pred);
|
||||
|
||||
const bool test = boost::lexicographical_compare(rng1, rng2, pred);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), rng2, pred) );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(rng1, boost::make_iterator_range(rng2), pred) );
|
||||
BOOST_CHECK( test == boost::lexicographical_compare(boost::make_iterator_range(rng1), boost::make_iterator_range(rng2), pred) );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// 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_range_test_algorithm_lower_bound
|
||||
{
|
||||
class lower_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct lower_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::lower_bound(cont, 5, m_pred);
|
||||
BOOST_CHECK( result == boost::lower_bound(
|
||||
boost::make_iterator_range(cont), 5, m_pred) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::lower_bound<return_type>(cont, 5, policy.pred());
|
||||
BOOST_CHECK( result == boost::lower_bound<return_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_lower_bound_impl()
|
||||
{
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_lower_bound()
|
||||
{
|
||||
test_lower_bound_impl< std::vector<int> >();
|
||||
test_lower_bound_impl< std::list<int> >();
|
||||
test_lower_bound_impl< std::deque<int> >();
|
||||
|
||||
test_lower_bound_impl< const std::vector<int> >();
|
||||
test_lower_bound_impl< const std::list<int> >();
|
||||
test_lower_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
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_range_test_algorithm_lower_bound::test_lower_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
// 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_range_test_algorithm_max_element
|
||||
{
|
||||
class max_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont);
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::max_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::max_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::max_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::max_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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 BOOST_RANGE_UNUSED;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type
|
||||
container_t;
|
||||
|
||||
boost::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_range_test_algorithm_max_element::test_max_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
// 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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(boost::make_iterator_range(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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(cont1, boost::make_iterator_range(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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(boost::make_iterator_range(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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(cont1, boost::make_iterator_range(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()
|
||||
);
|
||||
|
||||
test_it = boost::merge(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// 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_range_test_algorithm_min_element
|
||||
{
|
||||
class min_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont);
|
||||
BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont);
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(boost::make_iterator_range(cont)) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::min_element(cont, Pred());
|
||||
BOOST_CHECK( result == boost::min_element(
|
||||
boost::make_iterator_range(cont), Pred()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
result_t result = boost::min_element<return_type>(cont, policy.pred());
|
||||
BOOST_CHECK( result == boost::min_element<return_type>(
|
||||
boost::make_iterator_range(cont), policy.pred()) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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 BOOST_RANGE_UNUSED;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type
|
||||
container_t;
|
||||
|
||||
boost::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_range_test_algorithm_min_element::test_min_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
// 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 eval_mismatch(Container1& cont1,
|
||||
Container2& cont2,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type ref_it1,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type ref_it2
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type iter1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type iter2_t;
|
||||
typedef std::pair<iter1_t, iter2_t> result_pair_t;
|
||||
|
||||
result_pair_t result = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
cont2);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(cont1,
|
||||
boost::make_iterator_range(cont2));
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2));
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2, class Pred >
|
||||
void eval_mismatch(Container1& cont1,
|
||||
Container2& cont2,
|
||||
Pred pred,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type ref_it1,
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type ref_it2
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type iter1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type iter2_t;
|
||||
typedef std::pair<iter1_t, iter2_t> result_pair_t;
|
||||
|
||||
result_pair_t result = boost::mismatch(cont1, cont2, pred);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
cont2, pred);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(cont1,
|
||||
boost::make_iterator_range(cont2), pred);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2),
|
||||
pred);
|
||||
BOOST_CHECK( result.first == ref_it1 );
|
||||
BOOST_CHECK( result.second == ref_it2 );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void eval_mismatch(Container1& cont1,
|
||||
Container2& cont2,
|
||||
const int ref1,
|
||||
const int ref2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type iter1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type iter2_t;
|
||||
typedef std::pair<iter1_t, iter2_t> result_pair_t;
|
||||
|
||||
result_pair_t result = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1), cont2);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(cont1, boost::make_iterator_range(cont2));
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2));
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2, class Pred >
|
||||
void eval_mismatch(Container1& cont1,
|
||||
Container2& cont2,
|
||||
Pred pred,
|
||||
const int ref1,
|
||||
const int ref2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container1>::type iter1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container2>::type iter2_t;
|
||||
typedef std::pair<iter1_t, iter2_t> result_pair_t;
|
||||
|
||||
result_pair_t result = boost::mismatch(cont1, cont2, pred);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
cont2, pred);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(cont1, boost::make_iterator_range(cont2),
|
||||
pred);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
|
||||
result = boost::mismatch(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2),
|
||||
pred);
|
||||
BOOST_CHECK_EQUAL( ref1, *result.first );
|
||||
BOOST_CHECK_EQUAL( ref2, *result.second );
|
||||
}
|
||||
|
||||
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 BOOST_RANGE_UNUSED;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator
|
||||
const_iterator1_t BOOST_RANGE_UNUSED;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::iterator
|
||||
iterator2_t BOOST_RANGE_UNUSED;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::const_iterator
|
||||
const_iterator2_t BOOST_RANGE_UNUSED;
|
||||
|
||||
eval_mismatch(cont1, cont2, cont1.end(), cont2.end());
|
||||
eval_mismatch(cont1, cont2, std::equal_to<int>(), cont1.end(), cont2.end());
|
||||
eval_mismatch(cref_cont1, cont2, cref_cont1.end(), cont2.end());
|
||||
eval_mismatch(cref_cont1, cont2, std::equal_to<int>(), cref_cont1.end(), cont2.end());
|
||||
eval_mismatch(cont1, cref_cont2, cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cont1, cref_cont2, std::equal_to<int>(), cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cref_cont1, cref_cont2, cref_cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cref_cont1, cref_cont2, std::equal_to<int>(), cref_cont1.end(), cref_cont2.end());
|
||||
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,3,4;
|
||||
eval_mismatch(cont1, cont2, cont1.end(), cont2.end());
|
||||
eval_mismatch(cont1, cont2, std::equal_to<int>(), cont1.end(), cont2.end());
|
||||
eval_mismatch(cref_cont1, cont2, cref_cont1.end(), cont2.end());
|
||||
eval_mismatch(cref_cont1, cont2, std::equal_to<int>(), cref_cont1.end(), cont2.end());
|
||||
eval_mismatch(cont1, cref_cont2, cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cont1, cref_cont2, std::equal_to<int>(), cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cref_cont1, cref_cont2, cref_cont1.end(), cref_cont2.end());
|
||||
eval_mismatch(cref_cont1, cref_cont2, std::equal_to<int>(), cref_cont1.end(), cref_cont2.end());
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,5,4;
|
||||
eval_mismatch(cont1, cont2, 3, 5);
|
||||
eval_mismatch(cont1, cont2, std::equal_to<int>(), 3, 5);
|
||||
eval_mismatch(cont1, cont2, std::not_equal_to<int>(), cont1.begin(), cont2.begin());
|
||||
eval_mismatch(cref_cont1, cont2, 3, 5);
|
||||
eval_mismatch(cref_cont1, cont2, std::equal_to<int>(), 3, 5);
|
||||
eval_mismatch(cref_cont1, cont2, std::not_equal_to<int>(), cref_cont1.begin(), cont2.begin());
|
||||
eval_mismatch(cont1, cref_cont2, 3, 5);
|
||||
eval_mismatch(cont1, cref_cont2, std::equal_to<int>(), 3, 5);
|
||||
eval_mismatch(cont1, cref_cont2, std::not_equal_to<int>(), cont1.begin(), cref_cont2.begin());
|
||||
eval_mismatch(cref_cont1, cref_cont2, 3, 5);
|
||||
eval_mismatch(cref_cont1, cref_cont2, std::equal_to<int>(), 3, 5);
|
||||
eval_mismatch(cref_cont1, cref_cont2, std::not_equal_to<int>(), cref_cont1.begin(), 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;
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
// 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()
|
||||
);
|
||||
|
||||
test = cont;
|
||||
|
||||
BOOST_CHECK( test_ret == boost::next_permutation(boost::make_iterator_range(test)) );
|
||||
|
||||
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()
|
||||
);
|
||||
|
||||
test = cont;
|
||||
|
||||
BOOST_CHECK( test_ret == boost::next_permutation(boost::make_iterator_range(test), pred) );
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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/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)
|
||||
{
|
||||
const Container old_cont(cont);
|
||||
|
||||
boost::nth_element(cont, mid);
|
||||
|
||||
// Test the same operation on the container, for the
|
||||
// case where a temporary is passed as the first
|
||||
// argument.
|
||||
Container cont2(old_cont);
|
||||
const std::size_t index = std::distance(cont.begin(), mid);
|
||||
Iterator mid2(cont2.begin());
|
||||
std::advance(mid2, index);
|
||||
boost::nth_element(boost::make_iterator_range(cont2), mid2);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const Container old_cont(cont);
|
||||
|
||||
boost::nth_element(cont, mid, BinaryPredicate());
|
||||
|
||||
Container cont2(old_cont);
|
||||
const std::size_t index = std::distance(cont.begin(), mid);
|
||||
Iterator mid2(cont2.begin());
|
||||
std::advance(mid2, index);
|
||||
boost::nth_element(boost::make_iterator_range(cont2), mid2,
|
||||
BinaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
// 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)
|
||||
{
|
||||
const Container old_cont(cont);
|
||||
|
||||
boost::partial_sort(cont, mid);
|
||||
|
||||
const std::size_t index = std::distance(cont.begin(), mid);
|
||||
Container cont2(old_cont);
|
||||
Iterator mid2(cont2.begin());
|
||||
std::advance(mid2, index);
|
||||
boost::partial_sort(cont2, mid2);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const Container old_cont(cont);
|
||||
|
||||
boost::partial_sort(cont, mid, BinaryPredicate());
|
||||
|
||||
const std::size_t index = std::distance(cont.begin(), mid);
|
||||
Container cont2(old_cont);
|
||||
Iterator mid2(cont2.begin());
|
||||
std::advance(mid2, index);
|
||||
boost::partial_sort(cont2, mid2, BinaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
// 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_range_test_algorithm_partition
|
||||
{
|
||||
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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
|
||||
const Container old_cont(cont);
|
||||
Container cont2(old_cont);
|
||||
iter_t result = boost::partition(cont, UnaryPredicate());
|
||||
|
||||
boost::partition(cont2, UnaryPredicate());
|
||||
cont2 = old_cont;
|
||||
boost::partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
const Container old_cont(cont);
|
||||
Container cont2(old_cont);
|
||||
result_t result = boost::partition<return_type>(cont, policy.pred());
|
||||
|
||||
// Test that operation a temporary created by using
|
||||
// make_iterator_range.
|
||||
boost::partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_partition()
|
||||
{
|
||||
test_partition_impl< std::vector<int> >();
|
||||
test_partition_impl< std::list<int> >();
|
||||
test_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
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_range_test_algorithm_partition::test_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
// 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);
|
||||
Container test2(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()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_ret == boost::prev_permutation(
|
||||
boost::make_iterator_range(test2)) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test2.begin(), test2.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_prev_permutation_pred_impl(const Container& cont,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
Container test2(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()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_ret == boost::prev_permutation(
|
||||
boost::make_iterator_range(test2), pred) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// 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 BOOST_RANGE_UNUSED;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Verify that the shuffle can be performed on a
|
||||
// temporary range
|
||||
Container test2(cont);
|
||||
boost::random_shuffle(boost::make_iterator_range(test2));
|
||||
ok = test_shuffle_result(cont, test2);
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
// Test that random shuffle works when
|
||||
// passed a temporary range
|
||||
RandomGenerator gen2;
|
||||
Container cont2(old_cont);
|
||||
boost::random_shuffle(boost::make_iterator_range(cont2), gen2);
|
||||
test_shuffle_result(cont2, old_cont);
|
||||
if (cont2.size() > 2)
|
||||
{
|
||||
BOOST_CHECK( gen2.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;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// 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() );
|
||||
|
||||
Container test2(c);
|
||||
iterator_t test_it2 = boost::remove(test2, to_remove);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test2.begin(), test_it2),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// 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_copy.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
|
||||
{
|
||||
template<typename Iterator, typename Value>
|
||||
void test_append(Iterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template< class Container, class Value >
|
||||
void test_remove_copy_impl( const Container& c, Value to_remove )
|
||||
{
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_type>::iterator
|
||||
iterator_t BOOST_RANGE_UNUSED;
|
||||
|
||||
test_append(
|
||||
std::remove_copy(c.begin(), c.end(),
|
||||
std::back_inserter(reference), to_remove),
|
||||
to_remove);
|
||||
|
||||
std::vector<value_type> test;
|
||||
test_append(
|
||||
boost::remove_copy(c, std::back_inserter(test), to_remove),
|
||||
to_remove);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
std::vector<value_type> test2;
|
||||
test_append(
|
||||
boost::remove_copy(boost::make_iterator_range(c),
|
||||
std::back_inserter(test2), to_remove),
|
||||
to_remove);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_copy_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_copy_impl(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_copy_impl(cont, 0);
|
||||
test_remove_copy_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_copy_impl(cont, 0);
|
||||
test_remove_copy_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_copy_impl(cont, 1);
|
||||
test_remove_copy_impl(cont, 9);
|
||||
test_remove_copy_impl(cont, 4);
|
||||
}
|
||||
|
||||
void test_remove_copy()
|
||||
{
|
||||
test_remove_copy_impl< std::vector<int> >();
|
||||
test_remove_copy_impl< std::list<int> >();
|
||||
test_remove_copy_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_copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_remove_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// 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_copy_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
|
||||
{
|
||||
template< class Iterator, class Value >
|
||||
void test_append(Iterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_remove_copy_if_impl( const Container& c, UnaryPredicate pred )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<const Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
|
||||
test_append(
|
||||
std::remove_copy_if(c.begin(), c.end(), std::back_inserter(reference), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
std::vector<value_type> test;
|
||||
test_append(
|
||||
boost::remove_copy_if(c, std::back_inserter(test), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
std::vector<value_type> test2;
|
||||
test_append(
|
||||
boost::remove_copy_if(boost::make_iterator_range(c),
|
||||
std::back_inserter(test2), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_copy_if_( const Container& c, int to_remove )
|
||||
{
|
||||
test_remove_copy_if_impl(c, boost::bind(std::equal_to<int>(), _1, to_remove));
|
||||
test_remove_copy_if_impl(c, boost::bind(std::not_equal_to<int>(), _1, to_remove));
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_copy_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_copy_if_(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_copy_if_(cont, 0);
|
||||
test_remove_copy_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_copy_if_(cont, 0);
|
||||
test_remove_copy_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_copy_if_(cont, 1);
|
||||
test_remove_copy_if_(cont, 9);
|
||||
test_remove_copy_if_(cont, 4);
|
||||
}
|
||||
|
||||
inline void test_remove_copy_if()
|
||||
{
|
||||
test_remove_copy_if_impl< std::vector<int> >();
|
||||
test_remove_copy_if_impl< std::list<int> >();
|
||||
test_remove_copy_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_copy_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_remove_copy_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
// 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() );
|
||||
|
||||
Container test2(c);
|
||||
iterator_t test_it2 = boost::remove_if(
|
||||
boost::make_iterator_range(test2), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test2.begin(), test_it2),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -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/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() );
|
||||
|
||||
std::vector<int> target2(cont.begin(), cont.end());
|
||||
boost::replace(boost::make_iterator_range(target2), what,
|
||||
with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target2.begin(), target2.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;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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_copy.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
|
||||
{
|
||||
template<typename Iterator, typename Value>
|
||||
void test_append(Iterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template< class Container, class Value >
|
||||
void test_replace_copy_impl( const Container& c, Value to_replace )
|
||||
{
|
||||
const Value replace_with = to_replace * 2;
|
||||
|
||||
typedef typename boost::range_value<Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_type>::iterator
|
||||
iterator_t BOOST_RANGE_UNUSED;
|
||||
|
||||
test_append(
|
||||
std::replace_copy(c.begin(), c.end(),
|
||||
std::back_inserter(reference), to_replace, replace_with),
|
||||
to_replace);
|
||||
|
||||
std::vector<value_type> test;
|
||||
test_append(
|
||||
boost::replace_copy(c, std::back_inserter(test), to_replace, replace_with),
|
||||
to_replace);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
std::vector<value_type> test2;
|
||||
test_append(
|
||||
boost::replace_copy(boost::make_iterator_range(c),
|
||||
std::back_inserter(test2), to_replace,
|
||||
replace_with),
|
||||
to_replace);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_copy_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_copy_impl(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_copy_impl(cont, 0);
|
||||
test_replace_copy_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_replace_copy_impl(cont, 0);
|
||||
test_replace_copy_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_copy_impl(cont, 1);
|
||||
test_replace_copy_impl(cont, 9);
|
||||
test_replace_copy_impl(cont, 4);
|
||||
}
|
||||
|
||||
void test_replace_copy()
|
||||
{
|
||||
test_replace_copy_impl< std::vector<int> >();
|
||||
test_replace_copy_impl< std::list<int> >();
|
||||
test_replace_copy_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_copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_replace_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// 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_copy_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
|
||||
{
|
||||
template< class Iterator, class Value >
|
||||
void test_append(Iterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_replace_copy_if_impl( const Container& c, UnaryPredicate pred )
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<const Container>::type value_type;
|
||||
const value_type replace_with = value_type();
|
||||
std::vector<value_type> reference;
|
||||
|
||||
test_append(
|
||||
std::replace_copy_if(c.begin(), c.end(), std::back_inserter(reference), pred, replace_with),
|
||||
value_type()
|
||||
);
|
||||
|
||||
std::vector<value_type> test;
|
||||
test_append(
|
||||
boost::replace_copy_if(c, std::back_inserter(test), pred, replace_with),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
std::vector<value_type> test2;
|
||||
test_append(
|
||||
boost::replace_copy_if(boost::make_iterator_range(c),
|
||||
std::back_inserter(test2), pred,
|
||||
replace_with),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_copy_if_( const Container& c, int to_replace )
|
||||
{
|
||||
test_replace_copy_if_impl(c, boost::bind(std::equal_to<int>(), _1, to_replace));
|
||||
test_replace_copy_if_impl(c, boost::bind(std::not_equal_to<int>(), _1, to_replace));
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_copy_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_copy_if_(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_copy_if_(cont, 0);
|
||||
test_replace_copy_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_replace_copy_if_(cont, 0);
|
||||
test_replace_copy_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_copy_if_(cont, 1);
|
||||
test_replace_copy_if_(cont, 9);
|
||||
test_replace_copy_if_(cont, 4);
|
||||
}
|
||||
|
||||
inline void test_replace_copy_if()
|
||||
{
|
||||
test_replace_copy_if_impl< std::vector<int> >();
|
||||
test_replace_copy_if_impl< std::list<int> >();
|
||||
test_replace_copy_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_copy_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_replace_copy_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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() );
|
||||
|
||||
std::vector<int> target2(cont.begin(), cont.end());
|
||||
boost::replace_if(boost::make_iterator_range(target2),
|
||||
boost::bind(pred, _1, what), with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target2.begin(), target2.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;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// 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);
|
||||
Container test2(cont);
|
||||
|
||||
boost::reverse(test);
|
||||
std::reverse(reference.begin(), reference.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
boost::reverse(boost::make_iterator_range(test2));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -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/reverse_copy.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
|
||||
{
|
||||
template<class OutputIterator, class Value>
|
||||
void test_append(OutputIterator out, Value value)
|
||||
{
|
||||
*out++ = value;
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_reverse_copy_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
std::vector<value_type> test;
|
||||
|
||||
test_append(
|
||||
std::reverse_copy(cont.begin(), cont.end(), std::back_inserter(reference)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
test_append(
|
||||
boost::reverse_copy(cont, std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
test.clear();
|
||||
|
||||
test_append(
|
||||
boost::reverse_copy(boost::make_iterator_range(cont),
|
||||
std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_reverse_copy_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_reverse_copy_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_reverse_copy_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_reverse_copy_impl(cont);
|
||||
}
|
||||
|
||||
void test_reverse_copy()
|
||||
{
|
||||
test_reverse_copy_impl< std::vector<int> >();
|
||||
test_reverse_copy_impl< std::list<int> >();
|
||||
test_reverse_copy_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_copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &::test_reverse_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// 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() );
|
||||
|
||||
test = cont;
|
||||
test_where_it = test.begin();
|
||||
std::advance(test_where_it,
|
||||
std::distance(cont.begin(), where_it));
|
||||
|
||||
boost::rotate(boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
// 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_copy.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
|
||||
{
|
||||
template<class OutputIterator, class Value>
|
||||
void test_append(OutputIterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void test_rotate_copy_impl(Container& cont, Iterator where_it)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container>::type
|
||||
value_type;
|
||||
|
||||
std::vector<value_type> reference;
|
||||
std::vector<value_type> test;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
iterator_t BOOST_RANGE_UNUSED;
|
||||
|
||||
test_append(
|
||||
std::rotate_copy(cont.begin(), where_it, cont.end(),
|
||||
std::back_inserter(reference)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
test_append(
|
||||
boost::rotate_copy(cont, where_it, std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
test.clear();
|
||||
|
||||
test_append(
|
||||
boost::rotate_copy(boost::make_iterator_range(cont), where_it,
|
||||
std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_copy_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iterator_t;
|
||||
|
||||
iterator_t last = cont.end();
|
||||
for (iterator_t it = cont.begin(); it != last; ++it)
|
||||
{
|
||||
test_rotate_copy_impl(cont, it);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_copy_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_rotate_copy_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_rotate_copy_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_rotate_copy_impl(cont);
|
||||
}
|
||||
|
||||
void test_rotate_copy()
|
||||
{
|
||||
test_rotate_copy_impl< std::vector<int> >();
|
||||
test_rotate_copy_impl< std::list<int> >();
|
||||
test_rotate_copy_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_copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_rotate_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// 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);
|
||||
BOOST_CHECK( it == boost::search(boost::make_iterator_range(cont1), cont2) );
|
||||
BOOST_CHECK( it == boost::search(cont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( it == boost::search(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2)) );
|
||||
iterator1_t it2 = boost::search(cont1, ccont2);
|
||||
BOOST_CHECK( it2 == boost::search(boost::make_iterator_range(cont1), ccont2) );
|
||||
BOOST_CHECK( it2 == boost::search(cont1, boost::make_iterator_range(ccont2)) );
|
||||
BOOST_CHECK( it2 == boost::search(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(ccont2)) );
|
||||
const_iterator1_t cit = boost::search(ccont1, cont2);
|
||||
BOOST_CHECK( cit == boost::search(boost::make_iterator_range(ccont1), cont2) );
|
||||
BOOST_CHECK( cit == boost::search(ccont1, boost::make_iterator_range(cont2)) );
|
||||
BOOST_CHECK( cit == boost::search(boost::make_iterator_range(ccont1),
|
||||
boost::make_iterator_range(cont2)) );
|
||||
const_iterator1_t cit2 = boost::search(ccont1, ccont2);
|
||||
BOOST_CHECK( cit2 == boost::search(boost::make_iterator_range(ccont1), ccont2) );
|
||||
BOOST_CHECK( cit2 == boost::search(ccont1, boost::make_iterator_range(ccont2)) );
|
||||
BOOST_CHECK( cit2 == boost::search(boost::make_iterator_range(ccont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
// 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_n.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
|
||||
{
|
||||
template<typename ForwardIterator, typename Integer, typename Value>
|
||||
inline ForwardIterator
|
||||
reference_search_n(ForwardIterator first, ForwardIterator last,
|
||||
Integer count, const Value& value)
|
||||
{
|
||||
if (count <= 0)
|
||||
return first;
|
||||
else if (count == 1)
|
||||
return std::find(first, last, value);
|
||||
else
|
||||
{
|
||||
first = std::find(first, last, value);
|
||||
while (first != last)
|
||||
{
|
||||
typename std::iterator_traits<ForwardIterator>::difference_type n = count;
|
||||
ForwardIterator i = first;
|
||||
++i;
|
||||
while (i != last && n != 1 && *i==value)
|
||||
{
|
||||
++i;
|
||||
--n;
|
||||
}
|
||||
if (n == 1)
|
||||
return first;
|
||||
if (i == last)
|
||||
return last;
|
||||
first = std::find(++i, last, value);
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename Integer, typename Value,
|
||||
typename BinaryPredicate>
|
||||
inline ForwardIterator
|
||||
reference_search_n(ForwardIterator first, ForwardIterator last,
|
||||
Integer count, const Value& value,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef typename std::iterator_traits<
|
||||
ForwardIterator
|
||||
>::iterator_category cat_t BOOST_RANGE_UNUSED;
|
||||
|
||||
if (count <= 0)
|
||||
return first;
|
||||
if (count == 1)
|
||||
{
|
||||
while (first != last && !static_cast<bool>(pred(*first, value)))
|
||||
++first;
|
||||
return first;
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_t;
|
||||
|
||||
while (first != last && !static_cast<bool>(pred(*first, value)))
|
||||
++first;
|
||||
|
||||
while (first != last)
|
||||
{
|
||||
difference_t n = count;
|
||||
ForwardIterator i = first;
|
||||
++i;
|
||||
while (i != last && n != 1 && static_cast<bool>(pred(*i, value)))
|
||||
{
|
||||
++i;
|
||||
--n;
|
||||
}
|
||||
if (n == 1)
|
||||
return first;
|
||||
if (i == last)
|
||||
return last;
|
||||
first = ++i;
|
||||
while (first != last && !static_cast<bool>(pred(*first, value)))
|
||||
++first;
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template< class Container1, class Value, class Pred >
|
||||
void test_search_n_pred_impl(Container1& cont1, Value value, Pred pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
|
||||
const Container1& ccont1 = cont1;
|
||||
|
||||
for (std::size_t n = 0; n < cont1.size(); ++n)
|
||||
{
|
||||
iterator1_t it = boost::search_n(cont1, n, value, pred);
|
||||
BOOST_CHECK( it == boost::search_n(boost::make_iterator_range(cont1), n, value, pred) );
|
||||
BOOST_CHECK( it == reference_search_n(cont1.begin(), cont1.end(), n, value, pred) );
|
||||
|
||||
const_iterator1_t cit = boost::search_n(ccont1, n, value, pred);
|
||||
BOOST_CHECK( cit == boost::search_n(boost::make_iterator_range(ccont1), n, value, pred) );
|
||||
BOOST_CHECK( cit == reference_search_n(ccont1.begin(), ccont1.end(), n, value, pred) );
|
||||
}
|
||||
}
|
||||
|
||||
template< class Container1, class Value >
|
||||
void test_search_n_impl(Container1& cont1, Value value)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
|
||||
const Container1& ccont1 = cont1;
|
||||
|
||||
for (std::size_t n = 0; n < cont1.size(); ++n)
|
||||
{
|
||||
iterator1_t it = boost::search_n(cont1, n, value);
|
||||
BOOST_CHECK( it == boost::search_n(boost::make_iterator_range(cont1), n, value) );
|
||||
BOOST_CHECK( it == reference_search_n(cont1.begin(), cont1.end(), n, value) );
|
||||
|
||||
const_iterator1_t cit = boost::search_n(ccont1, n, value);
|
||||
BOOST_CHECK( cit == boost::search_n(boost::make_iterator_range(ccont1), n, value) );
|
||||
BOOST_CHECK( cit == reference_search_n(ccont1.begin(), ccont1.end(), n, value) );
|
||||
}
|
||||
|
||||
test_search_n_pred_impl(cont1, value, std::less<int>());
|
||||
test_search_n_pred_impl(cont1, value, std::greater<int>());
|
||||
test_search_n_pred_impl(cont1, value, std::equal_to<int>());
|
||||
test_search_n_pred_impl(cont1, value, std::not_equal_to<int>());
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_search_n_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
|
||||
test_search_n_impl(cont1, 1);
|
||||
|
||||
cont1 += 1;
|
||||
test_search_n_impl(cont1, 1);
|
||||
test_search_n_impl(cont1, 0);
|
||||
|
||||
cont1.clear();
|
||||
cont1 += 1,1;
|
||||
test_search_n_impl(cont1, 1);
|
||||
test_search_n_impl(cont1, 0);
|
||||
|
||||
cont1 += 1,1,1;
|
||||
test_search_n_impl(cont1, 1);
|
||||
test_search_n_impl(cont1, 0);
|
||||
|
||||
cont1.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
test_search_n_impl(cont1, 1);
|
||||
test_search_n_impl(cont1, 2);
|
||||
test_search_n_impl(cont1, 5);
|
||||
test_search_n_impl(cont1, 9);
|
||||
}
|
||||
|
||||
void test_search_n()
|
||||
{
|
||||
test_search_n_impl< std::list<int>, std::list<int> >();
|
||||
test_search_n_impl< std::vector<int>, std::vector<int> >();
|
||||
test_search_n_impl< std::set<int>, std::set<int> >();
|
||||
test_search_n_impl< std::list<int>, std::vector<int> >();
|
||||
test_search_n_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_n" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_search_n ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
// 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);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_difference(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
// 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);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_intersection(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// 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);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
boost::make_iterator_range(cont1), cont2,
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
cont1, boost::make_iterator_range(cont2),
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_symmetric_difference(
|
||||
boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
// 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);
|
||||
|
||||
test_result = boost::set_union(boost::make_iterator_range(cont1),
|
||||
cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_union(cont1,
|
||||
boost::make_iterator_range(cont2),
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_union(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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);
|
||||
|
||||
test_result = boost::set_union(boost::make_iterator_range(cont1),
|
||||
cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_union(cont1,
|
||||
boost::make_iterator_range(cont2),
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
|
||||
test_result = boost::set_union(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(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;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
// 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() );
|
||||
|
||||
Container test2(cont);
|
||||
boost::sort(boost::make_iterator_range(test2));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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()
|
||||
);
|
||||
|
||||
Container test2(cont);
|
||||
boost::sort(boost::make_iterator_range(test2), pred);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test2.begin(), test2.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;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// 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_range_test_algorithm_stable_partition
|
||||
{
|
||||
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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
Container cont2(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::stable_partition(cont, UnaryPredicate());
|
||||
|
||||
iter_t temp_result = boost::stable_partition(
|
||||
boost::make_iterator_range(cont2), UnaryPredicate());
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
|
||||
std::distance(cont2.begin(), temp_result) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
Container cont2(cont);
|
||||
result_t result = boost::stable_partition<return_type>(cont, policy.pred());
|
||||
|
||||
result_t result2 = boost::stable_partition<return_type>(
|
||||
boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
boost::ignore_unused_variable_warning(result2);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
|
||||
cont.begin(), cont.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
stable_partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_stable_partition()
|
||||
{
|
||||
test_stable_partition_impl< std::vector<int> >();
|
||||
test_stable_partition_impl< std::list<int> >();
|
||||
test_stable_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
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_range_test_algorithm_stable_partition::test_stable_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// 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() );
|
||||
|
||||
test = cont;
|
||||
boost::stable_sort(boost::make_iterator_range(test));
|
||||
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() );
|
||||
|
||||
test = cont;
|
||||
boost::stable_sort(boost::make_iterator_range(test), 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;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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/swap_ranges.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
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test_swap_ranges_impl(const Container1& source1, const Container2& source2)
|
||||
{
|
||||
Container1 reference1(source1);
|
||||
Container2 reference2(source2);
|
||||
std::swap_ranges(reference1.begin(), reference1.end(), reference2.begin());
|
||||
|
||||
Container1 test1(source1);
|
||||
Container2 test2(source2);
|
||||
boost::swap_ranges(test1, test2);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference1.begin(), reference1.end(),
|
||||
test1.begin(), test1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference2.begin(), reference2.end(),
|
||||
test2.begin(), test2.end() );
|
||||
|
||||
test1 = source1;
|
||||
test2 = source2;
|
||||
boost::swap_ranges(boost::make_iterator_range(test1), test2);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference1.begin(), reference1.end(),
|
||||
test1.begin(), test1.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference2.begin(), reference2.end(),
|
||||
test2.begin(), test2.end() );
|
||||
|
||||
test1 = source1;
|
||||
test2 = source2;
|
||||
boost::swap_ranges(test1, boost::make_iterator_range(test2));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference1.begin(), reference1.end(),
|
||||
test1.begin(), test1.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference2.begin(), reference2.end(),
|
||||
test2.begin(), test2.end() );
|
||||
|
||||
test1 = source1;
|
||||
test2 = source2;
|
||||
boost::swap_ranges(boost::make_iterator_range(test1),
|
||||
boost::make_iterator_range(test2));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference1.begin(), reference1.end(),
|
||||
test1.begin(), test1.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference2.begin(), reference2.end(),
|
||||
test2.begin(), test2.end() );
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_swap_ranges_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 c1;
|
||||
Container2 c2;
|
||||
|
||||
test_swap_ranges_impl(c1, c2);
|
||||
|
||||
c1.clear();
|
||||
c1 += 1;
|
||||
c2.clear();
|
||||
c2 += 2;
|
||||
test_swap_ranges_impl(c1, c2);
|
||||
|
||||
c1.clear();
|
||||
c1 += 1,2,3,4,5,6,7,8,9,10;
|
||||
c2.clear();
|
||||
c2 += 10,9,8,7,6,5,4,3,2,1;
|
||||
test_swap_ranges_impl(c1, c2);
|
||||
}
|
||||
|
||||
inline void test_swap_ranges()
|
||||
{
|
||||
test_swap_ranges_impl< std::vector<int>, std::vector<int> >();
|
||||
test_swap_ranges_impl< std::vector<int>, std::list<int> >();
|
||||
test_swap_ranges_impl< std::vector<int>, std::deque<int> >();
|
||||
test_swap_ranges_impl< std::list<int>, std::vector<int> >();
|
||||
test_swap_ranges_impl< std::list<int>, std::list<int> >();
|
||||
test_swap_ranges_impl< std::list<int>, std::deque<int> >();
|
||||
test_swap_ranges_impl< std::deque<int>, std::vector<int> >();
|
||||
test_swap_ranges_impl< std::deque<int>, std::list<int> >();
|
||||
test_swap_ranges_impl< std::deque<int>, 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.swap_ranges" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_swap_ranges ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
// 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);
|
||||
|
||||
boost::ignore_unused_variable_warning(reference_it);
|
||||
|
||||
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() );
|
||||
|
||||
BOOST_CHECK( test_it == boost::transform(boost::make_iterator_range(cont), target.begin(), fn) );
|
||||
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() );
|
||||
BOOST_CHECK( test_it == boost::transform(boost::make_iterator_range(ccont), target.begin(), fn) );
|
||||
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);
|
||||
|
||||
boost::ignore_unused_variable_warning(reference_it);
|
||||
|
||||
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() );
|
||||
|
||||
BOOST_CHECK( test_it == boost::transform(boost::make_iterator_range(cont1), cont2, target.begin(), fn) );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
BOOST_CHECK( test_it == boost::transform(cont1, boost::make_iterator_range(cont2), target.begin(), fn) );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
BOOST_CHECK( test_it == boost::transform(boost::make_iterator_range(cont1),
|
||||
boost::make_iterator_range(cont2),
|
||||
target.begin(), fn) );
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
// 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/range/detail/range_return.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include "../test_driver/range_overload_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost_range_test_algorithm_unique
|
||||
{
|
||||
// test the 'unique' algorithm without a predicate
|
||||
class unique_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont);
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Container>
|
||||
struct test_range_overload
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
::boost::range_return_value,
|
||||
result_type = ::boost::return_begin_found);
|
||||
|
||||
template<typename Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<
|
||||
Container, result_type
|
||||
>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<
|
||||
Container,result_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique(cont);
|
||||
|
||||
boost::unique(boost::make_iterator_range(cont2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< boost::range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique<return_type>(cont, policy.pred());
|
||||
|
||||
boost::unique<return_type>(boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end() );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Container>
|
||||
struct test_range_overload
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
::boost::range_return_value,
|
||||
result_type = ::boost::return_begin_found);
|
||||
|
||||
template<typename Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<
|
||||
Container,result_type>::type result_t;
|
||||
|
||||
Container cont2(cont);
|
||||
|
||||
result_t result = boost::unique(cont, policy.pred());
|
||||
|
||||
boost::unique(boost::make_iterator_range(cont2), policy.pred());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
cont.begin(), cont.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::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;
|
||||
|
||||
boost::range_test::range_overload_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<typename T>
|
||||
struct equal_div_2
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef const T& first_argument_type;
|
||||
typedef const T& second_argument_type;
|
||||
|
||||
bool operator()(const T& left, const T& right) const
|
||||
{
|
||||
return left / 2 == right / 2;
|
||||
}
|
||||
};
|
||||
|
||||
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::equal_to<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::equal_to<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<equal_div_2<int> >(),
|
||||
std::less<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_range_test_algorithm_unique::test_unique ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -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/unique_copy.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
|
||||
{
|
||||
template<class OutputIterator, class Value>
|
||||
void test_append(OutputIterator target, Value value)
|
||||
{
|
||||
*target++ = value;
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_unique_copy_impl(Container& c)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
std::vector<value_type> test;
|
||||
|
||||
test_append(
|
||||
std::unique_copy(c.begin(), c.end(), std::back_inserter(reference)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
test_append(
|
||||
boost::unique_copy(c, std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(reference.begin(), reference.end(),
|
||||
test.begin(), test.end());
|
||||
|
||||
test.clear();
|
||||
|
||||
test_append(
|
||||
boost::unique_copy(boost::make_iterator_range(c),
|
||||
std::back_inserter(test)),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(reference.begin(), reference.end(),
|
||||
test.begin(), test.end());
|
||||
}
|
||||
|
||||
template<class Container, class Pred>
|
||||
void test_unique_copy_impl(Container& c, Pred pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container>::type value_type;
|
||||
std::vector<value_type> reference;
|
||||
std::vector<value_type> test;
|
||||
|
||||
test_append(
|
||||
std::unique_copy(c.begin(), c.end(), std::back_inserter(reference), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
test_append(
|
||||
boost::unique_copy(c, std::back_inserter(test), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(reference.begin(), reference.end(),
|
||||
test.begin(), test.end());
|
||||
|
||||
test.clear();
|
||||
|
||||
test_append(
|
||||
boost::unique_copy(boost::make_iterator_range(c),
|
||||
std::back_inserter(test), pred),
|
||||
value_type()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(reference.begin(), reference.end(),
|
||||
test.begin(), test.end());
|
||||
}
|
||||
|
||||
template<class Container, class Pred>
|
||||
void test_unique_copy_driver(Pred pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_unique_copy_impl(cont);
|
||||
test_unique_copy_impl(cont, pred);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end());
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
test_unique_copy_impl(cont);
|
||||
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
test_unique_copy_impl(cont, pred);
|
||||
|
||||
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());
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
test_unique_copy_impl(cont);
|
||||
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
test_unique_copy_impl(cont, pred);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_unique_copy_impl()
|
||||
{
|
||||
test_unique_copy_driver<Container>(std::less<int>());
|
||||
test_unique_copy_driver<Container>(std::greater<int>());
|
||||
}
|
||||
|
||||
void test_unique_copy()
|
||||
{
|
||||
test_unique_copy_impl< std::vector<int> >();
|
||||
test_unique_copy_impl< std::list<int> >();
|
||||
test_unique_copy_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_copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_unique_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// 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_range_test_algorithm_upper_bound
|
||||
{
|
||||
class upper_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template<boost::range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5);
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(boost::make_iterator_range(cont), 5) );
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct upper_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
|
||||
iter_t result = boost::upper_bound(cont, 5, BinaryPredicate());
|
||||
BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) );
|
||||
return result;
|
||||
}
|
||||
|
||||
template< boost::range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,result_type>::type result_t;
|
||||
|
||||
result_t result = boost::upper_bound<result_type>(cont, 5, policy.pred());
|
||||
|
||||
BOOST_CHECK( result == boost::upper_bound<result_type>(
|
||||
boost::make_iterator_range(cont), 5, policy.pred()) );
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME boost::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 boost::remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
boost::range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_upper_bound_impl()
|
||||
{
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_upper_bound()
|
||||
{
|
||||
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_range_test_algorithm_upper_bound::test_upper_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
Reference in New Issue
Block a user