]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/test/test_less.cpp
1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
11 #include <boost/type_erasure/any.hpp>
12 #include <boost/type_erasure/builtin.hpp>
13 #include <boost/type_erasure/operators.hpp>
14 #include <boost/type_erasure/any_cast.hpp>
15 #include <boost/type_erasure/tuple.hpp>
16 #include <boost/mpl/vector.hpp>
18 #define BOOST_TEST_MAIN
19 #include <boost/test/unit_test.hpp>
21 using namespace boost::type_erasure
;
23 BOOST_AUTO_TEST_CASE(test_basic
)
25 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<> > test_concept
;
26 any
<test_concept
> x(1);
27 any
<test_concept
> y(2);
30 BOOST_CHECK(!(y
< x
));
31 BOOST_CHECK(!(x
< x
));
33 BOOST_CHECK(!(x
> y
));
35 BOOST_CHECK(!(x
> x
));
37 BOOST_CHECK((x
<= y
));
38 BOOST_CHECK(!(y
<= x
));
39 BOOST_CHECK((x
<= x
));
41 BOOST_CHECK(!(x
>= y
));
42 BOOST_CHECK((y
>= x
));
43 BOOST_CHECK((x
>= x
));
46 BOOST_AUTO_TEST_CASE(test_mixed_less
)
48 typedef boost::mpl::vector
<copy_constructible
<_a
>, copy_constructible
<_b
>, less_than_comparable
<_a
, _b
> > test_concept
;
49 tuple
<test_concept
, _a
, _b
> t(1, 2.0);
50 any
<test_concept
, _a
> x(get
<0>(t
));
51 any
<test_concept
, _b
> y(get
<1>(t
));
55 BOOST_CHECK(!(y
<= x
));
56 BOOST_CHECK(!(x
>= y
));
59 BOOST_AUTO_TEST_CASE(test_mixed_equal
)
61 typedef boost::mpl::vector
<copy_constructible
<_a
>, copy_constructible
<_b
>, less_than_comparable
<_a
, _b
> > test_concept
;
62 tuple
<test_concept
, _a
, _b
> t(1, 1);
63 any
<test_concept
, _a
> x(get
<0>(t
));
64 any
<test_concept
, _b
> y(get
<1>(t
));
66 BOOST_CHECK(!(x
< y
));
67 BOOST_CHECK(!(y
> x
));
68 BOOST_CHECK((y
<= x
));
69 BOOST_CHECK((x
>= y
));
72 BOOST_AUTO_TEST_CASE(test_mixed_greater
)
74 typedef boost::mpl::vector
<copy_constructible
<_a
>, copy_constructible
<_b
>, less_than_comparable
<_a
, _b
> > test_concept
;
75 tuple
<test_concept
, _a
, _b
> t(2.0, 1);
76 any
<test_concept
, _a
> x(get
<0>(t
));
77 any
<test_concept
, _b
> y(get
<1>(t
));
79 BOOST_CHECK(!(x
< y
));
80 BOOST_CHECK(!(y
> x
));
81 BOOST_CHECK((y
<= x
));
82 BOOST_CHECK((x
>= y
));
85 BOOST_AUTO_TEST_CASE(test_fixed_lhs_less
)
87 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<int, _self
> > test_concept
;
89 any
<test_concept
> y(2.0);
93 BOOST_CHECK(!(y
<= x
));
94 BOOST_CHECK(!(x
>= y
));
97 BOOST_AUTO_TEST_CASE(test_fixed_lhs_equal
)
99 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<int, _self
> > test_concept
;
101 any
<test_concept
> y(1);
103 BOOST_CHECK(!(x
< y
));
104 BOOST_CHECK(!(y
> x
));
105 BOOST_CHECK((y
<= x
));
106 BOOST_CHECK((x
>= y
));
110 BOOST_AUTO_TEST_CASE(test_fixed_lhs_greater
)
112 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<int, _self
> > test_concept
;
114 any
<test_concept
> y(0.5);
116 BOOST_CHECK(!(x
< y
));
117 BOOST_CHECK(!(y
> x
));
118 BOOST_CHECK((y
<= x
));
119 BOOST_CHECK((x
>= y
));
122 BOOST_AUTO_TEST_CASE(test_fixed_rhs_less
)
124 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<_self
, int> > test_concept
;
125 any
<test_concept
> x(1.0);
128 BOOST_CHECK((x
< y
));
129 BOOST_CHECK((y
> x
));
130 BOOST_CHECK(!(y
<= x
));
131 BOOST_CHECK(!(x
>= y
));
134 BOOST_AUTO_TEST_CASE(test_fixed_rhs_equal
)
136 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<_self
, int> > test_concept
;
137 any
<test_concept
> x(1);
140 BOOST_CHECK(!(x
< y
));
141 BOOST_CHECK(!(y
> x
));
142 BOOST_CHECK((y
<= x
));
143 BOOST_CHECK((x
>= y
));
147 BOOST_AUTO_TEST_CASE(test_fixed_rhs_greater
)
149 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<_self
, int> > test_concept
;
150 any
<test_concept
> x(2.0);
153 BOOST_CHECK(!(x
< y
));
154 BOOST_CHECK(!(y
> x
));
155 BOOST_CHECK((y
<= x
));
156 BOOST_CHECK((x
>= y
));
159 BOOST_AUTO_TEST_CASE(test_relaxed
)
161 typedef boost::mpl::vector
<copy_constructible
<>, less_than_comparable
<>, relaxed
> test_concept
;
162 any
<test_concept
> x(1);
163 any
<test_concept
> y(2);
164 any
<test_concept
> z(std::string("test"));
166 BOOST_CHECK((x
< y
));
167 BOOST_CHECK(!(y
< x
));
168 BOOST_CHECK(!(x
< x
));
170 BOOST_CHECK(!(x
> y
));
171 BOOST_CHECK((y
> x
));
172 BOOST_CHECK(!(x
> x
));
174 BOOST_CHECK((x
<= y
));
175 BOOST_CHECK(!(y
<= x
));
176 BOOST_CHECK((x
<= x
));
178 BOOST_CHECK(!(x
>= y
));
179 BOOST_CHECK((y
>= x
));
180 BOOST_CHECK((x
>= x
));
182 bool expected
= x
< z
;
184 BOOST_CHECK_EQUAL((x
< z
), expected
);
185 BOOST_CHECK_EQUAL(!(z
< x
), expected
);
187 BOOST_CHECK_EQUAL(!(x
> z
), expected
);
188 BOOST_CHECK_EQUAL((z
> x
), expected
);
190 BOOST_CHECK_EQUAL((x
<= z
), expected
);
191 BOOST_CHECK_EQUAL(!(z
<= x
), expected
);
193 BOOST_CHECK_EQUAL(!(x
>= z
), expected
);
194 BOOST_CHECK_EQUAL((z
>= x
), expected
);
196 BOOST_CHECK_EQUAL((y
< z
), expected
);
197 BOOST_CHECK_EQUAL(!(z
< y
), expected
);
199 BOOST_CHECK_EQUAL(!(y
> z
), expected
);
200 BOOST_CHECK_EQUAL((z
> y
), expected
);
202 BOOST_CHECK_EQUAL((y
<= z
), expected
);
203 BOOST_CHECK_EQUAL(!(z
<= y
), expected
);
205 BOOST_CHECK_EQUAL(!(y
>= z
), expected
);
206 BOOST_CHECK_EQUAL((z
>= y
), expected
);
209 BOOST_AUTO_TEST_CASE(test_overload
)
211 typedef boost::mpl::vector
<
212 copy_constructible
<_a
>,
213 copy_constructible
<_b
>,
214 less_than_comparable
<_a
>,
215 less_than_comparable
<_a
, int>,
216 less_than_comparable
<int, _a
>,
217 less_than_comparable
<_b
>,
218 less_than_comparable
<_b
, int>,
219 less_than_comparable
<int, _b
>,
220 less_than_comparable
<_a
, _b
>
222 tuple
<test_concept
, _a
, _b
> t(1, 2);
223 any
<test_concept
, _a
> x(get
<0>(t
));
224 any
<test_concept
, _b
> y(get
<1>(t
));
226 BOOST_CHECK(!(x
< x
));
228 BOOST_CHECK(!(x
> x
));
231 BOOST_CHECK(!(x
< 1));
233 BOOST_CHECK(!(x
> 1));
236 BOOST_CHECK(!(1 < x
));
238 BOOST_CHECK(!(1 > x
));
241 BOOST_CHECK(!(y
< y
));
243 BOOST_CHECK(!(y
> y
));
246 BOOST_CHECK(!(y
< 2));
248 BOOST_CHECK(!(y
> 2));
251 BOOST_CHECK(!(2 < y
));
253 BOOST_CHECK(!(2 > y
));
258 BOOST_CHECK(!(y
<= x
));
259 BOOST_CHECK(!(x
>= y
));