]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/set_union.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_test / set_union.cpp
1 // Copyright Neil Groves 2009. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 //
6 //
7 // For more information, see http://www.boost.org/libs/range/
8 //
9 #include <boost/range/algorithm/set_algorithm.hpp>
10
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/assign.hpp>
15 #include <boost/bind.hpp>
16 #include <algorithm>
17 #include <functional>
18 #include <list>
19 #include <numeric>
20 #include <deque>
21 #include <vector>
22
23 namespace boost
24 {
25 namespace
26 {
27 template<class Container1, class Iterator, class Container2>
28 void check_result(
29 Container1& reference,
30 Iterator reference_result,
31 Container2& test_cont,
32 Iterator test_result
33 )
34 {
35 BOOST_CHECK_EQUAL(
36 std::distance<Iterator>(reference.begin(), reference_result),
37 std::distance<Iterator>(test_cont.begin(), test_result)
38 );
39
40 BOOST_CHECK_EQUAL_COLLECTIONS(
41 reference.begin(), reference.end(),
42 test_cont.begin(), test_cont.end()
43 );
44 }
45
46 template<class Container1, class Container2>
47 void test(Container1& cont1, Container2& cont2)
48 {
49 typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
50 typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
51
52 std::vector<value_t> reference(cont1.size() + cont2.size());
53 std::vector<value_t> test_cont(reference);
54
55 iterator_t reference_result
56 = std::set_union(cont1.begin(), cont1.end(),
57 cont2.begin(), cont2.end(),
58 reference.begin());
59
60 iterator_t test_result
61 = boost::set_union(cont1, cont2, test_cont.begin());
62
63 check_result(reference, reference_result,
64 test_cont, test_result);
65
66 test_result = boost::set_union(boost::make_iterator_range(cont1),
67 cont2, test_cont.begin());
68
69 check_result(reference, reference_result,
70 test_cont, test_result);
71
72 test_result = boost::set_union(cont1,
73 boost::make_iterator_range(cont2),
74 test_cont.begin());
75
76 check_result(reference, reference_result,
77 test_cont, test_result);
78
79 test_result = boost::set_union(boost::make_iterator_range(cont1),
80 boost::make_iterator_range(cont2),
81 test_cont.begin());
82
83 check_result(reference, reference_result,
84 test_cont, test_result);
85 }
86
87 template<class Container, class BinaryPredicate>
88 void sort_container(Container& cont, BinaryPredicate pred)
89 {
90 typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
91
92 std::vector<value_t> temp(cont.begin(), cont.end());
93 std::sort(temp.begin(), temp.end(), pred);
94 cont.assign(temp.begin(), temp.end());
95 }
96
97 template<class Container1,
98 class Container2,
99 class BinaryPredicate>
100 void test_pred(Container1 cont1, Container2 cont2,
101 BinaryPredicate pred)
102 {
103 typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t;
104 typedef BOOST_DEDUCED_TYPENAME std::vector<value_t>::iterator iterator_t;
105
106 sort_container(cont1, pred);
107 sort_container(cont2, pred);
108
109 std::vector<value_t> reference(cont1.size() + cont2.size());
110 std::vector<value_t> test_cont(reference);
111
112 iterator_t reference_result
113 = std::set_union(cont1.begin(), cont1.end(),
114 cont2.begin(), cont2.end(),
115 reference.begin(),
116 pred);
117
118 iterator_t test_result
119 = boost::set_union(cont1, cont2, test_cont.begin(), pred);
120
121 check_result(reference, reference_result,
122 test_cont, test_result);
123
124 test_result = boost::set_union(boost::make_iterator_range(cont1),
125 cont2, test_cont.begin(), pred);
126
127 check_result(reference, reference_result,
128 test_cont, test_result);
129
130 test_result = boost::set_union(cont1,
131 boost::make_iterator_range(cont2),
132 test_cont.begin(), pred);
133
134 check_result(reference, reference_result,
135 test_cont, test_result);
136
137 test_result = boost::set_union(boost::make_iterator_range(cont1),
138 boost::make_iterator_range(cont2),
139 test_cont.begin(), pred);
140
141 check_result(reference, reference_result,
142 test_cont, test_result);
143 }
144
145 template<class Container1, class Container2>
146 void test_set_union_impl(
147 Container1& cont1,
148 Container2& cont2
149 )
150 {
151 test(cont1, cont2);
152 test_pred(cont1, cont2, std::less<int>());
153 test_pred(cont1, cont2, std::greater<int>());
154 }
155
156 template<class Container1, class Container2>
157 void test_set_union_impl()
158 {
159 using namespace boost::assign;
160
161 Container1 cont1;
162 Container2 cont2;
163
164 test_set_union_impl(cont1, cont2);
165
166 cont1.clear();
167 cont2.clear();
168 cont1 += 1;
169 test_set_union_impl(cont1, cont2);
170
171 cont1.clear();
172 cont2.clear();
173 cont2 += 1;
174 test_set_union_impl(cont1, cont2);
175
176 cont1.clear();
177 cont2.clear();
178 cont1 += 1,2,3,4,5,6,7,8,9;
179 cont2 += 2,3,4;
180 test_set_union_impl(cont1, cont2);
181
182 cont1.clear();
183 cont2.clear();
184 cont1 += 2,3,4;
185 cont2 += 1,2,3,4,5,6,7,8,9;
186 test_set_union_impl(cont1, cont2);
187 }
188
189 void test_set_union()
190 {
191 test_set_union_impl< std::vector<int>, std::vector<int> >();
192 test_set_union_impl< std::list<int>, std::list<int> >();
193 test_set_union_impl< std::deque<int>, std::deque<int> >();
194 test_set_union_impl< std::vector<int>, std::list<int> >();
195 test_set_union_impl< std::list<int>, std::vector<int> >();
196 }
197 }
198 }
199
200
201 boost::unit_test::test_suite*
202 init_unit_test_suite(int argc, char* argv[])
203 {
204 boost::unit_test::test_suite* test
205 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_union" );
206
207 test->add( BOOST_TEST_CASE( &boost::test_set_union ) );
208
209 return test;
210 }