• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2005-2007 Dan Marsden
3     Copyright (c) 2005-2007 Joel de Guzman
4 
5     Distributed under the Boost Software License, Version 1.0. (See accompanying
6     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 
9 #include <functional>
10 #include <boost/phoenix/core.hpp>
11 #include <boost/phoenix/stl/algorithm/transformation.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 
14 #include <list>
15 
16 namespace
17 {
nth_element_test()18     void nth_element_test()
19     {
20         using boost::phoenix::nth_element;
21         using boost::phoenix::arg_names::arg1;
22         int array[] = {5,1,4,3,2};
23         nth_element(arg1, array + 2)(array);
24         BOOST_TEST(array[0] < 3);
25         BOOST_TEST(array[1] < 3);
26         BOOST_TEST(array[2] == 3);
27         BOOST_TEST(array[3] > 3);
28         BOOST_TEST(array[4] > 3);
29 
30         boost::phoenix::nth_element(arg1, array + 2, std::greater<int>())(array);
31         BOOST_TEST(array[0] > 3);
32         BOOST_TEST(array[1] > 3);
33         BOOST_TEST(array[2] == 3);
34         BOOST_TEST(array[3] < 3);
35         BOOST_TEST(array[4] < 3);
36 
37         return;
38     }
39 
merge_test()40     void merge_test()
41     {
42         using boost::phoenix::merge;
43         using boost::phoenix::arg_names::arg1;
44         using boost::phoenix::arg_names::arg2;
45         using boost::phoenix::arg_names::arg3;
46         int array[] = {1,2,3};
47         int array2[] = {2,3,4};
48         int output[6];
49 
50         BOOST_TEST(merge(arg1, arg2, arg3)(array, array2, output) == output + 6);
51         int expected_result[] = {1,2,2,3,3,4};
52         BOOST_TEST(std::equal(output, output + 6, expected_result));
53 
54         int array3[] = {5,4,3};
55         int array4[] = {3,2,1};
56         int output2[6];
57         BOOST_TEST(boost::phoenix::merge(arg1, arg2, arg3, std::greater<int>())(array3, array4, output2) ==
58                    output2 + 6);
59         int expected_result2[] = {5,4,3,3,2,1};
60         BOOST_TEST(std::equal(output2, output2 + 6, expected_result2));
61         return;
62     }
63 
inplace_merge_test()64     void inplace_merge_test()
65     {
66         using boost::phoenix::inplace_merge;
67         using boost::phoenix::arg_names::arg1;
68         int array[] = {1,2,3,2,3,4};
69         inplace_merge(arg1, array + 3)(array);
70         int expected_result[] = {1,2,2,3,3,4};
71         BOOST_TEST(std::equal(array, array + 6, expected_result));
72 
73         int array2[] = {5,4,3,4,3,2};
74         boost::phoenix::inplace_merge(arg1, array2 + 3, std::greater<int>())(array2);
75         int expected_result2[] = {5,4,4,3,3,2};
76         BOOST_TEST(std::equal(array2, array2 + 6, expected_result2));
77         return;
78     }
79 
set_union_test()80     void set_union_test()
81     {
82         using boost::phoenix::set_union;
83         using boost::phoenix::arg_names::arg1;
84         using boost::phoenix::arg_names::arg2;
85         using boost::phoenix::arg_names::arg3;
86         int array[] = {1,2,3};
87         int array2[] = {2,3,4};
88         int output[4];
89         BOOST_TEST(set_union(arg1, arg2, arg3)(array, array2, output) == output + 4);
90         int expected_result[] = {1,2,3,4};
91         BOOST_TEST(std::equal(output, output + 4, expected_result));
92 
93         int array3[] = {3,2,1};
94         int array4[] = {4,3,2};
95         int output2[4];
96         BOOST_TEST(boost::phoenix::set_union(arg1, arg2, arg3, std::greater<int>())
97                    (array3, array4, output2) ==
98                    output2 + 4);
99         int expected_result2[] = {4,3,2,1};
100         BOOST_TEST(std::equal(output2, output2 + 4, expected_result2));
101         return;
102     }
103 
set_intersection_test()104     void set_intersection_test()
105     {
106         using boost::phoenix::set_intersection;
107         using boost::phoenix::arg_names::arg1;
108         using boost::phoenix::arg_names::arg2;
109         using boost::phoenix::arg_names::arg3;
110         int array[] = {1,2,3};
111         int array2[] = {2,3,4};
112         int output[2];
113         BOOST_TEST(set_intersection(arg1, arg2, arg3)(array, array2, output) == output + 2);
114         int expected_result[] = {2,3};
115         BOOST_TEST(std::equal(output, output + 2, expected_result));
116 
117         int array3[] = {3,2,1};
118         int array4[] = {4,3,2};
119         int output2[2];
120         BOOST_TEST(boost::phoenix::set_intersection(arg1, arg2, arg3, std::greater<int>())
121                    (array3, array4, output2) ==
122                    output2 + 2);
123         int expected_result2[] = {3,2};
124         BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
125         return;
126     }
127 
set_difference_test()128     void set_difference_test()
129     {
130         using boost::phoenix::set_difference;
131         using boost::phoenix::arg_names::arg1;
132         using boost::phoenix::arg_names::arg2;
133         using boost::phoenix::arg_names::arg3;
134         int array[] = {1,2,3};
135         int array2[] = {2,3,4};
136         int output[1];
137         BOOST_TEST(set_difference(arg1, arg2, arg3)(array, array2, output) == output + 1);
138         int expected_result[] = {1};
139         BOOST_TEST(std::equal(output, output + 1, expected_result));
140 
141         int array3[] = {3,2,1};
142         int array4[] = {4,3,2};
143         int output2[1];
144         BOOST_TEST(boost::phoenix::set_difference(arg1, arg2, arg3, std::greater<int>())
145                    (array3, array4, output2) ==
146                    output2 + 1);
147         int expected_result2[] = {1};
148         BOOST_TEST(std::equal(output2, output2 + 1, expected_result2));
149         return;
150     }
151 
set_symmetric_difference_test()152     void set_symmetric_difference_test()
153     {
154         using boost::phoenix::set_symmetric_difference;
155         using boost::phoenix::arg_names::arg1;
156         using boost::phoenix::arg_names::arg2;
157         using boost::phoenix::arg_names::arg3;
158         int array[] = {1,2,3};
159         int array2[] = {2,3,4};
160         int output[2];
161         BOOST_TEST(set_symmetric_difference(arg1, arg2, arg3)(array, array2, output) == output + 2);
162         int expected_result[] = {1,4};
163         BOOST_TEST(std::equal(output, output + 2, expected_result));
164 
165         int array3[] = {3,2,1};
166         int array4[] = {4,3,2};
167         int output2[2];
168         BOOST_TEST(boost::phoenix::set_symmetric_difference(arg1, arg2, arg3, std::greater<int>())
169                    (array3, array4, output2) ==
170                    output2 + 2);
171         int expected_result2[] = {4,1};
172         BOOST_TEST(std::equal(output2, output2 + 2, expected_result2));
173         return;
174     }
175 }
176 
main()177 int main()
178 {
179     nth_element_test();
180     merge_test();
181     inplace_merge_test();
182     set_union_test();
183     set_intersection_test();
184     set_difference_test();
185     set_symmetric_difference_test();
186     return boost::report_errors();
187 }
188