forked from boostorg/range
Boost.RangeEx merged into Boost.Range
[SVN r60897]
This commit is contained in:
+111
-14
@@ -1,5 +1,6 @@
|
||||
# Boost.Range library
|
||||
#
|
||||
# Copyright Neil Groves 2009
|
||||
# Copyright Thorsten Ottosen 2003-2004. Use, modification and
|
||||
# distribution is subject to the Boost Software License, Version
|
||||
# 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -8,28 +9,124 @@
|
||||
# For more information, see http://www.boost.org/libs/range/
|
||||
#
|
||||
|
||||
# bring in rules for testing
|
||||
import testing ;
|
||||
|
||||
project
|
||||
: requirements
|
||||
<library>/boost/test//boost_unit_test_framework/
|
||||
<library>/boost/regex//boost_regex/
|
||||
<link>static
|
||||
<threading>multi
|
||||
;
|
||||
|
||||
rule range-test ( name : includes * )
|
||||
{
|
||||
return [
|
||||
run $(name).cpp /boost/test//boost_unit_test_framework/<link>static
|
||||
run $(name).cpp /boost/test//boost_unit_test_framework /boost/regex//boost_regex/<link>static
|
||||
:
|
||||
:
|
||||
:
|
||||
: <toolset>gcc:<cxxflags>"-Wall -Wunused "
|
||||
] ;
|
||||
}
|
||||
|
||||
test-suite range :
|
||||
[ range-test array ]
|
||||
[ range-test iterator_pair ]
|
||||
[ range-test std_container ]
|
||||
[ range-test string ]
|
||||
[ range-test iterator_range ]
|
||||
[ range-test sub_range ]
|
||||
[ range-test partial_workaround ]
|
||||
[ range-test algorithm_example ]
|
||||
[ range-test reversible_range ]
|
||||
[ range-test const_ranges ]
|
||||
[ range-test extension_mechanism ]
|
||||
# [ range-test mfc : <include>$(VC71_ROOT)/atlmfc/include ]
|
||||
[ range-test adaptor_test/adjacent_filtered ]
|
||||
[ range-test adaptor_test/copied ]
|
||||
[ range-test adaptor_test/filtered ]
|
||||
[ range-test adaptor_test/indexed ]
|
||||
[ range-test adaptor_test/indirected ]
|
||||
[ range-test adaptor_test/map ]
|
||||
[ range-test adaptor_test/replaced ]
|
||||
[ range-test adaptor_test/replaced_if ]
|
||||
[ range-test adaptor_test/reversed ]
|
||||
[ range-test adaptor_test/sliced ]
|
||||
[ range-test adaptor_test/strided ]
|
||||
[ range-test adaptor_test/tokenized ]
|
||||
[ range-test adaptor_test/transformed ]
|
||||
[ range-test adaptor_test/uniqued ]
|
||||
[ range-test adaptor_test/adjacent_filtered_example ]
|
||||
[ range-test adaptor_test/copied_example ]
|
||||
[ range-test adaptor_test/filtered_example ]
|
||||
[ range-test adaptor_test/indexed_example ]
|
||||
[ range-test adaptor_test/indirected_example ]
|
||||
[ range-test adaptor_test/map_keys_example ]
|
||||
[ range-test adaptor_test/map_values_example ]
|
||||
[ range-test adaptor_test/replaced_example ]
|
||||
[ range-test adaptor_test/replaced_if_example ]
|
||||
[ range-test adaptor_test/reversed_example ]
|
||||
[ range-test adaptor_test/sliced_example ]
|
||||
[ range-test adaptor_test/strided_example ]
|
||||
[ range-test adaptor_test/transformed_example ]
|
||||
[ range-test adaptor_test/uniqued_example ]
|
||||
[ range-test algorithm_test/adjacent_find ]
|
||||
[ range-test algorithm_test/binary_search ]
|
||||
[ range-test algorithm_test/copy ]
|
||||
[ range-test algorithm_test/copy_backward ]
|
||||
[ range-test algorithm_test/count ]
|
||||
[ range-test algorithm_test/count_if ]
|
||||
[ range-test algorithm_test/equal ]
|
||||
[ range-test algorithm_test/equal_range ]
|
||||
[ range-test algorithm_test/fill ]
|
||||
[ range-test algorithm_test/find ]
|
||||
[ range-test algorithm_test/find_if ]
|
||||
[ range-test algorithm_test/find_end ]
|
||||
[ range-test algorithm_test/find_first_of ]
|
||||
[ range-test algorithm_test/for_each ]
|
||||
[ range-test algorithm_test/generate ]
|
||||
[ range-test algorithm_test/heap ]
|
||||
[ range-test algorithm_test/includes ]
|
||||
[ range-test algorithm_test/inplace_merge ]
|
||||
[ range-test algorithm_test/lexicographical_compare ]
|
||||
[ range-test algorithm_test/lower_bound ]
|
||||
[ range-test algorithm_test/max_element ]
|
||||
[ range-test algorithm_test/merge ]
|
||||
[ range-test algorithm_test/min_element ]
|
||||
[ range-test algorithm_test/mismatch ]
|
||||
[ range-test algorithm_test/next_permutation ]
|
||||
[ range-test algorithm_test/nth_element ]
|
||||
[ range-test algorithm_test/partial_sort ]
|
||||
[ range-test algorithm_test/partition ]
|
||||
[ range-test algorithm_test/prev_permutation ]
|
||||
[ range-test algorithm_test/random_shuffle ]
|
||||
[ range-test algorithm_test/remove ]
|
||||
[ range-test algorithm_test/remove_if ]
|
||||
[ range-test algorithm_test/replace ]
|
||||
[ range-test algorithm_test/replace_if ]
|
||||
[ range-test algorithm_test/reverse ]
|
||||
[ range-test algorithm_test/rotate ]
|
||||
[ range-test algorithm_test/search ]
|
||||
[ range-test algorithm_test/set_difference ]
|
||||
[ range-test algorithm_test/set_intersection ]
|
||||
[ range-test algorithm_test/set_symmetric_difference ]
|
||||
[ range-test algorithm_test/set_union ]
|
||||
[ range-test algorithm_test/sort ]
|
||||
[ range-test algorithm_test/stable_partition ]
|
||||
[ range-test algorithm_test/stable_sort ]
|
||||
[ range-test algorithm_test/transform ]
|
||||
[ range-test algorithm_test/unique ]
|
||||
[ range-test algorithm_test/upper_bound ]
|
||||
[ range-test adl_conformance ]
|
||||
[ range-test adl_conformance_no_using ]
|
||||
[ range-test algorithm ]
|
||||
[ range-test algorithm_example ]
|
||||
[ range-test array ]
|
||||
# [ range-test atl : <include>$(VC71_ROOT)/atlmfc/include ]
|
||||
[ range-test combine ]
|
||||
[ range-test compat2 ]
|
||||
[ range-test compat3 ]
|
||||
[ range-test const_ranges ]
|
||||
[ range-test counting_range ]
|
||||
[ range-test extension_mechanism ]
|
||||
[ range-test irange ]
|
||||
[ range-test iterator_pair ]
|
||||
[ range-test iterator_range ]
|
||||
# [ range-test mfc : <include>$(VC71_ROOT)/atlmfc/include ]
|
||||
[ range-test join ]
|
||||
[ range-test partial_workaround ]
|
||||
[ range-test reversible_range ]
|
||||
[ range-test std_container ]
|
||||
[ range-test string ]
|
||||
[ range-test sub_range ]
|
||||
;
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// 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/adaptor/adjacent_filtered.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void adjacent_filtered_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
// This is my preferred syntax using the | operator.
|
||||
std::vector< value_t > test_result1
|
||||
= boost::copy_range< std::vector< value_t > >(
|
||||
c | adjacent_filtered(std::not_equal_to< value_t >()));
|
||||
|
||||
// This is an alternative syntax preferred by some.
|
||||
std::vector< value_t > test_result2
|
||||
= boost::copy_range< std::vector< value_t > >(
|
||||
adaptors::adjacent_filter(c, std::not_equal_to< value_t >()));
|
||||
|
||||
// Calculate the reference result.
|
||||
std::vector< value_t > reference_result;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
|
||||
value_t prev_v = value_t();
|
||||
for (iter_t it = c.begin(); it != c.end(); ++it)
|
||||
{
|
||||
if (it == c.begin())
|
||||
{
|
||||
reference_result.push_back(*it);
|
||||
}
|
||||
else if (*it != prev_v)
|
||||
{
|
||||
reference_result.push_back(*it);
|
||||
}
|
||||
prev_v = *it;
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result1.begin(),
|
||||
test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result2.begin(),
|
||||
test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Collection >
|
||||
void adjacent_filtered_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Collection c;
|
||||
|
||||
// test empty collection
|
||||
adjacent_filtered_test_impl(c);
|
||||
|
||||
// test one element;
|
||||
c += 1;
|
||||
adjacent_filtered_test_impl(c);
|
||||
|
||||
// test many elements;
|
||||
c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
|
||||
adjacent_filtered_test_impl(c);
|
||||
}
|
||||
|
||||
void adjacent_filtered_test()
|
||||
{
|
||||
adjacent_filtered_test_impl< std::vector< int > >();
|
||||
adjacent_filtered_test_impl< std::list< int > >();
|
||||
adjacent_filtered_test_impl< std::set< int > >();
|
||||
adjacent_filtered_test_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.adaptor.adjacent_filtered" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::adjacent_filtered_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/adaptor/adjacent_filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void adjacent_filtered_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | adjacent_filtered(std::not_equal_to<int>()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | adjacent_filtered(std::not_equal_to<int>()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.adjacent_filtered_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &adjacent_filtered_example_test ) );
|
||||
|
||||
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/
|
||||
//
|
||||
#include <boost/range/adaptor/copied.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void copied_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
// This is my preferred syntax using the | operator.
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | copied(0u, c.size()));
|
||||
|
||||
// This is the alternative syntax preferred by some.
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::copy(c, 0u, c.size()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_result1.begin(), test_result1.end(),
|
||||
c.begin(), c.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_result2.begin(), test_result2.end(),
|
||||
c.begin(), c.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void copied_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// test empty collection
|
||||
copied_test_impl(c);
|
||||
|
||||
// test one element
|
||||
c += 1;
|
||||
copied_test_impl(c);
|
||||
|
||||
// test many elements
|
||||
c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
|
||||
copied_test_impl(c);
|
||||
}
|
||||
|
||||
void copied_test()
|
||||
{
|
||||
copied_test_impl< std::vector< int > >();
|
||||
copied_test_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.adaptor.copied" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::copied_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/adaptor/copied.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void copied_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | copied(1, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 2,3,4,5;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | copied(1, 5));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.copied_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &copied_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// 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/adaptor/filtered.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct always_false_pred
|
||||
{
|
||||
template< class T1 >
|
||||
bool operator()(T1) const { return false; }
|
||||
};
|
||||
|
||||
struct always_true_pred
|
||||
{
|
||||
template< class T1 >
|
||||
bool operator()(T1) const { return true; }
|
||||
};
|
||||
|
||||
struct is_even
|
||||
{
|
||||
template< class IntegerT >
|
||||
bool operator()( IntegerT x ) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
struct is_odd
|
||||
{
|
||||
template< class IntegerT >
|
||||
bool operator()( IntegerT x ) const { return x % 2 != 0; }
|
||||
};
|
||||
|
||||
template< class Container, class Pred >
|
||||
void filtered_test_impl( Container& c, Pred pred )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
// This is my preferred syntax using the | operator.
|
||||
std::vector< value_t > test_result1;
|
||||
boost::push_back(test_result1, c | filtered(pred));
|
||||
|
||||
// This is an alternative syntax preferred by some.
|
||||
std::vector< value_t > test_result2;
|
||||
boost::push_back(test_result2, adaptors::filter(c, pred));
|
||||
|
||||
// Calculate the reference result.
|
||||
std::vector< value_t > reference_result;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
|
||||
for (iter_t it = c.begin(); it != c.end(); ++it)
|
||||
{
|
||||
if (pred(*it))
|
||||
reference_result.push_back(*it);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result1.begin(),
|
||||
test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result2.begin(),
|
||||
test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container, class Pred >
|
||||
void filtered_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// test empty container
|
||||
filtered_test_impl(c, Pred());
|
||||
|
||||
// test one element
|
||||
c += 1;
|
||||
filtered_test_impl(c, Pred());
|
||||
|
||||
// test many elements
|
||||
c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
|
||||
filtered_test_impl(c, Pred());
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void filtered_test_all_predicates()
|
||||
{
|
||||
filtered_test_impl< Container, always_false_pred >();
|
||||
filtered_test_impl< Container, always_true_pred >();
|
||||
filtered_test_impl< Container, is_odd >();
|
||||
filtered_test_impl< Container, is_even >();
|
||||
}
|
||||
|
||||
void filtered_test()
|
||||
{
|
||||
filtered_test_all_predicates< std::vector< int > >();
|
||||
filtered_test_all_predicates< std::list< int > >();
|
||||
filtered_test_all_predicates< std::set< int > >();
|
||||
filtered_test_all_predicates< 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.adaptor.filtered" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::filtered_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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/adaptor/filtered.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct is_even
|
||||
{
|
||||
bool operator()( int x ) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
void filtered_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | filtered(is_even()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 2,4,6,8;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | filtered(is_even()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.filtered_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &filtered_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/indexed.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void indexed_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
// This is my preferred syntax using the | operator.
|
||||
std::vector< value_t > test_result1;
|
||||
boost::push_back(test_result1, c | indexed(0));
|
||||
|
||||
// This is an alternative syntax preferred by some.
|
||||
std::vector< value_t > test_result2;
|
||||
boost::push_back(test_result2, adaptors::index(c, 0));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( c.begin(), c.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( c.begin(), c.end(),
|
||||
test_result2.begin(), test_result2.end() );
|
||||
|
||||
boost::indexed_range< Container > test_result3
|
||||
= c | indexed(0);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_const_iterator<
|
||||
boost::indexed_range< Container > >::type iter_t;
|
||||
|
||||
iter_t it = test_result3.begin();
|
||||
for (std::size_t i = 0, count = c.size(); i < count; ++i)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( i, static_cast<std::size_t>(it.index()) );
|
||||
++it;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void indexed_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// test empty container
|
||||
indexed_test_impl(c);
|
||||
|
||||
// test one element
|
||||
c += 1;
|
||||
indexed_test_impl(c);
|
||||
|
||||
// test many elements
|
||||
c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
|
||||
indexed_test_impl(c);
|
||||
}
|
||||
|
||||
void indexed_test()
|
||||
{
|
||||
indexed_test_impl< std::vector< int > >();
|
||||
indexed_test_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.adaptor.indexed" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::indexed_test ) );
|
||||
|
||||
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/adaptor/indexed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
template<class Iterator>
|
||||
void display_element_and_index(Iterator first, Iterator last)
|
||||
{
|
||||
for (Iterator it = first; it != last; ++it)
|
||||
{
|
||||
std::cout << "Element = " << *it << " Index = " << it.index() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template<class SinglePassRange>
|
||||
void display_element_and_index(const SinglePassRange& rng)
|
||||
{
|
||||
display_element_and_index(boost::begin(rng), boost::end(rng));
|
||||
}
|
||||
|
||||
template<class Iterator1, class Iterator2>
|
||||
void check_element_and_index(
|
||||
Iterator1 test_first,
|
||||
Iterator1 test_last,
|
||||
Iterator2 reference_first,
|
||||
Iterator2 reference_last)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( std::distance(test_first, test_last),
|
||||
std::distance(reference_first, reference_last) );
|
||||
|
||||
int reference_index = 0;
|
||||
|
||||
Iterator1 test_it = test_first;
|
||||
Iterator2 reference_it = reference_first;
|
||||
for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( *test_it, *reference_it );
|
||||
BOOST_CHECK_EQUAL( test_it.index(), reference_index );
|
||||
}
|
||||
}
|
||||
|
||||
template<class SinglePassRange1, class SinglePassRange2>
|
||||
void check_element_and_index(
|
||||
const SinglePassRange1& test_rng,
|
||||
const SinglePassRange2& reference_rng)
|
||||
{
|
||||
check_element_and_index(boost::begin(test_rng), boost::end(test_rng),
|
||||
boost::begin(reference_rng), boost::end(reference_rng));
|
||||
}
|
||||
|
||||
void indexed_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 10,20,30,40,50,60,70,80,90;
|
||||
|
||||
display_element_and_index( input | indexed(0) );
|
||||
|
||||
check_element_and_index(
|
||||
input | indexed(0),
|
||||
input);
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indexed_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &indexed_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/indirected.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
template< class Container >
|
||||
void indirected_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
// This is my preferred syntax using the | operator.
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | indirected);
|
||||
|
||||
// This is an alternative syntax preferred by some.
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::indirect(c));
|
||||
|
||||
// Calculate the reference result.
|
||||
std::vector< int > reference_result;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
|
||||
for (iter_t it = c.begin(); it != c.end(); ++it)
|
||||
{
|
||||
reference_result.push_back(**it);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result1.begin(),
|
||||
test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(),
|
||||
reference_result.end(),
|
||||
test_result2.begin(),
|
||||
test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void indirected_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
indirected_test_impl(c);
|
||||
|
||||
c += boost::shared_ptr<int>(new int(1));
|
||||
indirected_test_impl(c);
|
||||
|
||||
std::vector<int> v;
|
||||
v += 1,1,2,2,2,3,4,4,4,4,5,6,7,8,9,9;
|
||||
for (std::vector<int>::const_iterator it = v.begin(); it != v.end(); ++it)
|
||||
{
|
||||
c += boost::shared_ptr<int>(new int(*it));
|
||||
}
|
||||
indirected_test_impl(c);
|
||||
}
|
||||
|
||||
void indirected_test()
|
||||
{
|
||||
indirected_test_impl< std::vector< boost::shared_ptr< int > > >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::indirected_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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/adaptor/indirected.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void indirected_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<boost::shared_ptr<int> > input;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.push_back(boost::shared_ptr<int>(new int(i)));
|
||||
|
||||
boost::copy(
|
||||
input | indirected,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
reference.push_back(i);
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | indirected);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &indirected_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// 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/adaptor/map.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void map_test_keys( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> keys;
|
||||
boost::push_back(keys, c | map_keys);
|
||||
|
||||
std::vector<int> keys2;
|
||||
boost::push_back(keys2, adaptors::keys(c));
|
||||
|
||||
std::vector<int> reference_keys;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
|
||||
for (iter_t it = c.begin(); it != c.end(); ++it)
|
||||
{
|
||||
reference_keys.push_back(it->first);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys.begin(),
|
||||
reference_keys.end(),
|
||||
keys.begin(),
|
||||
keys.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys.begin(),
|
||||
reference_keys.end(),
|
||||
keys2.begin(),
|
||||
keys2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void map_test_values( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> values;
|
||||
boost::push_back(values, c | map_values);
|
||||
|
||||
std::vector<int> values2;
|
||||
boost::push_back(values2, adaptors::values(c));
|
||||
|
||||
std::vector<int> reference_values;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t;
|
||||
for (iter_t it = c.begin(); it != c.end(); ++it)
|
||||
{
|
||||
reference_values.push_back(it->second);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_values.begin(),
|
||||
reference_values.end(),
|
||||
values.begin(),
|
||||
values.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference_values.begin(),
|
||||
reference_values.end(),
|
||||
values2.begin(),
|
||||
values2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void map_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
map_test_keys(c);
|
||||
map_test_values(c);
|
||||
|
||||
// Test one element
|
||||
c.insert(std::make_pair(1,2));
|
||||
map_test_keys(c);
|
||||
map_test_values(c);
|
||||
|
||||
// Test many elements
|
||||
for (int x = 2; x < 10; ++x)
|
||||
{
|
||||
c.insert(std::make_pair(x, x * 2));
|
||||
}
|
||||
map_test_keys(c);
|
||||
map_test_values(c);
|
||||
}
|
||||
|
||||
void map_test()
|
||||
{
|
||||
map_test_impl< std::map<int,int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::map_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void map_keys_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int,int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_keys,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 0,1,2,3,4,5,6,7,8,9;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | map_keys);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map_keys_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &map_keys_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void map_values_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::map<int,int> input;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
input.insert(std::make_pair(i, i * 10));
|
||||
|
||||
boost::copy(
|
||||
input | map_values,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 0,10,20,30,40,50,60,70,80,90;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | map_values);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map_values_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &map_values_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// 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/adaptor/replaced.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void replaced_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
const int value_to_replace = 1;
|
||||
const int replacement_value = 0;
|
||||
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | replaced(value_to_replace, replacement_value));
|
||||
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::replace(c, value_to_replace, replacement_value));
|
||||
|
||||
std::vector< int > reference( c.begin(), c.end() );
|
||||
std::replace(reference.begin(), reference.end(), value_to_replace, replacement_value);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void replaced_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
replaced_test_impl(c);
|
||||
|
||||
// Test one
|
||||
c += 1;
|
||||
replaced_test_impl(c);
|
||||
|
||||
// Test many
|
||||
c += 1,1,1,2,2,2,3,3,3,3,3,4,5,6,6,6,7,8,9;
|
||||
replaced_test_impl(c);
|
||||
}
|
||||
|
||||
void replaced_test()
|
||||
{
|
||||
replaced_test_impl< std::vector< int > >();
|
||||
replaced_test_impl< std::list< int > >();
|
||||
replaced_test_impl< std::set< int > >();
|
||||
replaced_test_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.adaptor.replaced" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::replaced_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/adaptor/replaced.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void replaced_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,2,5,2,7,2,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced(2, 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,10,3,10,5,10,7,10,9;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | replaced(2, 10));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &replaced_example_test ) );
|
||||
|
||||
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/adaptor/replaced_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct if_value_is_one
|
||||
{
|
||||
bool operator()(int x) const { return x == 1; }
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
void replaced_if_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
if_value_is_one pred;
|
||||
|
||||
const int replacement_value = 0;
|
||||
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | replaced_if(pred, replacement_value));
|
||||
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, boost::adaptors::replace_if(c, pred, replacement_value));
|
||||
|
||||
std::vector< int > reference( c.begin(), c.end() );
|
||||
std::replace_if(reference.begin(), reference.end(), pred, replacement_value);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result2.begin(), test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void replaced_if_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
replaced_if_test_impl(c);
|
||||
|
||||
// Test one
|
||||
c += 1;
|
||||
replaced_if_test_impl(c);
|
||||
|
||||
// Test many
|
||||
c += 1,1,1,2,2,2,3,3,3,3,3,4,5,6,6,6,7,8,9;
|
||||
replaced_if_test_impl(c);
|
||||
}
|
||||
|
||||
void replaced_if_test()
|
||||
{
|
||||
replaced_if_test_impl< std::vector< int > >();
|
||||
replaced_if_test_impl< std::list< int > >();
|
||||
replaced_if_test_impl< std::set< int > >();
|
||||
replaced_if_test_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.adaptor.replaced_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::replaced_if_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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/adaptor/replaced_if.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct is_even
|
||||
{
|
||||
bool operator()(int x) const { return x % 2 == 0; }
|
||||
};
|
||||
|
||||
void replaced_if_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | replaced_if(is_even(), 10),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,10,3,10,5,10,7,10,9;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | replaced_if(is_even(), 10));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_if_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &replaced_if_example_test ) );
|
||||
|
||||
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/
|
||||
//
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class Container >
|
||||
void reversed_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | reversed);
|
||||
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::reverse(c));
|
||||
|
||||
std::vector< int > reference( c.rbegin(), c.rend() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result2.begin(), test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void reversed_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
reversed_test_impl(c);
|
||||
|
||||
// Test one
|
||||
c += 1;
|
||||
reversed_test_impl(c);
|
||||
|
||||
// Test many
|
||||
c += 1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,5,6,7,8,9;
|
||||
reversed_test_impl(c);
|
||||
}
|
||||
|
||||
void reversed_test()
|
||||
{
|
||||
reversed_test_impl< std::vector< int > >();
|
||||
reversed_test_impl< std::list< int > >();
|
||||
reversed_test_impl< std::set< int > >();
|
||||
reversed_test_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.adaptor.reversed" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::reversed_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 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/adaptor/reversed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void reversed_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | reversed,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | reversed);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( input.rbegin(), input.rend(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.reversed_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &reversed_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/sliced.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void sliced_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector< value_t > test_result1;
|
||||
boost::push_back(test_result1, c | sliced(0u,c.size()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_result1.begin(), test_result1.end(),
|
||||
c.begin(), c.end() );
|
||||
|
||||
std::vector< value_t > test_alt_result1;
|
||||
boost::push_back(test_alt_result1, adaptors::slice(c, 0u, c.size()));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_alt_result1.begin(), test_alt_result1.end(),
|
||||
c.begin(), c.end() );
|
||||
|
||||
BOOST_CHECK( boost::empty(c | sliced(0u, 0u)) );
|
||||
|
||||
const std::size_t half_count = c.size() / 2u;
|
||||
if (half_count > 0u)
|
||||
{
|
||||
std::vector< value_t > test_result2;
|
||||
boost::push_back(test_result2, c | sliced(0u, half_count));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_result2.begin(), test_result2.end(),
|
||||
c.begin(), c.begin() + half_count );
|
||||
|
||||
std::vector< value_t > test_alt_result2;
|
||||
boost::push_back(test_alt_result2, adaptors::slice(c, 0u, half_count));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test_alt_result2.begin(), test_alt_result2.end(),
|
||||
c.begin(), c.begin() + half_count );
|
||||
}
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void sliced_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
sliced_test_impl(c);
|
||||
|
||||
// Test one element
|
||||
c += 1;
|
||||
sliced_test_impl(c);
|
||||
|
||||
// Test many elements
|
||||
c += 1,1,1,2,2,3,4,5,6,6,6,7,8,9;
|
||||
sliced_test_impl(c);
|
||||
}
|
||||
|
||||
void sliced_test()
|
||||
{
|
||||
sliced_test_impl< std::vector< int > >();
|
||||
sliced_test_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.adaptor.sliced" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::sliced_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/adaptor/sliced.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void sliced_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
boost::copy(
|
||||
input | sliced(2, 5),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 3,4,5;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | sliced(2, 5));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.sliced_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &sliced_example_test ) );
|
||||
|
||||
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/adaptor/strided.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const int STRIDE_SIZE = 2;
|
||||
|
||||
template< class Container >
|
||||
void strided_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
BOOST_ASSERT( c.size() % STRIDE_SIZE == 0 );
|
||||
|
||||
Container reference;
|
||||
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iterator_t;
|
||||
iterator_t it = c.begin();
|
||||
for (iterator_t last = c.end();
|
||||
it != last; it += STRIDE_SIZE)
|
||||
{
|
||||
reference.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
Container test;
|
||||
boost::push_back( test, c | strided(2) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
|
||||
Container test2;
|
||||
boost::push_back( test2, adaptors::stride(c, 2) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test2.begin(), test2.end(),
|
||||
reference.begin(), reference.end() );
|
||||
|
||||
// Test the const versions:
|
||||
const Container& cc = c;
|
||||
Container test3;
|
||||
boost::push_back( test3, cc | strided(2) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test3.begin(), test3.end(),
|
||||
reference.begin(), reference.end() );
|
||||
|
||||
Container test4;
|
||||
boost::push_back( test4, adaptors::stride(cc, 2) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test4.begin(), test4.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void strided_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
strided_test_impl(c);
|
||||
|
||||
// Test two elements
|
||||
c += 1,2;
|
||||
strided_test_impl(c);
|
||||
|
||||
// Test many elements
|
||||
c += 1,1,1,2,2,3,4,5,6,6,6,7,8,9;
|
||||
strided_test_impl(c);
|
||||
}
|
||||
|
||||
void strided_test()
|
||||
{
|
||||
strided_test_impl< std::vector< int > >();
|
||||
strided_test_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.adaptor.strided" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::strided_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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/adaptor/strided.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void strided_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | strided(2),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,3,5,7,9;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | strided(2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.strided_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &strided_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/tokenized.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Iterator, class Container >
|
||||
void tokenized_test_impl( Container& c, std::size_t expected_result )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector< boost::sub_match< Iterator > > test_result1;
|
||||
boost::push_back(test_result1, c | tokenized(boost::regex("\\b")));
|
||||
|
||||
BOOST_CHECK_EQUAL( test_result1.size(), expected_result );
|
||||
|
||||
// std::vector< boost::sub_match< Iterator > > test_result2;
|
||||
// boost::push_back(test_result2, adaptors::tokenize(c, boost::regex("\\b")));
|
||||
|
||||
// BOOST_CHECK_EQUAL( test_result2.size(), expected_result );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void tokenized_test_impl()
|
||||
{
|
||||
Container1 c;
|
||||
Container2& r = c;
|
||||
|
||||
typedef typename boost::range_iterator<Container2>::type It;
|
||||
|
||||
// Test empty
|
||||
tokenized_test_impl<It, Container2>(r, 0u);
|
||||
|
||||
// Test one element
|
||||
c = "a";
|
||||
tokenized_test_impl<It, Container2>(r, 2u);
|
||||
|
||||
// Test many elements
|
||||
c = "a b c d e f g hijlmnopqrstuvwxyz";
|
||||
tokenized_test_impl<It, Container2>(r, 16u);
|
||||
}
|
||||
|
||||
void tokenized_test()
|
||||
{
|
||||
// tokenized_test_impl<std::string, const std::string>();
|
||||
tokenized_test_impl<std::string, std::string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::tokenized_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// 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/adaptor/transformed.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct double_x
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int x) const { return x * 2; }
|
||||
};
|
||||
|
||||
struct halve_x
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int x) const { return x / 2; }
|
||||
};
|
||||
|
||||
template< class Container, class TransformFn >
|
||||
void transformed_test_impl_core( Container& c, TransformFn fn )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | transformed(fn));
|
||||
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::transform(c, fn));
|
||||
|
||||
std::vector< int > reference;
|
||||
std::transform(c.begin(), c.end(), std::back_inserter(reference), fn);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result2.begin(), test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container, class TransformFn >
|
||||
void transformed_test_fn_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
TransformFn fn;
|
||||
|
||||
// Test empty
|
||||
transformed_test_impl_core(c, fn);
|
||||
|
||||
// Test one element
|
||||
c += 1;
|
||||
transformed_test_impl_core(c, fn);
|
||||
|
||||
// Test many elements
|
||||
c += 1,1,1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
transformed_test_impl_core(c, fn);
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void transformed_test_impl()
|
||||
{
|
||||
transformed_test_fn_impl< Container, double_x >();
|
||||
transformed_test_fn_impl< Container, halve_x >();
|
||||
}
|
||||
|
||||
void transformed_test()
|
||||
{
|
||||
transformed_test_impl< std::vector< int > >();
|
||||
transformed_test_impl< std::list< int > >();
|
||||
transformed_test_impl< std::set< int > >();
|
||||
transformed_test_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.adaptor.transformed" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::transformed_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct double_int
|
||||
{
|
||||
typedef int result_type;
|
||||
int operator()(int x) const { return x * 2; }
|
||||
};
|
||||
|
||||
void transformed_example_test()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,2,3,4,5,6,7,8,9,10;
|
||||
|
||||
boost::copy(
|
||||
input | transformed(double_int()),
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 2,4,6,8,10,12,14,16,18,20;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back(test, input | transformed(double_int()));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.transformed_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &transformed_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/adaptor/uniqued.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void uniqued_test_impl( Container& c )
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector< int > test_result1;
|
||||
boost::push_back(test_result1, c | uniqued);
|
||||
|
||||
std::vector< int > test_result2;
|
||||
boost::push_back(test_result2, adaptors::unique(c));
|
||||
|
||||
std::vector< int > reference(c.begin(), c.end());
|
||||
reference.erase(
|
||||
std::unique(reference.begin(), reference.end()),
|
||||
reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result1.begin(), test_result1.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result2.begin(), test_result2.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void uniqued_test_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container c;
|
||||
|
||||
// Test empty
|
||||
uniqued_test_impl(c);
|
||||
|
||||
// Test one
|
||||
c += 1;
|
||||
uniqued_test_impl(c);
|
||||
|
||||
// Test many
|
||||
c += 1,1,1,2,2,2,2,2,3,3,3,3,4,5,6,6,6,7,7,7,8,8,9,9,9,9,9,10;
|
||||
uniqued_test_impl(c);
|
||||
}
|
||||
|
||||
void uniqued_test()
|
||||
{
|
||||
uniqued_test_impl< std::vector< int > >();
|
||||
uniqued_test_impl< std::list< int > >();
|
||||
uniqued_test_impl< std::set< int > >();
|
||||
uniqued_test_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.adaptor.uniqued" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::uniqued_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// 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/adaptor/uniqued.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/range/algorithm_ext/push_back.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
void uniqued_example_test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::adaptors;
|
||||
|
||||
std::vector<int> input;
|
||||
input += 1,1,2,2,2,3,4,5,6;
|
||||
|
||||
boost::copy(
|
||||
input | uniqued,
|
||||
std::ostream_iterator<int>(std::cout, ","));
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6;
|
||||
|
||||
std::vector<int> test;
|
||||
boost::push_back( test, input | uniqued );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.adaptor.uniqued_example" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &uniqued_example_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2006. 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/adaptors.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
template< class T >
|
||||
struct less_than
|
||||
{
|
||||
T val;
|
||||
|
||||
less_than() : val(0)
|
||||
{}
|
||||
|
||||
less_than( T t ) : val(t)
|
||||
{}
|
||||
|
||||
bool operator()( const T& r ) const
|
||||
{
|
||||
return r < val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template< class T >
|
||||
struct multiply
|
||||
{
|
||||
T val;
|
||||
|
||||
typedef T& result_type;
|
||||
|
||||
multiply( T t ) : val(t)
|
||||
{ }
|
||||
|
||||
T& operator()( T& r ) const
|
||||
{
|
||||
return r *= 2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template< class Rng >
|
||||
void check_copy( Rng r )
|
||||
{
|
||||
//
|
||||
// Make sure the generated iterators
|
||||
// can actually be copied
|
||||
//
|
||||
Rng r2 = r;
|
||||
r2 = r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< class Rng >
|
||||
void check()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
Rng rng = boost::assign::list_of(1)(2)(3)(4)(5).to_container( rng );
|
||||
Rng out;
|
||||
|
||||
//
|
||||
// test each alphabetically
|
||||
//
|
||||
BOOST_FOREACH( int i, rng | filtered( less_than<int>(4) )
|
||||
/*| reversed*/
|
||||
| transformed( multiply<int>(2) ) )
|
||||
{
|
||||
out.push_back( i );
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( out.size(), 3u );
|
||||
BOOST_CHECK_EQUAL( *out.begin(), 2 );
|
||||
BOOST_CHECK_EQUAL( *boost::next(out.begin()), 4 );
|
||||
BOOST_CHECK_EQUAL( *boost::next(out.begin(),2), 6 );
|
||||
|
||||
rng = boost::assign::list_of(1)(1)(2)(2)(3)(3)(4)(5).to_container( rng );
|
||||
out.clear();
|
||||
/*
|
||||
BOOST_FOREACH( int i, rng | adjacent_filtered( std::equal_to<int>() )
|
||||
| uniqued )
|
||||
{
|
||||
|
||||
out.push_back( i );
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< class IndirectRng >
|
||||
void check_indirect()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
IndirectRng rng;
|
||||
|
||||
std::vector< boost::shared_ptr< int > > holder;
|
||||
|
||||
for( unsigned i = 0u; i != 20u; ++i )
|
||||
{
|
||||
boost::shared_ptr<int> v(new int(i));
|
||||
rng.push_back( v.get() );
|
||||
}
|
||||
|
||||
BOOST_FOREACH( int& i, rng | indirected | reversed
|
||||
| transformed( multiply<int>(2) ) )
|
||||
{
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< class RandomAccessRng >
|
||||
void check_random_access()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
RandomAccessRng rng(1, 20u);
|
||||
RandomAccessRng out;
|
||||
|
||||
BOOST_FOREACH( int i, rng | reversed
|
||||
| transformed( multiply<int>(2) )
|
||||
/* | sliced(0,15) */ )
|
||||
{
|
||||
out.push_back( i );
|
||||
}
|
||||
|
||||
|
||||
BOOST_FOREACH( int i, rng | copied(3u,13u) )
|
||||
{
|
||||
out.push_back( i );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< class Map >
|
||||
void check_map()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
|
||||
Map m;
|
||||
m.insert( std::make_pair(1,2) );
|
||||
m.insert( std::make_pair(2,2) );
|
||||
m.insert( std::make_pair(3,2) );
|
||||
m.insert( std::make_pair(4,2) );
|
||||
m.insert( std::make_pair(5,2) );
|
||||
m.insert( std::make_pair(6,2) );
|
||||
m.insert( std::make_pair(7,2) );
|
||||
|
||||
std::vector<int> keys
|
||||
= boost::copy_range< std::vector<int> >( m | map_keys );
|
||||
std::vector<int> values
|
||||
= boost::copy_range< std::vector<int> >( m | map_values );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void check_regex()
|
||||
{
|
||||
using namespace boost::adaptors;
|
||||
std::string s("This is a string of tokens");
|
||||
std::vector<std::string> tokens =
|
||||
boost::copy_range< std::vector<std::string> >( s | tokenized( "\\s+", -1 ) );
|
||||
}
|
||||
|
||||
|
||||
void check_adaptors()
|
||||
{
|
||||
check< std::vector<int> >();
|
||||
check< std::list<int> >();
|
||||
check_indirect< std::vector<int*> >();
|
||||
check_indirect< std::list<int*> >();
|
||||
|
||||
check_map< std::map<int,int> >();
|
||||
// check_random_access< std::vector<int> >();
|
||||
check_regex();
|
||||
|
||||
using namespace boost::adaptors;
|
||||
std::vector<int> vec(10u,20);
|
||||
std::vector<int*> pvec;
|
||||
std::map<int,int> map;
|
||||
|
||||
check_copy( vec | adjacent_filtered( std::equal_to<int>() ) );
|
||||
// check_copy( vec | indexed );
|
||||
check_copy( vec | reversed );
|
||||
check_copy( vec | uniqued );
|
||||
check_copy( pvec | indirected );
|
||||
|
||||
// check_copy( vec | sliced(1,5) );
|
||||
//
|
||||
// This does not return an iterator_range<>, so
|
||||
// won't pass this test of implicit conversion
|
||||
// check_copy( vec | copied(1,5) );
|
||||
//
|
||||
check_copy( map | map_values );
|
||||
check_copy( map | map_keys );
|
||||
check_copy( std::string( "a string" ) | tokenized( "\\s+", -1 ) );
|
||||
check_copy( vec | filtered( less_than<int>(2) ) );
|
||||
check_copy( vec | transformed( multiply<int>(2) ) );
|
||||
}
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - Adaptors" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &check_adaptors ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+35
-32
@@ -27,38 +27,41 @@ enum adl_types
|
||||
global_namespace
|
||||
};
|
||||
|
||||
namespace boost
|
||||
// Use boost_test rather than boost as the namespace for this test
|
||||
// to allow the test framework to use boost::begin() etc. without
|
||||
// violating the One Defintion Rule.
|
||||
namespace boost_test
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( Range& r )
|
||||
{
|
||||
return boost_namespace;
|
||||
return boost_namespace;
|
||||
}
|
||||
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( const Range& r )
|
||||
{
|
||||
return boost_namespace;
|
||||
return boost_namespace;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( Range& r )
|
||||
{
|
||||
using range_detail::begin; // create ADL hook
|
||||
return begin( r );
|
||||
}
|
||||
|
||||
|
||||
template< class Range >
|
||||
inline typename Range::iterator begin( const Range& r )
|
||||
{
|
||||
using range_detail::begin; // create ADL hook
|
||||
return begin( r );
|
||||
}
|
||||
}
|
||||
} // 'boost_test'
|
||||
|
||||
|
||||
namespace find_templated
|
||||
@@ -74,7 +77,7 @@ namespace find_templated
|
||||
iterator end() { return unused; }
|
||||
iterator end() const { return unused; }
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// A fully generic version here will create
|
||||
// ambiguity.
|
||||
@@ -84,7 +87,7 @@ namespace find_templated
|
||||
{
|
||||
return templated_namespace;
|
||||
}
|
||||
|
||||
|
||||
template< class T >
|
||||
inline typename range<T>::iterator begin( const range<T>& r )
|
||||
{
|
||||
@@ -98,20 +101,20 @@ namespace find_non_templated
|
||||
struct range
|
||||
{
|
||||
typedef adl_types iterator;
|
||||
|
||||
|
||||
range() { /* allow const objects */ }
|
||||
iterator begin() { return unused; }
|
||||
iterator begin() const { return unused; }
|
||||
iterator end() { return unused; }
|
||||
iterator end() const { return unused; }
|
||||
};
|
||||
|
||||
|
||||
inline range::iterator begin( range& r )
|
||||
{
|
||||
return non_templated_namespace;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline range::iterator begin( const range& r )
|
||||
{
|
||||
return non_templated_namespace;
|
||||
@@ -132,12 +135,12 @@ struct range
|
||||
inline range::iterator begin( range& r )
|
||||
{
|
||||
return global_namespace;
|
||||
}
|
||||
}
|
||||
|
||||
inline range::iterator begin( const range& r )
|
||||
{
|
||||
return global_namespace;
|
||||
}
|
||||
}
|
||||
|
||||
void check_adl_conformance()
|
||||
{
|
||||
@@ -147,29 +150,29 @@ void check_adl_conformance()
|
||||
const find_non_templated::range r4;
|
||||
range r5;
|
||||
const range r6;
|
||||
|
||||
|
||||
//
|
||||
// Notice how ADL kicks in even when we have qualified
|
||||
// Notice how ADL kicks in even when we have qualified
|
||||
// notation!
|
||||
//
|
||||
|
||||
|
||||
BOOST_CHECK( boost::begin( r ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r2 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r3 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r4 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r5 ) != boost_namespace );
|
||||
BOOST_CHECK( boost::begin( r6 ) != boost_namespace );
|
||||
|
||||
BOOST_CHECK_EQUAL( boost::begin( r ), templated_namespace ) ;
|
||||
BOOST_CHECK_EQUAL( boost::begin( r2 ), templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r3 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r4 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r5 ), global_namespace );
|
||||
BOOST_CHECK_EQUAL( boost::begin( r6 ), global_namespace );
|
||||
|
||||
BOOST_CHECK( boost_test::begin( r ) != boost_namespace );
|
||||
BOOST_CHECK( boost_test::begin( r2 ) != boost_namespace );
|
||||
BOOST_CHECK( boost_test::begin( r3 ) != boost_namespace );
|
||||
BOOST_CHECK( boost_test::begin( r4 ) != boost_namespace );
|
||||
BOOST_CHECK( boost_test::begin( r5 ) != boost_namespace );
|
||||
BOOST_CHECK( boost_test::begin( r6 ) != boost_namespace );
|
||||
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r ), templated_namespace ) ;
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r2 ), templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r3 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r4 ), non_templated_namespace );
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r5 ), global_namespace );
|
||||
BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace );
|
||||
}
|
||||
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
#include <boost/test/included/unit_test_framework.hpp>
|
||||
|
||||
using boost::unit_test_framework::test_suite;
|
||||
|
||||
|
||||
@@ -0,0 +1,471 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2006. 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/
|
||||
//
|
||||
// (C) Copyright Eric Niebler 2004.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
/*
|
||||
Revision history:
|
||||
13 December 2004 : Initial version.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// The 'secure' library warnings produce so much noise that it makes it
|
||||
// impossible to see more useful warnings.
|
||||
#define _SCL_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// counting_iterator generates a warning about truncating an integer
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
#include <boost/iterator/counting_iterator.hpp>
|
||||
#ifdef _MSC_VER
|
||||
template ::boost::counting_iterator<int>;
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/numeric.hpp>
|
||||
#include <boost/range/algorithm.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <boost/range/size_type.hpp>
|
||||
#include <boost/range/size.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <iterator>
|
||||
#include <functional>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// dummy function object, used with algorithms
|
||||
//
|
||||
struct null_fun
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T const &t) const
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// dummy predicate, used with algorithms
|
||||
//
|
||||
struct null_pred
|
||||
{
|
||||
template<typename T>
|
||||
bool operator()(T const &t) const
|
||||
{
|
||||
return t == T();
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// dummy unary op, used with algorithms
|
||||
//
|
||||
struct null_op1
|
||||
{
|
||||
template<typename T>
|
||||
T const & operator()(T const & t) const
|
||||
{
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// dummy binary op, used with algorithms
|
||||
//
|
||||
struct null_op2
|
||||
{
|
||||
template<typename T,typename U>
|
||||
T const & operator()(T const & t, U const & u) const
|
||||
{
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Rng>
|
||||
void test_random_algorithms(Rng & rng, std::random_access_iterator_tag)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Rng>::type iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Rng>::type value_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_size<Rng>::type size_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::iterator_category<iterator>::type iterator_category;
|
||||
|
||||
// just make sure these compile (for now)
|
||||
if(0)
|
||||
{
|
||||
boost::random_shuffle(rng);
|
||||
|
||||
// Must be a value since random_shuffle must take the generator by
|
||||
// reference to match the standard.
|
||||
null_op1 rng_generator;
|
||||
boost::random_shuffle(rng, rng_generator);
|
||||
|
||||
boost::sort(rng);
|
||||
boost::sort(rng, std::less<value_type>());
|
||||
|
||||
boost::stable_sort(rng);
|
||||
boost::stable_sort(rng, std::less<value_type>());
|
||||
|
||||
boost::partial_sort(rng, boost::begin(rng));
|
||||
boost::partial_sort(rng, boost::begin(rng), std::less<value_type>());
|
||||
|
||||
boost::nth_element(rng, boost::begin(rng));
|
||||
boost::nth_element(rng, boost::begin(rng), std::less<value_type>());
|
||||
|
||||
boost::push_heap(rng);
|
||||
boost::push_heap(rng, std::less<value_type>());
|
||||
|
||||
boost::pop_heap(rng);
|
||||
boost::pop_heap(rng, std::less<value_type>());
|
||||
|
||||
boost::make_heap(rng);
|
||||
boost::make_heap(rng, std::less<value_type>());
|
||||
|
||||
boost::sort_heap(rng);
|
||||
boost::sort_heap(rng, std::less<value_type>());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Rng>
|
||||
void test_random_algorithms(Rng & rng, std::input_iterator_tag)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
template<typename Rng>
|
||||
void test_algorithms(Rng & rng)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Rng>::type iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Rng>::type value_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_size<Rng>::type size_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::iterator_category<iterator>::type iterator_category;
|
||||
|
||||
// just make sure these compile (for now)
|
||||
if(0)
|
||||
{
|
||||
value_type val = value_type();
|
||||
|
||||
value_type rng2[] = {value_type(),value_type(),value_type()};
|
||||
typedef value_type* iterator2;
|
||||
|
||||
value_type out[100] = {};
|
||||
typedef value_type* out_iterator;
|
||||
|
||||
null_fun f = null_fun();
|
||||
iterator i = iterator();
|
||||
bool b = bool();
|
||||
out_iterator o = out_iterator();
|
||||
size_type s = size_type();
|
||||
|
||||
f = boost::for_each(rng, null_fun());
|
||||
|
||||
i = boost::find(rng, val);
|
||||
i = boost::find_if(rng, null_pred());
|
||||
|
||||
i = boost::find_end(rng, rng2);
|
||||
i = boost::find_end(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
i = boost::find_first_of(rng, rng2);
|
||||
i = boost::find_first_of(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
i = boost::adjacent_find(rng);
|
||||
i = boost::adjacent_find(rng, std::equal_to<value_type>());
|
||||
|
||||
s = boost::count(rng, val);
|
||||
s = boost::count_if(rng, null_pred());
|
||||
|
||||
std::pair<iterator,iterator2> p1;
|
||||
p1 = boost::mismatch(rng, rng2);
|
||||
p1 = boost::mismatch(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
b = boost::equal(rng, rng2);
|
||||
b = boost::equal(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
i = boost::search(rng, rng2);
|
||||
i = boost::search(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
o = boost::copy(rng, boost::begin(out));
|
||||
o = boost::copy_backward(rng, boost::end(out));
|
||||
|
||||
o = boost::transform(rng, boost::begin(out), null_op1());
|
||||
o = boost::transform(rng, rng2, boost::begin(out), null_op2());
|
||||
|
||||
boost::replace(rng, val, val);
|
||||
boost::replace_if(rng, null_pred(), val);
|
||||
|
||||
/*
|
||||
o = boost::replace_copy(rng, boost::begin(out), val, val);
|
||||
o = boost::replace_copy_if(rng, boost::begin(out), null_pred(), val);
|
||||
*/
|
||||
|
||||
boost::fill(rng, val);
|
||||
//
|
||||
// size requires RandomAccess
|
||||
//
|
||||
//boost::fill_n(rng, boost::size(rng), val);
|
||||
//boost::fill_n(rng, std::distance(boost::begin(rng),boost::end(rng)),val);
|
||||
|
||||
boost::generate(rng, &std::rand);
|
||||
//
|
||||
// size requires RandomAccess
|
||||
//
|
||||
//boost::generate_n(rng, boost::size(rng), &std::rand);
|
||||
//boost::generate_n(rng,std::distance(boost::begin(rng),boost::end(rng)), &std::rand);
|
||||
|
||||
i = boost::remove(rng, val);
|
||||
i = boost::remove_if(rng, null_pred());
|
||||
|
||||
/*
|
||||
o = boost::remove_copy(rng, boost::begin(out), val);
|
||||
o = boost::remove_copy_if(rng, boost::begin(out), null_pred());
|
||||
*/
|
||||
|
||||
typename boost::range_return<Rng, boost::return_begin_found>::type rrng = boost::unique(rng);
|
||||
rrng = boost::unique(rng, std::equal_to<value_type>());
|
||||
|
||||
/*
|
||||
o = boost::unique_copy(rng, boost::begin(out));
|
||||
o = boost::unique_copy(rng, boost::begin(out), std::equal_to<value_type>());
|
||||
*/
|
||||
|
||||
boost::reverse(rng);
|
||||
|
||||
/*
|
||||
o = boost::reverse_copy(rng, boost::begin(out));
|
||||
*/
|
||||
|
||||
boost::rotate(rng, boost::begin(rng));
|
||||
|
||||
/*
|
||||
o = boost::rotate_copy(rng, boost::begin(rng), boost::begin(out));
|
||||
*/
|
||||
|
||||
i = boost::partition(rng, null_pred());
|
||||
i = boost::stable_partition(rng, null_pred());
|
||||
|
||||
/*
|
||||
o = boost::partial_sort_copy(rng, out);
|
||||
o = boost::partial_sort_copy(rng, out, std::less<value_type>());
|
||||
*/
|
||||
|
||||
i = boost::lower_bound(rng, val);
|
||||
i = boost::lower_bound(rng, val, std::less<value_type>());
|
||||
|
||||
i = boost::upper_bound(rng, val);
|
||||
i = boost::upper_bound(rng, val, std::less<value_type>());
|
||||
|
||||
std::pair<iterator,iterator> p2;
|
||||
p2 = boost::equal_range(rng, val);
|
||||
p2 = boost::equal_range(rng, val, std::less<value_type>());
|
||||
|
||||
b = boost::binary_search(rng, val);
|
||||
b = boost::binary_search(rng, val, std::less<value_type>());
|
||||
|
||||
boost::inplace_merge(rng, boost::begin(rng));
|
||||
boost::inplace_merge(rng, boost::begin(rng), std::less<value_type>());
|
||||
|
||||
b = boost::includes(rng, rng2);
|
||||
b = boost::includes(rng, rng2, std::equal_to<value_type>());
|
||||
|
||||
o = boost::set_union(rng, rng2, boost::begin(out));
|
||||
o = boost::set_union(rng, rng2, boost::begin(out), std::equal_to<value_type>());
|
||||
|
||||
o = boost::set_intersection(rng, rng2, boost::begin(out));
|
||||
o = boost::set_intersection(rng, rng2, boost::begin(out), std::equal_to<value_type>());
|
||||
|
||||
o = boost::set_difference(rng, rng2, boost::begin(out));
|
||||
o = boost::set_difference(rng, rng2, boost::begin(out), std::equal_to<value_type>());
|
||||
|
||||
o = boost::set_symmetric_difference(rng, rng2, boost::begin(out));
|
||||
o = boost::set_symmetric_difference(rng, rng2, boost::begin(out), std::equal_to<value_type>());
|
||||
|
||||
i = boost::min_element(rng);
|
||||
i = boost::min_element(rng, std::less<value_type>());
|
||||
|
||||
i = boost::max_element(rng);
|
||||
i = boost::max_element(rng, std::less<value_type>());
|
||||
|
||||
b = boost::lexicographical_compare(rng, rng);
|
||||
b = boost::lexicographical_compare(rng, rng, std::equal_to<value_type>());
|
||||
|
||||
b = boost::next_permutation(rng);
|
||||
b = boost::next_permutation(rng, std::less<value_type>());
|
||||
|
||||
b = boost::prev_permutation(rng);
|
||||
b = boost::prev_permutation(rng, std::less<value_type>());
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// numeric algorithms
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
val = boost::accumulate( rng, val );
|
||||
val = boost::accumulate( rng, val, null_op2() );
|
||||
val = boost::inner_product( rng, rng, val );
|
||||
val = boost::inner_product( rng, rng, val,
|
||||
null_op2(), null_op2() );
|
||||
o = boost::partial_sum( rng, boost::begin(out) );
|
||||
o = boost::partial_sum( rng, boost::begin(out), null_op2() );
|
||||
o = boost::adjacent_difference( rng, boost::begin(out) );
|
||||
o = boost::adjacent_difference( rng, boost::begin(out),
|
||||
null_op2() );
|
||||
|
||||
}
|
||||
|
||||
// test the algorithms that require a random-access range
|
||||
test_random_algorithms(rng, iterator_category());
|
||||
}
|
||||
|
||||
int* addr(int &i) { return &i; }
|
||||
bool true_(int) { return true; }
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// test_main
|
||||
//
|
||||
void simple_compile_test()
|
||||
{
|
||||
// int_iterator
|
||||
typedef ::boost::counting_iterator<int> int_iterator;
|
||||
|
||||
// define come containers
|
||||
std::list<int> my_list(int_iterator(1),int_iterator(6));
|
||||
|
||||
|
||||
std::vector<int> my_vector(int_iterator(1),int_iterator(6));
|
||||
|
||||
std::pair<std::vector<int>::iterator,std::vector<int>::iterator> my_pair(my_vector.begin(),my_vector.end());
|
||||
|
||||
// test the algorithms with list and const list
|
||||
test_algorithms(my_list);
|
||||
test_algorithms(my_vector);
|
||||
test_algorithms(my_pair);
|
||||
|
||||
|
||||
std::vector<int> v;
|
||||
std::vector<int>& cv = v;
|
||||
|
||||
using namespace boost;
|
||||
|
||||
#define BOOST_RANGE_RETURNS_TEST( function_name, cont ) \
|
||||
function_name (cont); \
|
||||
function_name <return_found> (cont); \
|
||||
function_name <return_next> (cont); \
|
||||
function_name <return_prior> (cont); \
|
||||
function_name <return_begin_found> (cont); \
|
||||
function_name <return_begin_next> (cont); \
|
||||
function_name <return_begin_prior> (cont); \
|
||||
function_name <return_found_end> (cont); \
|
||||
function_name <return_next_end>(cont); \
|
||||
function_name <return_prior_end>(cont);
|
||||
|
||||
BOOST_RANGE_RETURNS_TEST( adjacent_find, cv );
|
||||
BOOST_RANGE_RETURNS_TEST( adjacent_find, v );
|
||||
BOOST_RANGE_RETURNS_TEST( max_element, cv );
|
||||
BOOST_RANGE_RETURNS_TEST( max_element, v );
|
||||
BOOST_RANGE_RETURNS_TEST( min_element, cv );
|
||||
BOOST_RANGE_RETURNS_TEST( min_element, v );
|
||||
BOOST_RANGE_RETURNS_TEST( unique, v );
|
||||
#undef BOOST_RANGE_RETURNS_TEST
|
||||
|
||||
#define BOOST_RANGE_RETURNS_TEST1( function_name, cont, arg1 ) \
|
||||
function_name (cont, arg1); \
|
||||
function_name <return_found> (cont, arg1); \
|
||||
function_name <return_next> (cont, arg1); \
|
||||
function_name <return_prior> (cont, arg1); \
|
||||
function_name <return_begin_found> (cont, arg1); \
|
||||
function_name <return_begin_next> (cont, arg1); \
|
||||
function_name <return_begin_prior> (cont, arg1); \
|
||||
function_name <return_found_end> (cont, arg1); \
|
||||
function_name <return_next_end>(cont, arg1); \
|
||||
function_name <return_prior_end>(cont, arg1);
|
||||
|
||||
BOOST_RANGE_RETURNS_TEST1( adjacent_find, cv, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( adjacent_find, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( find, cv, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( find, v, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_end, cv, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_end, cv, v );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_end, v, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_end, v, v );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_first_of, cv, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_first_of, cv, v );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_first_of, v, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_first_of, v, v );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_if, cv, std::negate<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( find_if, v, std::negate<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( search, cv, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( search, cv, v );
|
||||
BOOST_RANGE_RETURNS_TEST1( search, v, cv );
|
||||
BOOST_RANGE_RETURNS_TEST1( search, v, v );
|
||||
|
||||
BOOST_RANGE_RETURNS_TEST1( remove, v, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( remove_if, v, std::negate<int>() );
|
||||
|
||||
BOOST_RANGE_RETURNS_TEST1( lower_bound, cv, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( lower_bound, v, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( max_element, cv, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( max_element, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( min_element, cv, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( min_element, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( upper_bound, cv, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( upper_bound, v, 0 );
|
||||
BOOST_RANGE_RETURNS_TEST1( partition, cv, std::negate<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( partition, v, std::negate<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( stable_partition, cv, std::negate<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST1( stable_partition, v, std::negate<int>() );
|
||||
|
||||
#undef BOOST_RANGE_RETURNS_TEST1
|
||||
|
||||
#define BOOST_RANGE_RETURNS_TEST2( function_name, arg1, arg2 ) \
|
||||
function_name (v, arg1, arg2); \
|
||||
function_name <return_found> (v, arg1, arg2); \
|
||||
function_name <return_next> (v, arg1, arg2); \
|
||||
function_name <return_prior> (v, arg1, arg2); \
|
||||
function_name <return_begin_found> (v, arg1, arg2); \
|
||||
function_name <return_begin_next> (v, arg1, arg2); \
|
||||
function_name <return_begin_prior> (v, arg1, arg2); \
|
||||
function_name <return_found_end> (v, arg1, arg2); \
|
||||
function_name <return_next_end>(v, arg1, arg2); \
|
||||
function_name <return_prior_end>(v, arg1, arg2);
|
||||
|
||||
BOOST_RANGE_RETURNS_TEST2( find_end, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST2( find_first_of, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST2( search, v, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST2( lower_bound, 0, std::less<int>() );
|
||||
BOOST_RANGE_RETURNS_TEST2( upper_bound, 0, std::less<int>() );
|
||||
|
||||
#undef BOOST_RANGE_RETURNS_TEST2
|
||||
}
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - Algorithm" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &simple_compile_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/adjacent_find.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_adjacent_find_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator const_iterator_t;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
std::equal_to<int> pred;
|
||||
|
||||
BOOST_CHECK( boost::adjacent_find(cont) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK( boost::adjacent_find(cont) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() );
|
||||
BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() );
|
||||
|
||||
cont += 2,3,4,5,5,5,6,7,8,9;
|
||||
iterator_t it = boost::adjacent_find(cont);
|
||||
iterator_t it_pred = boost::adjacent_find(cont, pred);
|
||||
BOOST_CHECK( it == it_pred );
|
||||
BOOST_CHECK( it != cont.end() );
|
||||
BOOST_CHECK( it == std::adjacent_find(cont.begin(), cont.end()) );
|
||||
if (it != cont.end())
|
||||
{
|
||||
BOOST_CHECK( *it == 5 );
|
||||
}
|
||||
const_iterator_t cit = boost::adjacent_find(cref_cont);
|
||||
const_iterator_t cit_pred = boost::adjacent_find(cref_cont, pred);
|
||||
BOOST_CHECK( cit == cit_pred );
|
||||
BOOST_CHECK( cit != cref_cont.end() );
|
||||
BOOST_CHECK( cit == std::adjacent_find(cref_cont.begin(), cref_cont.end()) );
|
||||
if (cit != cref_cont.end())
|
||||
{
|
||||
BOOST_CHECK( *cit == 5 );
|
||||
}
|
||||
}
|
||||
|
||||
void test_adjacent_find()
|
||||
{
|
||||
test_adjacent_find_impl< std::vector<int> >();
|
||||
test_adjacent_find_impl< std::list<int> >();
|
||||
test_adjacent_find_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.adjacent_find" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_adjacent_find ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/binary_search.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
bool reference_result
|
||||
= std::binary_search(reference.begin(), reference.end(), 5);
|
||||
|
||||
bool test_result = boost::binary_search(test, 5);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
sort_container(reference, pred);
|
||||
sort_container(test, pred);
|
||||
|
||||
bool reference_result
|
||||
= std::binary_search(reference.begin(), reference.end(), 5,
|
||||
pred);
|
||||
|
||||
bool test_result = boost::binary_search(test, 5, pred);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_binary_search_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test(cont);
|
||||
test_pred(cont, std::less<int>());
|
||||
test_pred(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_binary_search()
|
||||
{
|
||||
test_binary_search_impl< std::vector<int> >();
|
||||
test_binary_search_impl< std::list<int> >();
|
||||
test_binary_search_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.binary_search" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_binary_search ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_copy_impl()
|
||||
{
|
||||
Container source;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target;
|
||||
target.resize(source.size());
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t;
|
||||
iterator_t it = boost::copy(source, target.begin());
|
||||
|
||||
BOOST_CHECK( it == target.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
target.begin(), target.end(),
|
||||
source.begin(), source.end()
|
||||
);
|
||||
}
|
||||
|
||||
void test_copy()
|
||||
{
|
||||
test_copy_impl< std::vector<int> >();
|
||||
test_copy_impl< std::list<int> >();
|
||||
test_copy_impl< std::set<int> >();
|
||||
test_copy_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_copy ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/copy_backward.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_copy_backward_impl()
|
||||
{
|
||||
Container source;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target;
|
||||
target.resize(source.size());
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t;
|
||||
iterator_t it = boost::copy_backward(source, target.begin());
|
||||
|
||||
BOOST_CHECK( it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( target.begin(), target.end(),
|
||||
source.rbegin(), source.rend() );
|
||||
}
|
||||
|
||||
void test_copy_backward()
|
||||
{
|
||||
test_copy_backward_impl< std::vector<int> >();
|
||||
test_copy_backward_impl< std::list<int> >();
|
||||
test_copy_backward_impl< std::set<int> >();
|
||||
test_copy_backward_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy_backward" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_copy_backward ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/count.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_count_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
|
||||
cont += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
|
||||
cont += 2;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cont, 2) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count(cref_cont, 2) );
|
||||
}
|
||||
|
||||
void test_count()
|
||||
{
|
||||
test_count_impl< std::vector<int> >();
|
||||
test_count_impl< std::list<int> >();
|
||||
test_count_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_count ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/count_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_function/false_predicate.hpp"
|
||||
#include "../test_function/equal_to_x.hpp"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_count_if_impl()
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef equal_to_x<int> pred_t;
|
||||
|
||||
Container cont;
|
||||
const Container& cref_cont = cont;
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
|
||||
cont += 1;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
|
||||
cont += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
|
||||
cont += 2;
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count_if(cont, pred_t(2)) );
|
||||
BOOST_CHECK_EQUAL( 2u, boost::count_if(cref_cont, pred_t(2)) );
|
||||
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, false_predicate()) );
|
||||
BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, false_predicate()) );
|
||||
}
|
||||
|
||||
void test_count_if()
|
||||
{
|
||||
test_count_if_impl< std::vector<int> >();
|
||||
test_count_if_impl< std::list<int> >();
|
||||
test_count_if_impl< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_count_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/equal.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_equal_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
container2_t mcont2;
|
||||
|
||||
Container1& cont1 = mcont1;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1.clear();
|
||||
mcont2 += 1;
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 1;
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4,5,6,7,8,9;
|
||||
BOOST_CHECK( boost::equal(cont1, cont2) );
|
||||
BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to<int>()) );
|
||||
BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to<int>()) );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_driver()
|
||||
{
|
||||
typedef Container1 container1_t;
|
||||
typedef Container2 container2_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container1>::type const_container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::add_const<Container2>::type const_container2_t;
|
||||
|
||||
test_equal_impl< const_container1_t, const_container2_t >();
|
||||
test_equal_impl< const_container1_t, container2_t >();
|
||||
test_equal_impl< container1_t, const_container2_t >();
|
||||
test_equal_impl< container1_t, container2_t >();
|
||||
}
|
||||
|
||||
void test_equal()
|
||||
{
|
||||
test_driver< std::list<int>, std::list<int> >();
|
||||
test_driver< std::vector<int>, std::vector<int> >();
|
||||
test_driver< std::set<int>, std::set<int> >();
|
||||
test_driver< std::multiset<int>, std::multiset<int> >();
|
||||
test_driver< std::list<int>, std::vector<int> >();
|
||||
test_driver< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_equal ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/equal_range.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container, class Pair>
|
||||
void check_result(
|
||||
const Container& reference,
|
||||
Pair reference_pair,
|
||||
const Container& test,
|
||||
Pair test_pair
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<const Container>::type
|
||||
const_iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<const_iterator_t>(reference.begin(), reference_pair.first),
|
||||
std::distance<const_iterator_t>(test.begin(), test_pair.first)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<const_iterator_t>(reference.begin(), reference_pair.second),
|
||||
std::distance<const_iterator_t>(test.begin(), test_pair.second)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_pair.first, reference_pair.second,
|
||||
test_pair.first, test_pair.second
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
typedef std::pair<iterator_t, iterator_t> pair_t;
|
||||
|
||||
pair_t reference_result
|
||||
= std::equal_range(reference.begin(), reference.end(), 5);
|
||||
|
||||
pair_t test_result = boost::equal_range(test, 5);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container>::type container_t;
|
||||
|
||||
container_t reference_temp(cont);
|
||||
container_t test_temp(cont);
|
||||
|
||||
sort_container(reference_temp, pred);
|
||||
sort_container(test_temp, pred);
|
||||
|
||||
Container reference(reference_temp);
|
||||
Container test(test_temp);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
typedef std::pair<iterator_t, iterator_t> pair_t;
|
||||
|
||||
pair_t reference_result
|
||||
= std::equal_range(reference.begin(), reference.end(), 5,
|
||||
BinaryPredicate());
|
||||
|
||||
pair_t test_result = boost::equal_range(test, 5, BinaryPredicate());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test, test_result);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_driver(const Container& cont)
|
||||
{
|
||||
Container mutable_cont(cont);
|
||||
test(mutable_cont);
|
||||
|
||||
test(cont);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_pred_driver(const Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container mutable_cont(cont);
|
||||
test_pred(mutable_cont, pred);
|
||||
|
||||
test_pred(cont, pred);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_equal_range_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont);
|
||||
test_pred_driver(cont, std::less<int>());
|
||||
test_pred_driver(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_equal_range()
|
||||
{
|
||||
test_equal_range_impl< std::vector<int> >();
|
||||
test_equal_range_impl< std::list<int> >();
|
||||
test_equal_range_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal_range" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_equal_range ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/fill.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_fill_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
std::fill(reference.begin(), reference.end(), 1);
|
||||
|
||||
Container target(cont);
|
||||
boost::fill(target, 1);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_fill_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 2;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2;
|
||||
test_fill_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_fill_impl(cont);
|
||||
}
|
||||
|
||||
void test_fill()
|
||||
{
|
||||
test_fill_impl< std::vector<int> >();
|
||||
test_fill_impl< std::list<int> >();
|
||||
test_fill_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.fill" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_fill ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class find_test_policy
|
||||
{
|
||||
public:
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find(cont, 3);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::find<return_type>(cont, 3);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find(cont.begin(), cont.end(), 3);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_find_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, find_test_policy());
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, find_test_policy());
|
||||
}
|
||||
|
||||
void test_find()
|
||||
{
|
||||
test_find_container< std::vector<int> >();
|
||||
test_find_container< std::list<int> >();
|
||||
test_find_container< std::deque<int> >();
|
||||
|
||||
test_find_container< const std::vector<int> >();
|
||||
test_find_container< const std::list<int> >();
|
||||
test_find_container< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_end.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container2>
|
||||
class find_end_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_end(cont, m_cont);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::find_end<return_type>(cont, policy.cont());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_end_pred_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_end_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_end(cont, m_cont, m_pred);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::find_end<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_end(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_end_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_end_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_end_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_end_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_end()
|
||||
{
|
||||
test_find_end_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::list<int>, std::list<int> >();
|
||||
test_find_end_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_end_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_end_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_end_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_end_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_end ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_first_of.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container2>
|
||||
class find_first_of_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_first_of(cont, m_cont);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::find_first_of<return_type>(cont, policy.cont());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end());
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
};
|
||||
|
||||
template<class Container2, class BinaryPredicate>
|
||||
class find_first_of_pred_test_policy
|
||||
{
|
||||
typedef Container2 container2_t;
|
||||
public:
|
||||
explicit find_first_of_pred_test_policy(const Container2& cont)
|
||||
: m_cont(cont)
|
||||
{
|
||||
}
|
||||
|
||||
container2_t& cont() { return m_cont; }
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_first_of(cont, m_cont, m_pred);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::find_first_of<return_type>(cont, policy.cont(), policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_first_of(cont.begin(), cont.end(),
|
||||
m_cont.begin(), m_cont.end(),
|
||||
m_pred);
|
||||
}
|
||||
|
||||
private:
|
||||
Container2 m_cont;
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void run_tests(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
range_test::range_return_test_driver test_driver;
|
||||
test_driver(cont1, find_first_of_test_policy<Container2>(cont2));
|
||||
test_driver(cont1, find_first_of_pred_test_policy<Container2, std::less<int> >(cont2));
|
||||
test_driver(cont2, find_first_of_pred_test_policy<Container2, std::greater<int> >(cont2));
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_find_first_of_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t mcont1;
|
||||
Container1& cont1 = mcont1;
|
||||
container2_t mcont2;
|
||||
Container2& cont2 = mcont2;
|
||||
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2 += 1;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont1 += 2,3,4,5,6,7,8,9;
|
||||
mcont2 += 2,3,4;
|
||||
run_tests(cont1, cont2);
|
||||
|
||||
mcont2.clear();
|
||||
mcont2 += 7,8,9;
|
||||
run_tests(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_find_first_of()
|
||||
{
|
||||
test_find_first_of_impl< std::vector<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::deque<int>, std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::deque<int>, const std::deque<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, const std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, const std::vector<int> >();
|
||||
test_find_first_of_impl< const std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< const std::list<int>, std::vector<int> >();
|
||||
test_find_first_of_impl< std::vector<int>, std::list<int> >();
|
||||
test_find_first_of_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/find_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include "../test_function/greater_than_x.hpp"
|
||||
#include "../test_function/false_predicate.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class UnaryPredicate>
|
||||
class find_if_test_policy
|
||||
{
|
||||
public:
|
||||
explicit find_if_test_policy(UnaryPredicate pred)
|
||||
: m_pred(pred) {}
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::find_if(cont, m_pred);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(find_if_test_policy& policy, Container& cont)
|
||||
{
|
||||
return boost::find_if<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::find_if(cont.begin(), cont.end(), m_pred);
|
||||
}
|
||||
|
||||
UnaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
UnaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class UnaryPredicate>
|
||||
find_if_test_policy<UnaryPredicate>
|
||||
make_policy(UnaryPredicate pred)
|
||||
{
|
||||
return find_if_test_policy<UnaryPredicate>(pred);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_find_if_container()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, make_policy(greater_than_x<int>(5)));
|
||||
test_driver(cont, make_policy(false_predicate()));
|
||||
}
|
||||
|
||||
void test_find_if()
|
||||
{
|
||||
test_find_if_container< std::vector<int> >();
|
||||
test_find_if_container< std::list<int> >();
|
||||
test_find_if_container< std::deque<int> >();
|
||||
|
||||
test_find_if_container< const std::vector<int> >();
|
||||
test_find_if_container< const std::list<int> >();
|
||||
test_find_if_container< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_find_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/for_each.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "../test_function/check_equal_fn.hpp"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class SinglePassRange >
|
||||
void test_for_each_impl( SinglePassRange rng )
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
typedef check_equal_fn< SinglePassRange > fn_t;
|
||||
|
||||
// Test the mutable version
|
||||
fn_t result_fn = boost::for_each(rng, fn_t(rng));
|
||||
BOOST_CHECK_EQUAL( boost::distance(rng), result_fn.invocation_count() );
|
||||
|
||||
// Test the constant version
|
||||
const SinglePassRange& cref_rng = rng;
|
||||
result_fn = boost::for_each(cref_rng, fn_t(cref_rng));
|
||||
BOOST_CHECK_EQUAL( boost::distance(cref_rng), result_fn.invocation_count() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_for_each_t()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
// Test empty
|
||||
Container cont;
|
||||
test_for_each_impl(cont);
|
||||
|
||||
// Test one element
|
||||
cont += 0;
|
||||
test_for_each_impl(cont);
|
||||
|
||||
// Test many elements
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_for_each_impl(cont);
|
||||
}
|
||||
|
||||
void test_for_each()
|
||||
{
|
||||
boost::array<int, 10> a = { 0,1,2,3,4,5,6,7,8,9 };
|
||||
test_for_each_impl(a);
|
||||
|
||||
test_for_each_t< std::vector<int> >();
|
||||
test_for_each_t< std::list<int> >();
|
||||
test_for_each_t< std::set<int> >();
|
||||
test_for_each_t< std::multiset<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.for_each" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_for_each ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/generate.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class generator_fn
|
||||
{
|
||||
public:
|
||||
typedef int result_type;
|
||||
|
||||
generator_fn() : m_count(0) {}
|
||||
int operator()() { return ++m_count; }
|
||||
|
||||
private:
|
||||
int m_count;
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
void test_generate_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
std::generate(reference.begin(), reference.end(), generator_fn());
|
||||
|
||||
Container test(cont);
|
||||
boost::generate(test, generator_fn());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_generate_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_generate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 9;
|
||||
test_generate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 9,8,7,6,5,4,3,2,1;
|
||||
test_generate_impl(cont);
|
||||
}
|
||||
|
||||
void test_generate()
|
||||
{
|
||||
test_generate_impl< std::vector<int> >();
|
||||
test_generate_impl< std::list<int> >();
|
||||
test_generate_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.generate" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_generate ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/heap_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void check_equal(const Container1& cont1, const Container2& cont2)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
std::vector<int> test_cont(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::push_heap(reference.begin(), reference.end());
|
||||
boost::push_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end());
|
||||
boost::sort_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end());
|
||||
boost::make_heap(test_cont);
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end());
|
||||
boost::pop_heap(test_cont);
|
||||
check_equal(reference, test_cont);
|
||||
}
|
||||
|
||||
template<class BinaryPredicate>
|
||||
void test_pred(BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
std::vector<int> reference;
|
||||
reference += 1,2,3,4,5,6,7,8,9;
|
||||
std::sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
std::vector<int> test_cont(reference);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
reference.push_back(5);
|
||||
test_cont.push_back(5);
|
||||
std::push_heap(reference.begin(), reference.end(), pred);
|
||||
boost::push_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
|
||||
std::sort_heap(reference.begin(), reference.end(), pred);
|
||||
boost::sort_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
|
||||
std::make_heap(reference.begin(), reference.end(), pred);
|
||||
boost::make_heap(test_cont, pred);
|
||||
|
||||
std::pop_heap(reference.begin(), reference.end(), pred);
|
||||
boost::pop_heap(test_cont, pred);
|
||||
check_equal(reference, test_cont);
|
||||
}
|
||||
|
||||
void test_heap()
|
||||
{
|
||||
test();
|
||||
test_pred(std::less<int>());
|
||||
test_pred(std::greater<int>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.heap" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_heap ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
Container1 old_cont1(cont1);
|
||||
Container2 old_cont2(cont2);
|
||||
|
||||
bool reference_result
|
||||
= std::includes(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
bool test_result = boost::includes(cont1, cont2);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont1.begin(), old_cont1.end(),
|
||||
cont1.begin(), cont1.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont2.begin(), old_cont2.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
Container1 old_cont1(cont1);
|
||||
Container2 old_cont2(cont2);
|
||||
|
||||
bool reference_result
|
||||
= std::includes(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
pred);
|
||||
|
||||
bool test_result = boost::includes(cont1, cont2, pred);
|
||||
|
||||
BOOST_CHECK( reference_result == test_result );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont1.begin(), old_cont1.end(),
|
||||
cont1.begin(), cont1.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont2.begin(), old_cont2.end(),
|
||||
cont2.begin(), cont2.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_includes_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_includes_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_includes_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_includes_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_includes()
|
||||
{
|
||||
test_includes_impl< std::vector<int>, std::vector<int> >();
|
||||
test_includes_impl< std::list<int>, std::list<int> >();
|
||||
test_includes_impl< std::deque<int>, std::deque<int> >();
|
||||
test_includes_impl< std::vector<int>, std::list<int> >();
|
||||
test_includes_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.includes" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_includes ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/inplace_merge.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference_target(cont1.begin(), cont1.end());
|
||||
reference_target.insert(reference_target.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
std::vector<value_t> test_target(reference_target);
|
||||
|
||||
std::inplace_merge(reference_target.begin(),
|
||||
reference_target.begin() + cont1.size(),
|
||||
reference_target.end());
|
||||
|
||||
boost::inplace_merge(test_target,
|
||||
test_target.begin() + cont1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference_target(cont1.begin(), cont1.end());
|
||||
reference_target.insert(reference_target.end(),
|
||||
cont2.begin(), cont2.end());
|
||||
|
||||
std::vector<value_t> test_target(reference_target);
|
||||
|
||||
std::inplace_merge(reference_target.begin(),
|
||||
reference_target.begin() + cont1.size(),
|
||||
reference_target.end(), pred);
|
||||
|
||||
boost::inplace_merge(test_target,
|
||||
test_target.begin() + cont1.size(),
|
||||
pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_inplace_merge_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_inplace_merge_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,3,5,7,9,11,13,15,17,19;
|
||||
cont2 += 2,4,6,8,10,12,14,16,18,20;
|
||||
test_inplace_merge_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_inplace_merge()
|
||||
{
|
||||
test_inplace_merge_impl< std::vector<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.inplace_merge" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_inplace_merge ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/lexicographical_compare.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class ForwardRange1, class ForwardRange2>
|
||||
void test_lexicographical_compare_impl_nopred(ForwardRange1& rng1,
|
||||
ForwardRange2& rng2)
|
||||
{
|
||||
bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2));
|
||||
|
||||
bool test = boost::lexicographical_compare(rng1, rng2);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
}
|
||||
|
||||
template<class ForwardRange1, class ForwardRange2,
|
||||
class BinaryPredicate>
|
||||
void test_lexicographical_compare_impl_pred(ForwardRange1& rng1,
|
||||
ForwardRange2& rng2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
bool reference = std::lexicographical_compare(
|
||||
boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2),
|
||||
pred);
|
||||
|
||||
bool test = boost::lexicographical_compare(rng1, rng2, pred);
|
||||
|
||||
BOOST_CHECK( reference == test );
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_lexicographical_compare_impl(Container1& cont1,
|
||||
Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::range_value<Container1>::type value_t;
|
||||
|
||||
test_lexicographical_compare_impl_nopred(cont1, cont2);
|
||||
test_lexicographical_compare_impl_pred(cont1, cont2, std::less<value_t>());
|
||||
test_lexicographical_compare_impl_pred(cont1, cont2, std::greater<value_t>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_lexicographical_compare_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type container1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type container2_t;
|
||||
|
||||
container1_t cont1;
|
||||
container2_t cont2;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1.push_back(1);
|
||||
cont2.push_back(1);
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2;
|
||||
cont2 += 1;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
cont2 += 2;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7;
|
||||
cont2 += 1,2,3,4,5,6,7;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7;
|
||||
cont2 += 1,2,3,4,5,6;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6;
|
||||
cont2 += 1,2,3,4,5,6,7;
|
||||
test_lexicographical_compare_impl<Container1,Container2>(cont1, cont2);
|
||||
}
|
||||
|
||||
template<class Container1>
|
||||
void test_lexicographical_compare_rhs()
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_value<Container1>::type value_t;
|
||||
|
||||
test_lexicographical_compare_impl<Container1, const std::vector<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, const std::deque<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, const std::list<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::vector<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::deque<value_t> >();
|
||||
test_lexicographical_compare_impl<Container1, std::list<value_t> >();
|
||||
}
|
||||
|
||||
void test_lexicographical_compare()
|
||||
{
|
||||
test_lexicographical_compare_rhs< const std::vector<int> >();
|
||||
test_lexicographical_compare_rhs< const std::deque<int> >();
|
||||
test_lexicographical_compare_rhs< const std::list<int> >();
|
||||
test_lexicographical_compare_rhs< std::vector<int> >();
|
||||
test_lexicographical_compare_rhs< std::deque<int> >();
|
||||
test_lexicographical_compare_rhs< std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lexicographical_compare" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_lexicographical_compare ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/lower_bound.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/algorithm/lower_bound.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class lower_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::lower_bound(cont, 5);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::lower_bound<return_type>(cont, 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct lower_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::lower_bound(cont, 5, m_pred);
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::lower_bound<return_type>(
|
||||
cont, 5, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::lower_bound(
|
||||
cont.begin(), cont.end(), 5, m_pred);
|
||||
}
|
||||
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_lower_bound_impl()
|
||||
{
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_lower_bound_impl<Container>(
|
||||
lower_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_lower_bound()
|
||||
{
|
||||
test_lower_bound_impl< std::vector<int> >();
|
||||
test_lower_bound_impl< std::list<int> >();
|
||||
test_lower_bound_impl< std::deque<int> >();
|
||||
|
||||
test_lower_bound_impl< const std::vector<int> >();
|
||||
test_lower_bound_impl< const std::list<int> >();
|
||||
test_lower_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/max_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class max_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::max_element(cont);
|
||||
}
|
||||
|
||||
template<range_return_value return_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::max_element<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::max_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class max_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::max_element(cont, Pred());
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::max_element<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::max_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_max_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_max_element_impl()
|
||||
{
|
||||
test_max_element_impl<Container>(max_element_test_policy());
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::less<int> >());
|
||||
|
||||
test_max_element_impl<Container>(
|
||||
max_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
|
||||
void test_max_element()
|
||||
{
|
||||
test_max_element_impl< const std::vector<int> >();
|
||||
test_max_element_impl< const std::deque<int> >();
|
||||
test_max_element_impl< const std::list<int> >();
|
||||
|
||||
test_max_element_impl< std::vector<int> >();
|
||||
test_max_element_impl< std::deque<int> >();
|
||||
test_max_element_impl< std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_max_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/merge.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t reference_it
|
||||
= std::merge(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference_target.begin());
|
||||
|
||||
std::vector<value_t> test_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t test_it
|
||||
= boost::merge(cont1, cont2, test_target.begin());
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<iterator_t>(reference_target.begin(), reference_it),
|
||||
std::distance<iterator_t>(test_target.begin(), test_it)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t reference_it
|
||||
= std::merge(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference_target.begin(), pred);
|
||||
|
||||
std::vector<value_t> test_target( cont1.size() + cont2.size() );
|
||||
|
||||
iterator_t test_it
|
||||
= boost::merge(cont1, cont2, test_target.begin(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance(reference_target.begin(), reference_it),
|
||||
std::distance(test_target.begin(), test_it)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference_target.begin(), reference_target.end(),
|
||||
test_target.begin(), test_target.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_merge_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_merge_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_merge_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,3,5,7,9,11,13,15,17,19;
|
||||
cont2 += 2,4,6,8,10,12,14,16,18,20;
|
||||
test_merge_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_merge()
|
||||
{
|
||||
test_merge_impl< std::vector<int>, std::vector<int> >();
|
||||
test_merge_impl< std::list<int>, std::list<int> >();
|
||||
test_merge_impl< std::deque<int>, std::deque<int> >();
|
||||
|
||||
test_merge_impl< std::list<int>, std::vector<int> >();
|
||||
test_merge_impl< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.merge" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_merge ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/min_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class min_element_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::min_element(cont);
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::min_element<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::min_element(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Pred>
|
||||
class min_element_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::min_element(cont, Pred());
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::min_element<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::min_element(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_min_element_impl(TestPolicy policy)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_min_element_impl()
|
||||
{
|
||||
test_min_element_impl<Container>(min_element_test_policy());
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::less<int> >());
|
||||
|
||||
test_min_element_impl<Container>(
|
||||
min_element_pred_test_policy<std::greater<int> >());
|
||||
}
|
||||
|
||||
void test_min_element()
|
||||
{
|
||||
test_min_element_impl< const std::vector<int> >();
|
||||
test_min_element_impl< const std::deque<int> >();
|
||||
test_min_element_impl< const std::list<int> >();
|
||||
|
||||
test_min_element_impl< std::vector<int> >();
|
||||
test_min_element_impl< std::deque<int> >();
|
||||
test_min_element_impl< std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_min_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/mismatch.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_mismatch_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container1>::type MutableContainer1;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::remove_const<Container2>::type MutableContainer2;
|
||||
|
||||
MutableContainer1 cont1;
|
||||
const Container1& cref_cont1 = cont1;
|
||||
MutableContainer2 cont2;
|
||||
const Container2& cref_cont2 = cont2;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::iterator iterator2_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container2::const_iterator const_iterator2_t;
|
||||
|
||||
typedef std::pair<iterator1_t, iterator2_t> pair_mmit_t;
|
||||
typedef std::pair<const_iterator1_t, iterator2_t> pair_cmit_t;
|
||||
typedef std::pair<iterator1_t, const_iterator2_t> pair_mcit_t;
|
||||
typedef std::pair<const_iterator1_t, const_iterator2_t> pair_ccit_t;
|
||||
|
||||
pair_mmit_t pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
|
||||
pair_cmit_t pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
|
||||
pair_mcit_t pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
|
||||
pair_ccit_t pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,3,4;
|
||||
pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.end() );
|
||||
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.end() );
|
||||
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.end() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.end() );
|
||||
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.end() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.end() );
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4;
|
||||
cont2 += 1,2,5,4;
|
||||
pair_mmit = boost::mismatch(cont1, cont2);
|
||||
BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 );
|
||||
BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 );
|
||||
BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 );
|
||||
pair_mmit = boost::mismatch(cont1, cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_mmit.first == cont1.begin() );
|
||||
BOOST_CHECK( pair_mmit.second == cont2.begin() );
|
||||
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2);
|
||||
BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 );
|
||||
BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 );
|
||||
BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 );
|
||||
pair_cmit = boost::mismatch(cref_cont1, cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_cmit.first == cref_cont1.begin() );
|
||||
BOOST_CHECK( pair_cmit.second == cont2.begin() );
|
||||
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 );
|
||||
BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 );
|
||||
BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 );
|
||||
pair_mcit = boost::mismatch(cont1, cref_cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_mcit.first == cont1.begin() );
|
||||
BOOST_CHECK( pair_mcit.second == cref_cont2.begin() );
|
||||
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2);
|
||||
BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 );
|
||||
BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 );
|
||||
BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 );
|
||||
pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::not_equal_to<int>());
|
||||
BOOST_CHECK( pair_ccit.first == cref_cont1.begin() );
|
||||
BOOST_CHECK( pair_ccit.second == cref_cont2.begin() );
|
||||
}
|
||||
|
||||
void test_mismatch()
|
||||
{
|
||||
test_mismatch_impl< std::list<int>, std::list<int> >();
|
||||
test_mismatch_impl< const std::list<int>, std::list<int> >();
|
||||
test_mismatch_impl< std::list<int>, const std::list<int> >();
|
||||
test_mismatch_impl< const std::list<int>, const std::list<int> >();
|
||||
|
||||
test_mismatch_impl< std::vector<int>, std::list<int> >();
|
||||
test_mismatch_impl< const std::vector<int>, std::list<int> >();
|
||||
test_mismatch_impl< std::vector<int>, const std::list<int> >();
|
||||
test_mismatch_impl< const std::vector<int>, const std::list<int> >();
|
||||
|
||||
test_mismatch_impl< std::list<int>, std::vector<int> >();
|
||||
test_mismatch_impl< const std::list<int>, std::vector<int> >();
|
||||
test_mismatch_impl< std::list<int>, const std::vector<int> >();
|
||||
test_mismatch_impl< const std::list<int>, const std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.mismatch" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_mismatch ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm/permutation.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_next_permutation_impl(const Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::next_permutation(reference.begin(), reference.end());
|
||||
|
||||
const bool test_ret
|
||||
= boost::next_permutation(test);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_next_permutation_pred_impl(const Container& cont,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::next_permutation(reference.begin(), reference.end(),
|
||||
pred);
|
||||
|
||||
const bool test_ret
|
||||
= boost::next_permutation(test, pred);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_next_permutation_(const Container& cont)
|
||||
{
|
||||
test_next_permutation_impl(cont);
|
||||
test_next_permutation_pred_impl(cont, std::less<int>());
|
||||
test_next_permutation_pred_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_next_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_next_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_next_permutation_(cont);
|
||||
}
|
||||
|
||||
void test_next_permutation()
|
||||
{
|
||||
run_tests< std::vector<int> >();
|
||||
run_tests< std::list<int> >();
|
||||
run_tests< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.next_permutation" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_next_permutation ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/nth_element.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct nth_element_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::nth_element(cont, mid);
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
std::nth_element(cont.begin(), mid, cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class BinaryPredicate>
|
||||
struct nth_element_pred_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::nth_element(cont, mid, BinaryPredicate());
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_nth_element(Container& cont, Iterator mid)
|
||||
{
|
||||
std::nth_element(cont.begin(), mid, cont.end(), BinaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_nth_element_tp_impl(Container& cont, TestPolicy policy)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL( reference.size(), test.size() );
|
||||
if (reference.size() != test.size())
|
||||
return;
|
||||
|
||||
iterator_t reference_mid = reference.begin();
|
||||
iterator_t test_mid = test.begin();
|
||||
|
||||
bool complete = false;
|
||||
while (!complete)
|
||||
{
|
||||
if (reference_mid == reference.end())
|
||||
complete = true;
|
||||
|
||||
policy.test_nth_element(test, test_mid);
|
||||
policy.reference_nth_element(reference, reference_mid);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
if (reference_mid != reference.end())
|
||||
{
|
||||
++reference_mid;
|
||||
++test_mid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_nth_element_impl(Container& cont)
|
||||
{
|
||||
test_nth_element_tp_impl(cont, nth_element_policy());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_nth_element_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
test_nth_element_tp_impl(cont, nth_element_pred_policy<BinaryPredicate>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests(Container& cont)
|
||||
{
|
||||
test_nth_element_impl(cont);
|
||||
test_nth_element_impl(cont, std::less<int>());
|
||||
test_nth_element_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_nth_element_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
run_tests(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
run_tests(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
run_tests(cont);
|
||||
}
|
||||
|
||||
void test_nth_element()
|
||||
{
|
||||
test_nth_element_impl< std::vector<int> >();
|
||||
test_nth_element_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.nth_element" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_nth_element ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/partial_sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct partial_sort_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::partial_sort(cont, mid);
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
std::partial_sort(cont.begin(), mid, cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
template<class BinaryPredicate>
|
||||
struct partial_sort_pred_policy
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
boost::partial_sort(cont, mid, BinaryPredicate());
|
||||
}
|
||||
|
||||
template<class Container, class Iterator>
|
||||
void reference_partial_sort(Container& cont, Iterator mid)
|
||||
{
|
||||
std::partial_sort(cont.begin(), mid, cont.end(), BinaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy>
|
||||
void test_partial_sort_tp_impl(Container& cont, TestPolicy policy)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
BOOST_CHECK_EQUAL( reference.size(), test.size() );
|
||||
if (reference.size() != test.size())
|
||||
return;
|
||||
|
||||
iterator_t reference_mid = reference.begin();
|
||||
iterator_t test_mid = test.begin();
|
||||
|
||||
bool complete = false;
|
||||
while (!complete)
|
||||
{
|
||||
if (reference_mid == reference.end())
|
||||
complete = true;
|
||||
|
||||
policy.test_partial_sort(test, test_mid);
|
||||
policy.reference_partial_sort(reference, reference_mid);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
if (reference_mid != reference.end())
|
||||
{
|
||||
++reference_mid;
|
||||
++test_mid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_partial_sort_impl(Container& cont)
|
||||
{
|
||||
test_partial_sort_tp_impl(cont, partial_sort_policy());
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_partial_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
test_partial_sort_tp_impl(cont, partial_sort_pred_policy<BinaryPredicate>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_partial_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_partial_sort_impl(cont);
|
||||
test_partial_sort_impl(cont, std::less<int>());
|
||||
test_partial_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_partial_sort()
|
||||
{
|
||||
test_partial_sort_impl< std::vector<int> >();
|
||||
test_partial_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partial_sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_partial_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/partition.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::partition(cont, UnaryPredicate());
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::partition<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_partition()
|
||||
{
|
||||
test_partition_impl< std::vector<int> >();
|
||||
test_partition_impl< std::list<int> >();
|
||||
test_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm/permutation.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_prev_permutation_impl(const Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::prev_permutation(reference.begin(), reference.end());
|
||||
|
||||
const bool test_ret
|
||||
= boost::prev_permutation(test);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_prev_permutation_pred_impl(const Container& cont,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
const bool reference_ret
|
||||
= std::prev_permutation(reference.begin(), reference.end(),
|
||||
pred);
|
||||
|
||||
const bool test_ret
|
||||
= boost::prev_permutation(test, pred);
|
||||
|
||||
BOOST_CHECK( reference_ret == test_ret );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_prev_permutation_(const Container& cont)
|
||||
{
|
||||
test_prev_permutation_impl(cont);
|
||||
test_prev_permutation_pred_impl(cont, std::less<int>());
|
||||
test_prev_permutation_pred_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void run_tests()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_prev_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_prev_permutation_(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_prev_permutation_(cont);
|
||||
}
|
||||
|
||||
void test_prev_permutation()
|
||||
{
|
||||
run_tests< std::vector<int> >();
|
||||
run_tests< std::list<int> >();
|
||||
run_tests< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.prev_permutation" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_prev_permutation ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/random_shuffle.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_function/counted_function.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Int>
|
||||
class counted_generator
|
||||
: private range_test_function::counted_function
|
||||
{
|
||||
public:
|
||||
typedef Int result_type;
|
||||
typedef Int argument_type;
|
||||
|
||||
using range_test_function::counted_function::invocation_count;
|
||||
|
||||
result_type operator()(argument_type modulo_value)
|
||||
{
|
||||
invoked();
|
||||
return static_cast<result_type>(std::rand() % modulo_value);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
bool test_shuffle_result(
|
||||
const Container& old_cont,
|
||||
const Container& new_cont
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<const Container>::type iterator_t;
|
||||
|
||||
// The size must remain equal
|
||||
BOOST_CHECK_EQUAL( old_cont.size(), new_cont.size() );
|
||||
if (old_cont.size() != new_cont.size())
|
||||
return false;
|
||||
|
||||
if (new_cont.size() < 2)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
old_cont.begin(), old_cont.end(),
|
||||
new_cont.begin(), new_cont.end()
|
||||
);
|
||||
|
||||
return std::equal(old_cont.begin(), old_cont.end(),
|
||||
new_cont.begin());
|
||||
}
|
||||
|
||||
// Elements must only be moved around. This is tested by
|
||||
// ensuring the count of each element remains the
|
||||
// same.
|
||||
bool failed = false;
|
||||
iterator_t last = old_cont.end();
|
||||
for (iterator_t it = old_cont.begin(); !failed && (it != last); ++it)
|
||||
{
|
||||
const std::size_t old_count
|
||||
= std::count(old_cont.begin(), old_cont.end(), *it);
|
||||
|
||||
const std::size_t new_count
|
||||
= std::count(new_cont.begin(), new_cont.end(), *it);
|
||||
|
||||
BOOST_CHECK_EQUAL( old_count, new_count );
|
||||
|
||||
failed = (old_count != new_count);
|
||||
}
|
||||
|
||||
return !failed;
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_nogen_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
const int MAX_RETRIES = 10000;
|
||||
|
||||
bool shuffled = false;
|
||||
for (int attempt = 0; !shuffled && (attempt < MAX_RETRIES); ++attempt)
|
||||
{
|
||||
Container test(cont);
|
||||
boost::random_shuffle(test);
|
||||
bool ok = test_shuffle_result(cont, test);
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
// Since the counts are equal, then if they are
|
||||
// not equal the contents must have been shuffled
|
||||
if (cont.size() == test.size()
|
||||
&& !std::equal(cont.begin(), cont.end(), test.begin()))
|
||||
{
|
||||
shuffled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class RandomGenerator, class Container>
|
||||
void test_random_shuffle_gen_impl(Container& cont)
|
||||
{
|
||||
RandomGenerator gen;
|
||||
Container old_cont(cont);
|
||||
boost::random_shuffle(cont, gen);
|
||||
test_shuffle_result(cont, old_cont);
|
||||
if (cont.size() > 2)
|
||||
{
|
||||
BOOST_CHECK( gen.invocation_count() > 0 );
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_impl(Container& cont)
|
||||
{
|
||||
Container old_cont(cont);
|
||||
boost::random_shuffle(cont);
|
||||
test_shuffle_result(cont, old_cont);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_random_shuffle_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef counted_generator<
|
||||
BOOST_DEDUCED_TYPENAME range_difference<Container>::type > generator_t;
|
||||
|
||||
Container cont;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_random_shuffle_nogen_impl(cont);
|
||||
test_random_shuffle_gen_impl<generator_t>(cont);
|
||||
}
|
||||
|
||||
void test_random_shuffle()
|
||||
{
|
||||
test_random_shuffle_impl< std::vector<int> >();
|
||||
test_random_shuffle_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.random_shuffle" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_random_shuffle ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/remove.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class Value >
|
||||
void test_remove_impl( const Container& c, Value to_remove )
|
||||
{
|
||||
Container reference(c);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::remove(reference.begin(), reference.end(), to_remove);
|
||||
|
||||
Container test(c);
|
||||
iterator_t test_it = boost::remove(test, to_remove);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_impl(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_impl(cont, 0);
|
||||
test_remove_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_impl(cont, 0);
|
||||
test_remove_impl(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_impl(cont, 1);
|
||||
test_remove_impl(cont, 9);
|
||||
test_remove_impl(cont, 4);
|
||||
}
|
||||
|
||||
void test_remove()
|
||||
{
|
||||
test_remove_impl< std::vector<int> >();
|
||||
test_remove_impl< std::list<int> >();
|
||||
test_remove_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_remove ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/remove_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_remove_if_impl( const Container& c, UnaryPredicate pred )
|
||||
{
|
||||
Container reference(c);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::remove_if(reference.begin(), reference.end(), pred);
|
||||
|
||||
Container test(c);
|
||||
iterator_t test_it = boost::remove_if(test, pred);
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_if_( const Container& c, int to_remove )
|
||||
{
|
||||
test_remove_if_impl(c, boost::bind(std::equal_to<int>(), _1, to_remove));
|
||||
test_remove_if_impl(c, boost::bind(std::not_equal_to<int>(), _1, to_remove));
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_remove_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_remove_if_(cont, 0);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_remove_if_(cont, 0);
|
||||
test_remove_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,1,1,1,1;
|
||||
test_remove_if_(cont, 0);
|
||||
test_remove_if_(cont, 1);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_remove_if_(cont, 1);
|
||||
test_remove_if_(cont, 9);
|
||||
test_remove_if_(cont, 4);
|
||||
}
|
||||
|
||||
inline void test_remove_if()
|
||||
{
|
||||
test_remove_if_impl< std::vector<int> >();
|
||||
test_remove_if_impl< std::list<int> >();
|
||||
test_remove_if_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_remove_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/replace.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_replace_impl(Container& cont)
|
||||
{
|
||||
const int what = 2;
|
||||
const int with_what = 5;
|
||||
|
||||
std::vector<int> reference(cont.begin(), cont.end());
|
||||
std::replace(reference.begin(), reference.end(), what, with_what);
|
||||
|
||||
std::vector<int> target(cont.begin(), cont.end());
|
||||
boost::replace(target, what, with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_impl(cont);
|
||||
}
|
||||
|
||||
void test_replace()
|
||||
{
|
||||
test_replace_impl< std::vector<int> >();
|
||||
test_replace_impl< std::list<int> >();
|
||||
test_replace_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_replace ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/replace_if.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container, class UnaryPredicate >
|
||||
void test_replace_if_impl(Container& cont, UnaryPredicate pred)
|
||||
{
|
||||
const int what = 2;
|
||||
const int with_what = 5;
|
||||
|
||||
std::vector<int> reference(cont.begin(), cont.end());
|
||||
std::replace_if(reference.begin(), reference.end(),
|
||||
boost::bind(pred, _1, what), with_what);
|
||||
|
||||
std::vector<int> target(cont.begin(), cont.end());
|
||||
boost::replace_if(target, boost::bind(pred, _1, what), with_what);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_if_impl(Container& cont)
|
||||
{
|
||||
test_replace_if_impl(cont, std::equal_to<int>());
|
||||
test_replace_if_impl(cont, std::not_equal_to<int>());
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_replace_if_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_replace_if_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_replace_if_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_replace_if_impl(cont);
|
||||
}
|
||||
|
||||
void test_replace_if()
|
||||
{
|
||||
test_replace_if_impl< std::vector<int> >();
|
||||
test_replace_if_impl< std::list<int> >();
|
||||
test_replace_if_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace_if" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_replace_if ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/reverse.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_reverse_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::reverse(test);
|
||||
std::reverse(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_reverse_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_reverse_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_reverse_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_reverse_impl(cont);
|
||||
}
|
||||
|
||||
void test_reverse()
|
||||
{
|
||||
test_reverse_impl< std::vector<int> >();
|
||||
test_reverse_impl< std::list<int> >();
|
||||
test_reverse_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.reverse" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_reverse ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/rotate.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container, class Iterator>
|
||||
void test_rotate_impl(Container& cont, Iterator where_it)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
Iterator reference_where_it = reference.begin();
|
||||
std::advance(reference_where_it,
|
||||
std::distance(cont.begin(), where_it));
|
||||
|
||||
std::rotate(reference.begin(), reference_where_it, reference.end());
|
||||
|
||||
Iterator test_where_it = test.begin();
|
||||
std::advance(test_where_it,
|
||||
std::distance(cont.begin(), where_it));
|
||||
|
||||
boost::rotate(test, test_where_it);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_impl(Container& cont)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
iterator_t last = cont.end();
|
||||
for (iterator_t it = cont.begin(); it != last; ++it)
|
||||
{
|
||||
test_rotate_impl(cont, it);
|
||||
}
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_rotate_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_rotate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_rotate_impl(cont);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_rotate_impl(cont);
|
||||
}
|
||||
|
||||
void test_rotate()
|
||||
{
|
||||
test_rotate_impl< std::vector<int> >();
|
||||
test_rotate_impl< std::list<int> >();
|
||||
test_rotate_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_rotate ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/search.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container1, class Container2 >
|
||||
void test_search_impl(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t;
|
||||
|
||||
const Container1& ccont1 = cont1;
|
||||
const Container2& ccont2 = cont2;
|
||||
|
||||
iterator1_t it = boost::search(cont1, cont2);
|
||||
iterator1_t it2 = boost::search(cont1, ccont2);
|
||||
const_iterator1_t cit = boost::search(ccont1, cont2);
|
||||
const_iterator1_t cit2 = boost::search(ccont1, ccont2);
|
||||
|
||||
BOOST_CHECK( it == std::search(cont1.begin(), cont1.end(), cont2.begin(), cont2.end()) );
|
||||
BOOST_CHECK( it2 == std::search(cont1.begin(), cont1.end(), ccont2.begin(), ccont2.end()) );
|
||||
BOOST_CHECK( cit == std::search(ccont1.begin(), ccont1.end(), cont2.begin(), cont2.end()) );
|
||||
BOOST_CHECK( cit2 == std::search(ccont1.begin(), ccont1.end(), ccont2.begin(), ccont2.end()) );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_search_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 10,11,12;
|
||||
test_search_impl(cont1, cont2);
|
||||
|
||||
cont2.clear();
|
||||
cont2 += 4,5,6;
|
||||
test_search_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_search()
|
||||
{
|
||||
test_search_impl< std::list<int>, std::list<int> >();
|
||||
test_search_impl< std::vector<int>, std::vector<int> >();
|
||||
test_search_impl< std::set<int>, std::set<int> >();
|
||||
test_search_impl< std::list<int>, std::vector<int> >();
|
||||
test_search_impl< std::vector<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.search" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_search ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_difference(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_difference(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_difference_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_difference_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_difference_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_difference()
|
||||
{
|
||||
test_set_difference_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_difference_impl< std::list<int>, std::list<int> >();
|
||||
test_set_difference_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_difference_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_difference_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_difference" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_difference ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_intersection(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_intersection(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_intersection(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_intersection(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_intersection_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_intersection_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_intersection_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_intersection()
|
||||
{
|
||||
test_set_intersection_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_intersection_impl< std::list<int>, std::list<int> >();
|
||||
test_set_intersection_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_intersection_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_intersection_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_intersection" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_intersection ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_symmetric_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_symmetric_difference(cont1, cont2,
|
||||
test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_symmetric_difference(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_symmetric_difference(cont1, cont2,
|
||||
test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_symmetric_difference_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_symmetric_difference_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_symmetric_difference_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_symmetric_difference()
|
||||
{
|
||||
test_set_symmetric_difference_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_symmetric_difference_impl< std::list<int>, std::list<int> >();
|
||||
test_set_symmetric_difference_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_symmetric_difference_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_symmetric_difference_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_symmetric_difference" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_symmetric_difference ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/set_algorithm.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container1, class Iterator, class Container2>
|
||||
void check_result(
|
||||
Container1& reference,
|
||||
Iterator reference_result,
|
||||
Container2& test_cont,
|
||||
Iterator test_result
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance<Iterator>(reference.begin(), reference_result),
|
||||
std::distance<Iterator>(test_cont.begin(), test_result)
|
||||
);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test_cont.begin(), test_cont.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_union(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin());
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_union(cont1, cont2, test_cont.begin());
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void sort_container(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
}
|
||||
|
||||
template<class Container1,
|
||||
class Container2,
|
||||
class BinaryPredicate>
|
||||
void test_pred(Container1 cont1, Container2 cont2,
|
||||
BinaryPredicate pred)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
sort_container(cont1, pred);
|
||||
sort_container(cont2, pred);
|
||||
|
||||
std::vector<value_t> reference(cont1.size() + cont2.size());
|
||||
std::vector<value_t> test_cont(reference);
|
||||
|
||||
iterator_t reference_result
|
||||
= std::set_union(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), cont2.end(),
|
||||
reference.begin(),
|
||||
pred);
|
||||
|
||||
iterator_t test_result
|
||||
= boost::set_union(cont1, cont2, test_cont.begin(), pred);
|
||||
|
||||
check_result(reference, reference_result,
|
||||
test_cont, test_result);
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_union_impl(
|
||||
Container1& cont1,
|
||||
Container2& cont2
|
||||
)
|
||||
{
|
||||
test(cont1, cont2);
|
||||
test_pred(cont1, cont2, std::less<int>());
|
||||
test_pred(cont1, cont2, std::greater<int>());
|
||||
}
|
||||
|
||||
template<class Container1, class Container2>
|
||||
void test_set_union_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont2 += 1;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 1,2,3,4,5,6,7,8,9;
|
||||
cont2 += 2,3,4;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
|
||||
cont1.clear();
|
||||
cont2.clear();
|
||||
cont1 += 2,3,4;
|
||||
cont2 += 1,2,3,4,5,6,7,8,9;
|
||||
test_set_union_impl(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_set_union()
|
||||
{
|
||||
test_set_union_impl< std::vector<int>, std::vector<int> >();
|
||||
test_set_union_impl< std::list<int>, std::list<int> >();
|
||||
test_set_union_impl< std::deque<int>, std::deque<int> >();
|
||||
test_set_union_impl< std::vector<int>, std::list<int> >();
|
||||
test_set_union_impl< std::list<int>, std::vector<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_union" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_set_union ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_sort_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::sort(test);
|
||||
std::sort(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::sort(test, pred);
|
||||
std::sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_sort_impl(cont);
|
||||
test_sort_impl(cont, std::less<int>());
|
||||
test_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_sort()
|
||||
{
|
||||
test_sort_impl< std::vector<int> >();
|
||||
test_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/stable_partition.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
struct equal_to_5
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef int argument_type;
|
||||
bool operator()(int x) const { return x == 5; }
|
||||
};
|
||||
|
||||
// test the 'partition' algorithm
|
||||
template<class UnaryPredicate>
|
||||
class stable_partition_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::stable_partition(cont, UnaryPredicate());
|
||||
}
|
||||
|
||||
UnaryPredicate pred() const { return UnaryPredicate(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::stable_partition<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
void test_stable_partition_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
stable_partition_test_policy< equal_to_5 > policy;
|
||||
|
||||
Container cont;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
void test_stable_partition()
|
||||
{
|
||||
test_stable_partition_impl< std::vector<int> >();
|
||||
test_stable_partition_impl< std::list<int> >();
|
||||
test_stable_partition_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/stable_sort.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void test_stable_sort_impl(Container& cont)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::stable_sort(test);
|
||||
std::stable_sort(reference.begin(), reference.end());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container, class BinaryPredicate>
|
||||
void test_stable_sort_impl(Container& cont, BinaryPredicate pred)
|
||||
{
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
boost::stable_sort(test, pred);
|
||||
std::stable_sort(reference.begin(), reference.end(), pred);
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_stable_sort_impl()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,3,4,5,6,7,8,9;
|
||||
test_stable_sort_impl(cont);
|
||||
test_stable_sort_impl(cont, std::less<int>());
|
||||
test_stable_sort_impl(cont, std::greater<int>());
|
||||
}
|
||||
|
||||
void test_stable_sort()
|
||||
{
|
||||
test_stable_sort_impl< std::vector<int> >();
|
||||
test_stable_sort_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_sort" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_stable_sort ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/transform.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include "../test_function/multiply_by_x.hpp"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template< class Container >
|
||||
void test_transform_impl1(Container& cont)
|
||||
{
|
||||
using namespace boost::range_test_function;
|
||||
|
||||
const Container& ccont = cont;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
std::vector<value_t> target(cont.size());
|
||||
std::vector<value_t> reference(cont.size());
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
multiply_by_x<int> fn(2);
|
||||
|
||||
iterator_t reference_it
|
||||
= std::transform(cont.begin(), cont.end(), reference.begin(), fn);
|
||||
|
||||
iterator_t test_it
|
||||
= boost::transform(cont, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
target.clear();
|
||||
target.resize(ccont.size());
|
||||
|
||||
test_it = boost::transform(ccont, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container >
|
||||
void test_transform_impl1()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_transform_impl1(cont);
|
||||
|
||||
cont += 1;
|
||||
test_transform_impl1(cont);
|
||||
|
||||
cont += 2,3,4,5,6,7;
|
||||
test_transform_impl1(cont);
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_transform_impl2(Container1& cont1, Container2& cont2)
|
||||
{
|
||||
const Container1& ccont1 = cont1;
|
||||
const Container2& ccont2 = cont2;
|
||||
|
||||
BOOST_CHECK_EQUAL( cont1.size(), cont2.size() );
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
|
||||
|
||||
std::vector<value_t> target(cont1.size());
|
||||
std::vector<value_t> reference(cont1.size());
|
||||
typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
|
||||
|
||||
std::multiplies<int> fn;
|
||||
|
||||
iterator_t reference_it
|
||||
= std::transform(cont1.begin(), cont1.end(),
|
||||
cont2.begin(), reference.begin(), fn);
|
||||
|
||||
iterator_t test_it
|
||||
= boost::transform(cont1, cont2, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
|
||||
target.clear();
|
||||
target.resize(ccont1.size());
|
||||
|
||||
test_it = boost::transform(ccont1, ccont2, target.begin(), fn);
|
||||
|
||||
BOOST_CHECK( test_it == target.end() );
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
target.begin(), target.end() );
|
||||
}
|
||||
|
||||
template< class Container1, class Container2 >
|
||||
void test_transform_impl2()
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
Container1 cont1;
|
||||
Container2 cont2;
|
||||
|
||||
test_transform_impl2(cont1, cont2);
|
||||
|
||||
cont1 += 1;
|
||||
cont2 += 2;
|
||||
test_transform_impl2(cont1, cont2);
|
||||
|
||||
cont1 += 2,3,4,5,6,7;
|
||||
cont2 += 4,6,8,10,12,14;
|
||||
test_transform_impl2(cont1, cont2);
|
||||
}
|
||||
|
||||
void test_transform()
|
||||
{
|
||||
test_transform_impl1< std::vector<int> >();
|
||||
test_transform_impl1< std::list<int> >();
|
||||
test_transform_impl1< std::set<int> >();
|
||||
test_transform_impl1< std::multiset<int> >();
|
||||
|
||||
test_transform_impl2< std::vector<int>, std::list<int> >();
|
||||
test_transform_impl2< std::list<int>, std::vector<int> >();
|
||||
test_transform_impl2< std::set<int>, std::set<int> >();
|
||||
test_transform_impl2< std::multiset<int>, std::list<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.transform" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_transform ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/unique.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// test the 'unique' algorithm without a predicate
|
||||
class unique_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::unique<return_type>(cont);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end());
|
||||
}
|
||||
};
|
||||
|
||||
// test the 'unique' algorithm with a predicate
|
||||
template<class Pred>
|
||||
class unique_pred_test_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
// There isn't an iterator return version of boost::unique, so just
|
||||
// perform the standard algorithm
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
|
||||
Pred pred() const { return Pred(); }
|
||||
|
||||
template< range_return_value return_type >
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::unique<return_type>(cont, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::unique(cont.begin(), cont.end(), Pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container, class TestPolicy, class Pred>
|
||||
void test_unique_impl(TestPolicy policy, Pred pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
Container cont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1;
|
||||
|
||||
std::vector<value_t> temp(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
cont.clear();
|
||||
cont += 1,2,2,2,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(cont.begin(), cont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
cont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_unique_impl()
|
||||
{
|
||||
test_unique_impl<Container>(
|
||||
unique_test_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_unique_impl<Container>(
|
||||
unique_pred_test_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
|
||||
void test_unique()
|
||||
{
|
||||
test_unique_impl< std::vector<int> >();
|
||||
test_unique_impl< std::list<int> >();
|
||||
test_unique_impl< std::deque<int> >();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_unique ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#include <boost/range/algorithm/upper_bound.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include "../test_driver/range_return_test_driver.hpp"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <numeric>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
class upper_bound_policy
|
||||
{
|
||||
public:
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::upper_bound(cont, 5);
|
||||
}
|
||||
|
||||
template<range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template<class Container, class Policy>
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
|
||||
operator()(Policy&, Container& cont)
|
||||
{
|
||||
return boost::upper_bound<result_type>(cont, 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(cont.begin(), cont.end(), 5);
|
||||
}
|
||||
};
|
||||
|
||||
template< class BinaryPredicate >
|
||||
struct upper_bound_pred_policy
|
||||
{
|
||||
template< class Container >
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
test_iter(Container& cont)
|
||||
{
|
||||
return boost::upper_bound(cont, 5, BinaryPredicate());
|
||||
}
|
||||
|
||||
template< range_return_value result_type>
|
||||
struct test_range
|
||||
{
|
||||
template< class Container, class Policy >
|
||||
BOOST_DEDUCED_TYPENAME range_return<Container,result_type>::type
|
||||
operator()(Policy& policy, Container& cont)
|
||||
{
|
||||
return boost::upper_bound<result_type>(
|
||||
cont, 5, policy.pred());
|
||||
}
|
||||
};
|
||||
|
||||
template<class Container>
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
reference(Container& cont)
|
||||
{
|
||||
return std::upper_bound(
|
||||
cont.begin(), cont.end(), 5, BinaryPredicate());
|
||||
}
|
||||
|
||||
BinaryPredicate& pred() { return m_pred; }
|
||||
|
||||
private:
|
||||
BinaryPredicate m_pred;
|
||||
};
|
||||
|
||||
template<class Container,
|
||||
class TestPolicy,
|
||||
class BinaryPredicate>
|
||||
void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred)
|
||||
{
|
||||
using namespace boost::assign;
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME remove_const<Container>::type container_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
|
||||
|
||||
range_test::range_return_test_driver test_driver;
|
||||
|
||||
container_t mcont;
|
||||
Container& cont = mcont;
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1;
|
||||
|
||||
std::vector<value_t> temp(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
|
||||
mcont.clear();
|
||||
mcont += 1,2,3,4,5,6,7,8,9;
|
||||
|
||||
temp.assign(mcont.begin(), mcont.end());
|
||||
std::sort(temp.begin(), temp.end(), pred);
|
||||
mcont.assign(temp.begin(), temp.end());
|
||||
|
||||
test_driver(cont, policy);
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void test_upper_bound_impl()
|
||||
{
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_policy(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::less<int> >(),
|
||||
std::less<int>()
|
||||
);
|
||||
|
||||
test_upper_bound_impl<Container>(
|
||||
upper_bound_pred_policy<std::greater<int> >(),
|
||||
std::greater<int>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void test_upper_bound()
|
||||
{
|
||||
test_upper_bound_impl< std::vector<int> >();
|
||||
test_upper_bound_impl< std::list<int> >();
|
||||
test_upper_bound_impl< std::deque<int> >();
|
||||
|
||||
test_upper_bound_impl< const std::vector<int> >();
|
||||
test_upper_bound_impl< const std::list<int> >();
|
||||
test_upper_bound_impl< const std::deque<int> >();
|
||||
}
|
||||
}
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Thorsten Ottosen 2006. 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/combine.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct add
|
||||
{
|
||||
template< class T >
|
||||
int operator()( const T& tuple ) const
|
||||
{
|
||||
return boost::get<0>(tuple) + boost::get<1>(tuple);
|
||||
}
|
||||
};
|
||||
|
||||
template< class CombinedRng >
|
||||
void apply( const CombinedRng& r )
|
||||
{
|
||||
std::vector<int> v;
|
||||
for( typename boost::range_iterator<const CombinedRng>::type
|
||||
i = boost::begin(r),
|
||||
e = boost::end(r);
|
||||
i != e; ++i )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void test_combine()
|
||||
{
|
||||
std::vector<int> v1, v2, v3;
|
||||
v1 = boost::assign::list_of(1)(2)(3)(4);
|
||||
v2 = boost::assign::list_of(1)(2)(3)(4);
|
||||
|
||||
int i1, i2;
|
||||
BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) )
|
||||
{
|
||||
v3.push_back( i1 + i2 );
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( v3.size(), v1.size() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
using boost::unit_test::test_suite;
|
||||
|
||||
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &test_combine ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+1
-1
@@ -42,7 +42,7 @@ template< typename C >
|
||||
class iterator_of
|
||||
{
|
||||
public:
|
||||
typedef range_iterator<Container>::BOOST_NESTED_TEMPLATE pts<C>::type type;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::BOOST_NESTED_TEMPLATE pts<C>::type type;
|
||||
};
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// 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/
|
||||
//
|
||||
// Disable a warning from <xutility> since this noise might
|
||||
// stop us detecting a problem in our code.
|
||||
#include <boost/range/counting_range.hpp>
|
||||
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
template<class Container>
|
||||
void counting_range_test_impl(int first, int last)
|
||||
{
|
||||
Container reference;
|
||||
for (int i = first; i < last; ++i)
|
||||
reference.push_back(i);
|
||||
|
||||
Container test;
|
||||
push_back( test, counting_range(first, last) );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end());
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
void counting_range_test_impl()
|
||||
{
|
||||
counting_range_test_impl<Container>(0, 0);
|
||||
counting_range_test_impl<Container>(-1, -1);
|
||||
counting_range_test_impl<Container>(-1, 0);
|
||||
counting_range_test_impl<Container>(0, 1);
|
||||
counting_range_test_impl<Container>(-100, 100);
|
||||
counting_range_test_impl<Container>(50, 55);
|
||||
}
|
||||
}
|
||||
|
||||
void counting_range_test()
|
||||
{
|
||||
counting_range_test_impl<std::vector<int> >();
|
||||
counting_range_test_impl<std::list<int> >();
|
||||
counting_range_test_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.adaptor.counting_range" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::counting_range_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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/irange.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
// Test an integer range with a step size of 1.
|
||||
template<typename Integer>
|
||||
void test_irange_impl(Integer first, Integer last)
|
||||
{
|
||||
std::vector<Integer> reference;
|
||||
for (Integer i = first; i < last; ++i)
|
||||
{
|
||||
reference.push_back(i);
|
||||
}
|
||||
|
||||
std::vector<Integer> test;
|
||||
boost::push_back(test, boost::irange(first, last));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
// Test an integer range with a runtime specified step size.
|
||||
template<typename Integer>
|
||||
void test_irange_impl(Integer first, Integer last, int step)
|
||||
{
|
||||
BOOST_ASSERT( step != 0 );
|
||||
std::vector<Integer> reference;
|
||||
if (step > 0)
|
||||
{
|
||||
for (Integer i = first; i < last; i += step)
|
||||
reference.push_back(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Integer i = first; i > last; i += step)
|
||||
reference.push_back(i);
|
||||
}
|
||||
|
||||
std::vector<Integer> test;
|
||||
boost::push_back(test, boost::irange(first, last, step));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(),
|
||||
reference.begin(), reference.end() );
|
||||
}
|
||||
|
||||
// Test driver function that for an integer range [first, last)
|
||||
// drives the test implementation through various integer
|
||||
// types.
|
||||
void test_irange(int first, int last)
|
||||
{
|
||||
test_irange_impl<signed char>(first,last);
|
||||
test_irange_impl<unsigned char>(first, last);
|
||||
test_irange_impl<signed short>(first, last);
|
||||
test_irange_impl<unsigned short>(first, last);
|
||||
test_irange_impl<signed int>(first, last);
|
||||
test_irange_impl<unsigned int>(first, last);
|
||||
test_irange_impl<signed long>(first, last);
|
||||
test_irange_impl<unsigned long>(first, last);
|
||||
}
|
||||
|
||||
// Test driver function that for an integer range [first, last)
|
||||
// drives the test implementation through various integer
|
||||
// types step_size items at a time.
|
||||
void test_irange(int first, int last, int step_size)
|
||||
{
|
||||
BOOST_ASSERT( step_size != 0 );
|
||||
BOOST_ASSERT( (last - first) % step_size == 0 );
|
||||
test_irange_impl<signed char>(first, last, step_size);
|
||||
test_irange_impl<unsigned char>(first, last, step_size);
|
||||
test_irange_impl<signed short>(first, last, step_size);
|
||||
test_irange_impl<unsigned short>(first, last, step_size);
|
||||
test_irange_impl<signed int>(first, last, step_size);
|
||||
test_irange_impl<unsigned int>(first, last, step_size);
|
||||
test_irange_impl<signed long>(first, last, step_size);
|
||||
test_irange_impl<unsigned long>(first, last, step_size);
|
||||
}
|
||||
|
||||
// Implementation of the unit test for the integer range
|
||||
// function.
|
||||
// This starts the test drivers to drive a set of integer types
|
||||
// for a combination of range values chosen to exercise a large
|
||||
// number of implementation branches.
|
||||
void irange_unit_test()
|
||||
{
|
||||
// Test the single-step version of irange(first, last)
|
||||
test_irange(0, 0);
|
||||
test_irange(0, 1);
|
||||
test_irange(0, 10);
|
||||
test_irange(1, 1);
|
||||
test_irange(1, 2);
|
||||
test_irange(1, 11);
|
||||
|
||||
// Test the n-step version of irange(first, last, step-size)
|
||||
test_irange(0, 0, 1);
|
||||
test_irange(0, 0, -1);
|
||||
test_irange(0, 10, 1);
|
||||
test_irange(10, 0, -1);
|
||||
test_irange(0, 2, 2);
|
||||
test_irange(2, 0, -2);
|
||||
test_irange(10, 20, 5);
|
||||
test_irange(20, 10, -5);
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
boost::unit_test::test_suite*
|
||||
init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
boost::unit_test::test_suite* test
|
||||
= BOOST_TEST_SUITE( "RangeTestSuite.irange" );
|
||||
|
||||
test->add(BOOST_TEST_CASE( &boost::irange_unit_test ));
|
||||
|
||||
return test;
|
||||
}
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2010. 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/join.hpp>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range/algorithm_ext.hpp>
|
||||
#include <boost/range/irange.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// This function is a helper function that writes integers
|
||||
// of increasing value into a range. It is used to test
|
||||
// that joined ranged may be written to.
|
||||
//
|
||||
// Requires:
|
||||
// - Range uses shallow copy semantics.
|
||||
template< typename Range >
|
||||
void fill_with_ints(Range rng)
|
||||
{
|
||||
typedef typename range_iterator<Range>::type iterator;
|
||||
iterator target = boost::begin(rng);
|
||||
const int count = boost::distance(rng);
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
*target = i;
|
||||
++target;
|
||||
}
|
||||
}
|
||||
|
||||
// The test_join_traversal function is used to provide additional
|
||||
// tests based upon the underlying join iterator traversal.
|
||||
// The join iterator takes care of the appropriate demotion, and
|
||||
// this demotion.
|
||||
|
||||
// test_join_traversal - additional tests for input and forward
|
||||
// traversal iterators. This is of course a no-op.
|
||||
template< typename Range1, typename Range2, typename TraversalTag >
|
||||
void test_join_traversal(Range1& rng1, Range2& rng2, TraversalTag)
|
||||
{
|
||||
}
|
||||
|
||||
// test_join_traversal - additional tests for bidirectional
|
||||
// traversal iterators.
|
||||
template< typename Range1, typename Range2 >
|
||||
void test_join_traversal(Range1& rng1, Range2& rng2, boost::bidirectional_traversal_tag)
|
||||
{
|
||||
typedef typename range_value<Range1>::type value_type;
|
||||
std::vector<value_type> reference(boost::begin(rng1), boost::end(rng1));
|
||||
boost::push_back(reference, rng2);
|
||||
std::reverse(reference.begin(), reference.end());
|
||||
|
||||
std::vector<value_type> test_result;
|
||||
BOOST_REVERSE_FOREACH( value_type x, join(rng1, rng2) )
|
||||
{
|
||||
test_result.push_back(x);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result.begin(), test_result.end() );
|
||||
}
|
||||
|
||||
// Test helper function to implement the additional tests for random
|
||||
// access traversal iterators. This is used by the test_join_traversal
|
||||
// function for random access iterators. The reason that the test
|
||||
// implementation is put into this function is to utilise
|
||||
// template parameter type deduction for the joined range type.
|
||||
template< typename Range1, typename Range2, typename JoinedRange >
|
||||
void test_random_access_join(Range1& rng1, Range2& rng2, JoinedRange joined)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( boost::end(joined) - boost::begin(joined), boost::distance(joined) );
|
||||
BOOST_CHECK( boost::end(joined) <= boost::begin(joined) );
|
||||
BOOST_CHECK( boost::begin(joined) >= boost::end(joined) );
|
||||
if (boost::empty(joined))
|
||||
{
|
||||
BOOST_CHECK(!(boost::begin(joined) < boost::end(joined)));
|
||||
BOOST_CHECK(!(boost::end(joined) > boost::begin(joined)));
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK(boost::begin(joined) < boost::end(joined));
|
||||
BOOST_CHECK(boost::end(joined) < boost::begin(joined));
|
||||
}
|
||||
|
||||
typedef typename boost::range_difference<JoinedRange>::type difference_t;
|
||||
const difference_t count = boost::distance(joined);
|
||||
BOOST_CHECK( boost::begin(joined) + count == boost::end(joined) );
|
||||
BOOST_CHECK( boost::end(joined) - count == boost::begin(joined) );
|
||||
|
||||
typedef typename boost::range_iterator<JoinedRange>::type iterator_t;
|
||||
iterator_t it = boost::begin(joined);
|
||||
it += count;
|
||||
BOOST_CHECK( it == boost::end(joined) );
|
||||
|
||||
it = boost::end(joined);
|
||||
it -= count;
|
||||
BOOST_CHECK( it == boost::begin(joined) );
|
||||
}
|
||||
|
||||
// test_join_traversal function for random access traversal joined
|
||||
// ranges.
|
||||
template< typename Range1, typename Range2 >
|
||||
void test_join_traversal(Range1& rng1, Range2& rng2, boost::random_access_traversal_tag)
|
||||
{
|
||||
test_join_traversal(rng1, rng2, boost::bidirectional_traversal_tag());
|
||||
test_random_access_join(rng1, rng2, join(rng1, rng2));
|
||||
}
|
||||
|
||||
// Test the ability to write values into a joined range. This is
|
||||
// achieved by copying the constant collections, altering them
|
||||
// and then checking the result. Hence this relies upon both
|
||||
// rng1 and rng2 having value copy semantics.
|
||||
template< typename Collection1, typename Collection2 >
|
||||
void test_write_to_joined_range(const Collection1& rng1, const Collection2& rng2)
|
||||
{
|
||||
Collection1 c1(rng1);
|
||||
Collection2 c2(rng2);
|
||||
typedef typename boost::range_value<Collection1>::type value_t;
|
||||
fill_with_ints(boost::join(c1,c2));
|
||||
|
||||
// Ensure that the size of the written range has not been
|
||||
// altered.
|
||||
BOOST_CHECK_EQUAL( boost::distance(c1), boost::distance(rng1) );
|
||||
BOOST_CHECK_EQUAL( boost::distance(c2), boost::distance(rng2) );
|
||||
|
||||
// For each element x, in c1 ensure that it has been written to
|
||||
// with incrementing integers
|
||||
int x = 0;
|
||||
typedef typename range_iterator<Collection1>::type iterator1;
|
||||
iterator1 it1 = boost::begin(c1);
|
||||
for (; it1 != boost::end(c1); ++it1)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( x, *it1 );
|
||||
++x;
|
||||
}
|
||||
|
||||
// For each element y, in c2 ensure that it has been written to
|
||||
// with incrementing integers
|
||||
typedef typename range_iterator<Collection2>::type iterator2;
|
||||
iterator2 it2 = boost::begin(c2);
|
||||
for (; it2 != boost::end(c2); ++it2)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( x, *it2 );
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform a unit test of a Boost.Range join() comparing
|
||||
// it to a reference that is populated by appending
|
||||
// elements from both source ranges into a vector.
|
||||
template< typename Collection1, typename Collection2 >
|
||||
void test_join_impl(Collection1& rng1, Collection2& rng2)
|
||||
{
|
||||
typedef typename range_value<Collection1>::type value_type;
|
||||
std::vector<value_type> reference(boost::begin(rng1), boost::end(rng1));
|
||||
boost::push_back(reference, rng2);
|
||||
|
||||
std::vector<value_type> test_result;
|
||||
boost::push_back(test_result, join(rng1, rng2));
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test_result.begin(), test_result.end() );
|
||||
|
||||
typedef boost::range_detail::join_iterator<
|
||||
typename boost::range_iterator<Collection1>::type,
|
||||
typename boost::range_iterator<Collection2>::type
|
||||
> join_iterator_t;
|
||||
|
||||
typedef boost::iterator_traversal< join_iterator_t > tag_t;
|
||||
|
||||
test_join_traversal(rng1, rng2, tag_t());
|
||||
|
||||
test_write_to_joined_range(rng1, rng2);
|
||||
}
|
||||
|
||||
// Make a collection filling it with items from the source
|
||||
// range. This is used to build collections of various
|
||||
// sizes populated with various values designed to optimize
|
||||
// the code coverage exercised by the core test function
|
||||
// test_join_impl.
|
||||
template<typename Collection, typename Range>
|
||||
boost::shared_ptr<Collection> makeCollection(const Range& source)
|
||||
{
|
||||
boost::shared_ptr<Collection> c(new Collection);
|
||||
c->insert(c->end(), boost::begin(source), boost::end(source));
|
||||
return c;
|
||||
}
|
||||
|
||||
// This templatised version of the test_join_impl function
|
||||
// generates and populates collections which are later
|
||||
// used as input to the core test function.
|
||||
// The caller of this function explicitly provides the
|
||||
// template parameters. This supports the generation
|
||||
// of testing a large combination of range types to be
|
||||
// joined. It is of particular importance to remember
|
||||
// to combine a random_access range with a bidirectional
|
||||
// range to determine that the correct demotion of
|
||||
// types occurs in the join_iterator.
|
||||
template< typename Collection1, typename Collection2 >
|
||||
void test_join_impl()
|
||||
{
|
||||
typedef boost::shared_ptr<Collection1> collection1_ptr;
|
||||
typedef boost::shared_ptr<Collection2> collection2_ptr;
|
||||
typedef boost::shared_ptr<const Collection1> collection1_cptr;
|
||||
typedef boost::shared_ptr<const Collection2> collection2_cptr;
|
||||
std::vector< collection1_cptr > left_containers;
|
||||
std::vector< collection2_cptr > right_containers;
|
||||
|
||||
left_containers.push_back(collection1_ptr(new Collection1));
|
||||
left_containers.push_back(makeCollection<Collection1>(irange(0,1)));
|
||||
left_containers.push_back(makeCollection<Collection1>(irange(0,100)));
|
||||
|
||||
right_containers.push_back(collection2_ptr(new Collection2));
|
||||
right_containers.push_back(makeCollection<Collection2>(irange(0,1)));
|
||||
right_containers.push_back(makeCollection<Collection2>(irange(0,100)));
|
||||
|
||||
BOOST_FOREACH( collection1_cptr left_container, left_containers )
|
||||
{
|
||||
BOOST_FOREACH( collection2_cptr right_container, right_containers )
|
||||
{
|
||||
test_join_impl(*left_container, *right_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// entry-point into the unit test for the join() function
|
||||
// this tests a representative sample of combinations of
|
||||
// source range type.
|
||||
void join_test()
|
||||
{
|
||||
test_join_impl< std::vector<int>, std::vector<int> >();
|
||||
test_join_impl< std::list<int>, std::list<int> >();
|
||||
test_join_impl< std::deque<int>, std::deque<int> >();
|
||||
|
||||
test_join_impl< std::vector<int>, std::list<int> >();
|
||||
test_join_impl< std::list<int>, std::vector<int> >();
|
||||
test_join_impl< std::vector<int>, std::deque<int> >();
|
||||
test_join_impl< std::deque<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.adaptor.joined" );
|
||||
|
||||
test->add( BOOST_TEST_CASE( &boost::join_test ) );
|
||||
|
||||
return test;
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_TEST_DRIVER_RANGE_RETURN_TEST_DRIVER_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_TEST_DRIVER_RANGE_RETURN_TEST_DRIVER_HPP_INCLUDED
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test
|
||||
{
|
||||
// check the results of an algorithm that returns
|
||||
// a range_return.
|
||||
//
|
||||
// This version is the general version. It should never be called.
|
||||
// All calls should invoke specialized implementations.
|
||||
template< range_return_value return_type >
|
||||
struct check_results
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
Iterator test_it,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_ASSERT( false );
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a 'found' iterator
|
||||
template< >
|
||||
struct check_results<return_found>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
Iterator test_it,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a 'next(found)' iterator
|
||||
template< >
|
||||
struct check_results<return_next>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
Iterator test_it,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
if (reference_it == reference.end())
|
||||
{
|
||||
BOOST_CHECK( test_it == test.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance(test.begin(), test_it),
|
||||
std::distance(reference.begin(), reference_it) + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a 'prior(found)' iterator
|
||||
template< >
|
||||
struct check_results<return_prior>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
Iterator test_it,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
if (reference_it == reference.begin())
|
||||
{
|
||||
BOOST_CHECK( test_it == test.begin() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance(test.begin(), test_it) + 1,
|
||||
std::distance(reference.begin(), reference_it));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[begin, found)' range
|
||||
template< >
|
||||
struct check_results<return_begin_found>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_rng.begin() == test.begin() );
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference_it,
|
||||
boost::begin(test_rng), boost::end(test_rng)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[begin, next(found))' range
|
||||
template< >
|
||||
struct check_results<return_begin_next>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_rng.begin() == test.begin() );
|
||||
|
||||
if (reference_it == reference.end())
|
||||
{
|
||||
BOOST_CHECK( test_rng.end() == test.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), boost::next(reference_it),
|
||||
test_rng.begin(), test_rng.end());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[begin, prior(found))' range
|
||||
template< >
|
||||
struct check_results<return_begin_prior>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
BOOST_CHECK( test_rng.begin() == test.begin() );
|
||||
|
||||
if (reference_it == reference.begin())
|
||||
{
|
||||
BOOST_CHECK( boost::end(test_rng) == test.begin() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL( std::distance(boost::begin(test_rng), boost::end(test_rng)) + 1,
|
||||
std::distance(reference.begin(), reference_it) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[found, end)' range
|
||||
template< >
|
||||
struct check_results<return_found_end>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
|
||||
test.begin(), test.end() );
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
std::distance(test.begin(), boost::begin(test_rng)),
|
||||
std::distance(reference.begin(), reference_it));
|
||||
|
||||
BOOST_CHECK( boost::end(test_rng) == test.end() );
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[next(found), end)' range
|
||||
template< >
|
||||
struct check_results<return_next_end>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_rng.end() == test.end() );
|
||||
|
||||
if (reference_it == reference.end())
|
||||
{
|
||||
BOOST_CHECK( test_rng.begin() == test.end() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
boost::next(reference_it), reference.end(),
|
||||
test_rng.begin(), test_rng.end()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a 'prior(found), end)' range
|
||||
template< >
|
||||
struct check_results<return_prior_end>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_rng.end() == test.end() );
|
||||
|
||||
if (reference_it == reference.begin())
|
||||
{
|
||||
BOOST_CHECK( test_rng.begin() == test.begin() );
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
boost::prior(reference_it), reference.end(),
|
||||
test_rng.begin(), test_rng.end()
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// check the results of an algorithm that returns
|
||||
// a '[begin, end)' range
|
||||
template< >
|
||||
struct check_results<return_begin_end>
|
||||
{
|
||||
template< class Container, class Iterator >
|
||||
static void check(
|
||||
Container& test,
|
||||
Container& reference,
|
||||
iterator_range<Iterator> test_rng,
|
||||
Iterator reference_it
|
||||
)
|
||||
{
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(
|
||||
reference.begin(), reference.end(),
|
||||
test.begin(), test.end()
|
||||
);
|
||||
|
||||
BOOST_CHECK( test_rng.begin() == test.begin() );
|
||||
BOOST_CHECK( test_rng.end() == test.end() );
|
||||
}
|
||||
};
|
||||
|
||||
// A test driver to exercise a test through all of the range_return
|
||||
// combinations.
|
||||
//
|
||||
// The test driver also contains the code required to check the
|
||||
// return value correctness.
|
||||
//
|
||||
// The TestPolicy needs to implement two functions:
|
||||
//
|
||||
// - perform the boost range version of the algorithm that returns
|
||||
// a range_return<Container,return_type>::type
|
||||
// template<range_return_value return_type, class Container>
|
||||
// BOOST_DEDUCED_TYPENAME range_return<Container,return_type>::type
|
||||
// test(Container& cont);
|
||||
//
|
||||
// - perform the reference std version of the algorithm that
|
||||
// returns the standard iterator result
|
||||
// template<class Container>
|
||||
// BOOST_DEDUCED_TYPENAME range_iterator<Container>::type
|
||||
// reference(Container& cont);
|
||||
class range_return_test_driver
|
||||
{
|
||||
public:
|
||||
template< class Container,
|
||||
class TestPolicy >
|
||||
void operator()(Container& cont, TestPolicy policy)
|
||||
{
|
||||
test_range_iter (cont, policy);
|
||||
test_range<return_found,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_next,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_prior,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_begin_found,Container,TestPolicy>()(cont, policy);
|
||||
test_range<return_begin_next,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_begin_prior,Container,TestPolicy>()(cont, policy);
|
||||
test_range<return_found_end,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_next_end,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_prior_end,Container,TestPolicy> ()(cont, policy);
|
||||
test_range<return_begin_end,Container,TestPolicy> ()(cont, policy);
|
||||
}
|
||||
|
||||
private:
|
||||
template< class Container, class TestPolicy >
|
||||
void test_range_iter(
|
||||
Container& cont,
|
||||
TestPolicy policy
|
||||
)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
|
||||
Container reference(cont);
|
||||
Container test(cont);
|
||||
|
||||
iterator_t range_result = policy.test_iter(test);
|
||||
iterator_t reference_it = policy.reference(reference);
|
||||
|
||||
check_results<return_found>::check(test, reference,
|
||||
range_result, reference_it);
|
||||
}
|
||||
|
||||
template< range_return_value result_type, class Container, class TestPolicy >
|
||||
struct test_range
|
||||
{
|
||||
void operator()(Container& cont, TestPolicy policy)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME range_iterator<Container>::type iterator_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME range_return<Container, result_type>::type range_return_t;
|
||||
typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range<result_type> test_range_t;
|
||||
|
||||
Container reference(cont);
|
||||
Container test_cont(cont);
|
||||
|
||||
range_return_t range_result = test_range_t()(policy, test_cont);
|
||||
iterator_t reference_it = policy.reference(reference);
|
||||
|
||||
check_results<result_type>::check(test_cont, reference,
|
||||
range_result, reference_it);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED
|
||||
|
||||
#include "counted_function.hpp"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
template< class Collection >
|
||||
class check_equal_fn : private counted_function
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Collection::const_iterator iter_t;
|
||||
public:
|
||||
explicit check_equal_fn( const Collection& c )
|
||||
: m_it(boost::begin(c)), m_last(boost::end(c)) {}
|
||||
|
||||
using counted_function::invocation_count;
|
||||
|
||||
void operator()(int x) const
|
||||
{
|
||||
invoked();
|
||||
BOOST_CHECK( m_it != m_last );
|
||||
if (m_it != m_last)
|
||||
{
|
||||
BOOST_CHECK_EQUAL( *m_it, x );
|
||||
++m_it;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable iter_t m_it;
|
||||
iter_t m_last;
|
||||
};
|
||||
|
||||
} // namespace range_test_function
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
|
||||
class counted_function
|
||||
{
|
||||
public:
|
||||
counted_function() : m_count(0u) {}
|
||||
|
||||
void invoked() const
|
||||
{
|
||||
++m_count;
|
||||
}
|
||||
|
||||
// Return the number of times that this function object
|
||||
// has been invoked.
|
||||
unsigned int invocation_count() const { return m_count; }
|
||||
|
||||
private:
|
||||
mutable unsigned int m_count;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_TEST_FUNCTION_EQUAL_TO_X_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_TEST_FUNCTION_EQUAL_TO_X_HPP_INCLUDED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
template<class Arg>
|
||||
struct equal_to_x
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef Arg argument_type;
|
||||
|
||||
explicit equal_to_x(Arg x) : m_x(x) {}
|
||||
bool operator()(Arg x) const { return x == m_x; }
|
||||
|
||||
private:
|
||||
Arg m_x;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_TEST_FUNCTION_FALSE_PREDICATE_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_TEST_FUNCTION_FALSE_PREDICATE_HPP_INCLUDED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
struct false_predicate
|
||||
{
|
||||
typedef bool result_type;
|
||||
|
||||
bool operator()() const { return false; }
|
||||
template<class Arg> bool operator()(Arg) const { return false; }
|
||||
template<class Arg1, class Arg2> bool operator()(Arg1,Arg2) const { return false; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_FUNCTION_GREATER_THAN_X_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_FUNCTION_GREATER_THAN_X_HPP_INCLUDED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
template< class Number >
|
||||
struct greater_than_x
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef Number argument_type;
|
||||
|
||||
explicit greater_than_x(Number x) : m_x(x) {}
|
||||
bool operator()(Number x) const { return x > m_x; }
|
||||
private:
|
||||
Number m_x;
|
||||
};
|
||||
} // namespace range_test_function
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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/
|
||||
//
|
||||
#ifndef BOOST_RANGE_TEST_TEST_FUNCTION_MULTIPLY_BY_X_HPP_INCLUDED
|
||||
#define BOOST_RANGE_TEST_TEST_FUNCTION_MULTIPLY_BY_X_HPP_INCLUDED
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_test_function
|
||||
{
|
||||
template< class Arg >
|
||||
struct multiply_by_x
|
||||
{
|
||||
typedef Arg result_type;
|
||||
typedef Arg argument_type;
|
||||
|
||||
explicit multiply_by_x(Arg x) : m_x(x) {}
|
||||
Arg operator()(Arg x) const { return x * m_x; }
|
||||
private:
|
||||
Arg m_x;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
||||
Reference in New Issue
Block a user