]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/algorithm/transformation2.cpp
1 /*=============================================================================
2 Copyright (c) 2005-2007 Dan Marsden
3 Copyright (c) 2005-2007 Joel de Guzman
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 ==============================================================================*/
10 #include <boost/phoenix/core.hpp>
11 #include <boost/phoenix/stl/algorithm/transformation.hpp>
12 #include <boost/detail/lightweight_test.hpp>
20 bool operator()(const int i
) const
28 using boost::phoenix::rotate
;
29 using boost::phoenix::arg_names::arg1
;
30 int array
[] = {1,2,3};
31 rotate(arg1
, array
+ 1)(array
);
32 std::cout
<< array
[0] << array
[1] << array
[2] << std::endl
;
33 BOOST_TEST(array
[0] == 2);
34 BOOST_TEST(array
[1] == 3);
35 BOOST_TEST(array
[2] == 1);
40 void rotate_copy_test()
42 using boost::phoenix::rotate_copy
;
43 using boost::phoenix::arg_names::arg1
;
44 using boost::phoenix::arg_names::arg2
;
45 int array
[] = {1,2,3};
47 rotate_copy(arg1
, array
+ 1, arg2
)(array
, array2
);
48 BOOST_TEST(array2
[0] == 2);
49 BOOST_TEST(array2
[1] == 3);
50 BOOST_TEST(array2
[2] == 1);
55 void random_shuffle_test()
57 using boost::phoenix::random_shuffle
;
58 using boost::phoenix::arg_names::arg1
;
59 int array
[] = {1,2,3};
60 random_shuffle(arg1
)(array
);
61 const int first
= array
[0];
62 BOOST_TEST(first
== 1 || first
== 2 || first
== 3);
63 const int second
= array
[1];
64 BOOST_TEST(second
== 1 || second
== 2 || second
== 3);
65 BOOST_TEST(first
!= second
);
66 const int third
= array
[2];
67 BOOST_TEST(third
== 1 || third
== 2 || third
== 3);
68 BOOST_TEST(first
!= third
&& second
!= third
);
74 using boost::phoenix::partition
;
75 using boost::phoenix::arg_names::arg1
;
76 int array
[] = {1,2,3};
77 int* const end
= partition(arg1
, even())(array
);
78 BOOST_TEST(end
== array
+ 1);
79 BOOST_TEST(array
[0] % 2 == 0);
80 BOOST_TEST(array
[1] % 2 != 0);
81 BOOST_TEST(array
[2] % 2 != 0);
85 void stable_partition_test()
87 using boost::phoenix::stable_partition
;
88 using boost::phoenix::arg_names::arg1
;
89 int array
[] = {1,2,3};
90 int* const end
= stable_partition(arg1
, even())(array
);
91 BOOST_TEST(end
== array
+ 1);
92 BOOST_TEST(array
[0] == 2);
93 BOOST_TEST(array
[1] == 1);
94 BOOST_TEST(array
[2] == 3);
100 using boost::phoenix::sort
;
101 using boost::phoenix::arg_names::arg1
;
102 int array
[] = {3,1,2};
103 std::list
<int> test_list(array
, array
+ 3);
105 BOOST_TEST(array
[0] == 1);
106 BOOST_TEST(array
[1] == 2);
107 BOOST_TEST(array
[2] == 3);
109 sort(arg1
)(test_list
);
110 std::list
<int>::const_iterator
it(test_list
.begin());
111 BOOST_TEST(*it
++ == 1);
112 BOOST_TEST(*it
++ == 2);
113 BOOST_TEST(*it
++ == 3);
115 boost::phoenix::sort(arg1
, std::greater
<int>())(array
);
116 BOOST_TEST(array
[0] == 3);
117 BOOST_TEST(array
[1] == 2);
118 BOOST_TEST(array
[2] == 1);
120 boost::phoenix::sort(arg1
, std::greater
<int>())(test_list
);
121 std::list
<int>::const_iterator
jt(test_list
.begin());
122 BOOST_TEST(*jt
++ == 3);
123 BOOST_TEST(*jt
++ == 2);
124 BOOST_TEST(*jt
++ == 1);
129 void stable_sort_test()
131 using boost::phoenix::stable_sort
;
132 using boost::phoenix::arg_names::arg1
;
133 int array
[] = {3,1,2};
134 stable_sort(arg1
)(array
);
135 BOOST_TEST(array
[0] == 1);
136 BOOST_TEST(array
[1] == 2);
137 BOOST_TEST(array
[2] == 3);
139 boost::phoenix::stable_sort(arg1
, std::greater
<int>())(array
);
140 BOOST_TEST(array
[0] == 3);
141 BOOST_TEST(array
[1] == 2);
142 BOOST_TEST(array
[2] == 1);
147 void partial_sort_test()
149 using boost::phoenix::partial_sort
;
150 using boost::phoenix::arg_names::arg1
;
151 int array
[] = {2,4,1,3};
152 partial_sort(arg1
, array
+ 2)(array
);
153 BOOST_TEST(array
[0] == 1);
154 BOOST_TEST(array
[1] == 2);
156 boost::phoenix::partial_sort(arg1
, array
+ 2, std::greater
<int>())(array
);
157 BOOST_TEST(array
[0] == 4);
158 BOOST_TEST(array
[1] == 3);
162 void partial_sort_copy_test()
164 using boost::phoenix::partial_sort_copy
;
165 using boost::phoenix::arg_names::arg1
;
166 using boost::phoenix::arg_names::arg2
;
167 int array
[] = {2,4,1,3};
169 partial_sort_copy(arg1
, arg2
)(array
, array2
);
170 BOOST_TEST(array2
[0] == 1);
171 BOOST_TEST(array2
[1] == 2);
173 boost::phoenix::partial_sort_copy(arg1
, arg2
, std::greater
<int>())(array
, array2
);
174 BOOST_TEST(array2
[0] == 4);
175 BOOST_TEST(array2
[1] == 3);
185 random_shuffle_test();
187 stable_partition_test();
191 partial_sort_copy_test();
192 return boost::report_errors();