2 Copyright (c) Marshall Clow 2011-2012.
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 For more information, see http://www.boost.org
12 #include <boost/config.hpp>
13 #include <boost/algorithm/cxx11/partition_copy.hpp>
15 #define BOOST_TEST_MAIN
16 #include <boost/test/unit_test.hpp>
18 #include <boost/algorithm/cxx11/all_of.hpp>
19 #include <boost/algorithm/cxx11/none_of.hpp>
24 namespace ba = boost::algorithm;
25 // namespace ba = boost;
27 template <typename Container, typename Predicate>
28 void test_sequence ( const Container &c, Predicate comp ) {
29 std::vector<typename Container::value_type> v1, v2;
31 v1.clear (); v2.clear ();
32 ba::partition_copy ( c.begin (), c.end (),
33 std::back_inserter (v1), std::back_inserter (v2), comp );
34 // std::cout << "Sizes(1): " << c.size () << " -> { " << v1.size () << ", " << v2.size () << " }" << std::endl;
35 BOOST_CHECK ( v1.size () + v2.size () == c.size ());
36 BOOST_CHECK ( ba::all_of ( v1.begin (), v1.end (), comp ));
37 BOOST_CHECK ( ba::none_of ( v2.begin (), v2.end (), comp ));
39 v1.clear (); v2.clear ();
40 ba::partition_copy ( c, std::back_inserter (v1), std::back_inserter ( v2 ), comp );
41 // std::cout << "Sizes(2): " << c.size () << " -> { " << v1.size () << ", " << v2.size () << " }" << std::endl;
42 BOOST_CHECK ( v1.size () + v2.size () == c.size ());
43 BOOST_CHECK ( ba::all_of ( v1, comp ));
44 BOOST_CHECK ( ba::none_of ( v2, comp ));
50 less_than ( T foo ) : val ( foo ) {}
51 less_than ( const less_than &rhs ) : val ( rhs.val ) {}
53 bool operator () ( const T &v ) const { return v < val; }
56 less_than operator = ( const less_than &rhs );
60 bool is_even ( int v ) { return v % 2 == 0; }
62 void test_sequence1 () {
66 for ( int i = 5; i < 15; ++i )
68 test_sequence ( v, less_than<int>(3)); // no elements
69 test_sequence ( v, less_than<int>(6)); // only the first element
70 test_sequence ( v, less_than<int>(10));
71 test_sequence ( v, less_than<int>(99)); // all elements satisfy
73 // With bidirectional iterators.
75 for ( int i = 5; i < 16; ++i )
77 test_sequence ( l, less_than<int>(3)); // no elements
78 test_sequence ( l, less_than<int>(6)); // only the first element
79 test_sequence ( l, less_than<int>(10));
80 test_sequence ( l, less_than<int>(99)); // all elements satisfy
85 BOOST_AUTO_TEST_CASE( test_main )