]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/unique_copy.cpp
3 // Copyright Neil Groves 2009. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/range/algorithm/unique_copy.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
26 template<class OutputIterator
, class Value
>
27 void test_append(OutputIterator target
, Value value
)
32 template<class Container
>
33 void test_unique_copy_impl(Container
& c
)
35 typedef BOOST_DEDUCED_TYPENAME
boost::range_value
<Container
>::type value_type
;
36 std::vector
<value_type
> reference
;
37 std::vector
<value_type
> test
;
40 std::unique_copy(c
.begin(), c
.end(), std::back_inserter(reference
)),
45 boost::unique_copy(c
, std::back_inserter(test
)),
49 BOOST_CHECK_EQUAL_COLLECTIONS(reference
.begin(), reference
.end(),
50 test
.begin(), test
.end());
55 boost::unique_copy(boost::make_iterator_range(c
),
56 std::back_inserter(test
)),
60 BOOST_CHECK_EQUAL_COLLECTIONS(reference
.begin(), reference
.end(),
61 test
.begin(), test
.end());
64 template<class Container
, class Pred
>
65 void test_unique_copy_impl(Container
& c
, Pred pred
)
67 typedef BOOST_DEDUCED_TYPENAME
boost::range_value
<Container
>::type value_type
;
68 std::vector
<value_type
> reference
;
69 std::vector
<value_type
> test
;
72 std::unique_copy(c
.begin(), c
.end(), std::back_inserter(reference
), pred
),
77 boost::unique_copy(c
, std::back_inserter(test
), pred
),
81 BOOST_CHECK_EQUAL_COLLECTIONS(reference
.begin(), reference
.end(),
82 test
.begin(), test
.end());
87 boost::unique_copy(boost::make_iterator_range(c
),
88 std::back_inserter(test
), pred
),
92 BOOST_CHECK_EQUAL_COLLECTIONS(reference
.begin(), reference
.end(),
93 test
.begin(), test
.end());
96 template<class Container
, class Pred
>
97 void test_unique_copy_driver(Pred pred
)
99 using namespace boost::assign
;
101 typedef BOOST_DEDUCED_TYPENAME
Container::value_type value_t
;
105 test_unique_copy_impl(cont
);
106 test_unique_copy_impl(cont
, pred
);
111 std::vector
<value_t
> temp(cont
.begin(), cont
.end());
112 std::sort(temp
.begin(), temp
.end());
113 cont
.assign(temp
.begin(), temp
.end());
114 test_unique_copy_impl(cont
);
116 std::sort(temp
.begin(), temp
.end(), pred
);
117 cont
.assign(temp
.begin(), temp
.end());
118 test_unique_copy_impl(cont
, pred
);
121 cont
+= 1,2,2,2,2,3,4,5,6,7,8,9;
123 temp
.assign(cont
.begin(), cont
.end());
124 std::sort(temp
.begin(), temp
.end());
125 cont
.assign(temp
.begin(), temp
.end());
126 test_unique_copy_impl(cont
);
128 std::sort(temp
.begin(), temp
.end(), pred
);
129 cont
.assign(temp
.begin(), temp
.end());
130 test_unique_copy_impl(cont
, pred
);
133 template<class Container
>
134 void test_unique_copy_impl()
136 test_unique_copy_driver
<Container
>(std::less
<int>());
137 test_unique_copy_driver
<Container
>(std::greater
<int>());
140 void test_unique_copy()
142 test_unique_copy_impl
< std::vector
<int> >();
143 test_unique_copy_impl
< std::list
<int> >();
144 test_unique_copy_impl
< std::deque
<int> >();
148 boost::unit_test::test_suite
*
149 init_unit_test_suite(int argc
, char* argv
[])
151 boost::unit_test::test_suite
* test
152 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique_copy" );
154 test
->add( BOOST_TEST_CASE( &test_unique_copy
) );