]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/icl/test/test_icl_interval_shared.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / icl / test / test_icl_interval_shared.hpp
1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2010: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef LIBS_ICL_TEST_TEST_ICL_interval_shared_hpp_JOFA_100306__
9 #define LIBS_ICL_TEST_TEST_ICL_interval_shared_hpp_JOFA_100306__
10
11 #include <boost/icl/interval_set.hpp>
12
13 template <class DomainT, ICL_COMPARE Compare,
14 ICL_INTERVAL(ICL_COMPARE) Interval>
15 void test_inner_complement(const ICL_INTERVAL_TYPE(Interval,DomainT,Compare)& itv1,
16 const ICL_INTERVAL_TYPE(Interval,DomainT,Compare)& itv2)
17 {
18 typedef interval_set<DomainT,Compare,Interval> ItvSetT;
19 typedef ICL_INTERVAL_TYPE(Interval,DomainT,Compare) IntervalT;
20
21 BOOST_CHECK_EQUAL(icl::length(inner_complement(itv1,itv2)), icl::distance(itv1,itv2));
22 BOOST_CHECK_EQUAL(icl::length(inner_complement(itv1,itv2)), icl::distance(itv2,itv1));
23 BOOST_CHECK_EQUAL(icl::length(inner_complement(itv2,itv1)), icl::distance(itv1,itv2));
24 BOOST_CHECK_EQUAL(icl::length(inner_complement(itv2,itv1)), icl::distance(itv2,itv1));
25
26 IntervalT in_comp = inner_complement(itv1,itv2);
27 ItvSetT itvset, inner_comp;
28 itvset.add(itv1).add(itv2);
29 ItvSetT hullset = ItvSetT(hull(itvset));
30 inner_comp = hullset - itvset;
31 IntervalT inner_comp_itv;
32 if(inner_comp.begin() != inner_comp.end())
33 inner_comp_itv = *inner_comp.begin();
34
35 BOOST_CHECK_EQUAL(inner_complement(itv1,itv2), inner_comp_itv);
36 BOOST_CHECK_EQUAL(inner_complement(itv2,itv1), inner_comp_itv);
37 BOOST_CHECK_EQUAL(icl::length(inner_comp), icl::distance(itv1,itv2));
38 BOOST_CHECK_EQUAL(icl::length(inner_comp), icl::distance(itv2,itv1));
39
40 BOOST_CHECK(icl::disjoint(itv1, in_comp));
41 BOOST_CHECK(icl::disjoint(itv2, in_comp));
42
43 IntervalT itv1_comp = hull(itv1, in_comp);
44 IntervalT itv2_comp = hull(itv2, in_comp);
45
46 if(!icl::is_empty(in_comp))
47 {
48 BOOST_CHECK(icl::intersects(itv1_comp, in_comp));
49 BOOST_CHECK(icl::intersects(itv2_comp, in_comp));
50
51 BOOST_CHECK_EQUAL(itv1_comp & itv2_comp, in_comp);
52 BOOST_CHECK_EQUAL( icl::is_empty(itv1_comp & itv2_comp), icl::disjoint(itv1_comp, itv2_comp));
53 BOOST_CHECK_EQUAL(!icl::is_empty(itv1_comp & itv2_comp), icl::intersects(itv1_comp, itv2_comp));
54 }
55 }
56
57 template <class IntervalT>
58 void test_inner_complement_(const IntervalT& itv1, const IntervalT& itv2)
59 {
60 typedef typename interval_traits<IntervalT>::domain_type DomainT;
61 // For the test of plain interval types we assume that std::less is
62 // the compare functor
63 test_inner_complement<DomainT, std::less, IntervalT>(itv1, itv2);
64 }
65
66 #ifndef BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
67
68 void interval_ctor_specific()
69 {
70 BOOST_CHECK_EQUAL(icl::length(icl::interval<double>::type()), 0.0);
71 BOOST_CHECK_EQUAL(icl::cardinality(icl::interval<double>::closed(5.0, 5.0)), 1);
72 BOOST_CHECK_EQUAL(icl::cardinality(icl::interval<std::string>::closed("test", "test")), 1);
73 BOOST_CHECK_EQUAL(icl::cardinality(icl::interval<std::string>::closed("best","test")),
74 icl::cardinality(icl::interval<double>::closed(0.0,0.1)));
75 BOOST_CHECK_EQUAL(icl::cardinality(icl::interval<std::string>::right_open("best","test")),
76 icl::infinity<size_type_of<icl::interval<std::string>::type>::type >::value() );
77 BOOST_CHECK_EQUAL(icl::cardinality(icl::interval<double>::right_open(0.0, 1.0)),
78 icl::infinity<size_type_of<icl::interval<double>::type>::type >::value() );
79 }
80
81 #endif // ndef BOOST_ICL_USE_STATIC_BOUNDED_INTERVALS
82
83 template <class T>
84 void interval_equal_4_integral_types()
85 {
86 typedef typename icl::interval<T>::type IntervalT;
87 T v2 = make<T>(2);
88 T v3 = make<T>(3);
89 T v7 = make<T>(7);
90 T v8 = make<T>(8);
91 BOOST_CHECK_EQUAL(IntervalT(), IntervalT(v7,v3));
92
93 //I: (I)nside = closed bound
94 //C: left open bound
95 //D: right open bound
96 IntervalT I3_7I = icl::interval<T>::closed(v3,v7);
97 IntervalT I3__8D = icl::interval<T>::right_open(v3,v8);
98 IntervalT C2__7I = icl::interval<T>::left_open(v2,v7);
99 IntervalT C2___8D = icl::interval<T>::open(v2,v8);
100
101 BOOST_CHECK_EQUAL( I3_7I , I3_7I );
102 BOOST_CHECK_EQUAL( I3_7I , I3__8D );
103 BOOST_CHECK_EQUAL( I3_7I , C2__7I );
104 BOOST_CHECK_EQUAL( I3_7I , C2___8D );
105
106 BOOST_CHECK_EQUAL( I3__8D, I3__8D );
107 BOOST_CHECK_EQUAL( I3__8D, C2__7I );
108 BOOST_CHECK_EQUAL( I3__8D, C2___8D );
109
110 BOOST_CHECK_EQUAL( C2__7I , C2__7I );
111 BOOST_CHECK_EQUAL( C2__7I , C2___8D );
112
113 BOOST_CHECK_EQUAL( C2___8D, C2___8D );
114 }
115
116 template <class T>
117 void interval_less_4_integral_types()
118 {
119 typedef typename icl::interval<T>::type IntervalT;
120 T v2 = make<T>(2);
121 T v3 = make<T>(3);
122 T v4 = make<T>(4);
123 T v7 = make<T>(7);
124 T v8 = make<T>(8);
125 BOOST_CHECK_EQUAL(IntervalT() < IntervalT(v7,v3), false);
126 BOOST_CHECK_EQUAL(icl::interval<T>::open(v2,v3) < icl::interval<T>::right_open(v7,v7), false);
127 BOOST_CHECK_EQUAL(icl::interval<T>::left_open(v3,v3) < icl::interval<T>::closed(v7,v3), false);
128
129 BOOST_CHECK_EQUAL(IntervalT() < IntervalT(v3,v4), true);
130 BOOST_CHECK_EQUAL(icl::interval<T>::open(v2,v3) < icl::interval<T>::right_open(v7,v8), true);
131
132 //I: (I)nside = closed bound
133 //C: left open bound
134 //D: right open bound
135 IntervalT I3_7I = icl::interval<T>::closed(v3,v7);
136 IntervalT I4_7I = icl::interval<T>::closed(v4,v7);
137
138 IntervalT I3__8D = icl::interval<T>::right_open(v3,v8);
139 IntervalT C2__7I = icl::interval<T>::left_open(v2,v7);
140 IntervalT C2___8D = icl::interval<T>::open(v2,v8);
141
142 BOOST_CHECK_EQUAL( I3_7I < I3_7I , false);
143 BOOST_CHECK_EQUAL( I3_7I < I3__8D , false);
144 BOOST_CHECK_EQUAL( I3_7I < C2__7I , false);
145 BOOST_CHECK_EQUAL( I3_7I < C2___8D , false);
146
147 BOOST_CHECK_EQUAL( I3_7I < I4_7I , true);
148
149
150 BOOST_CHECK_EQUAL( I3__8D< I3__8D , false);
151 BOOST_CHECK_EQUAL( I3__8D< C2__7I , false);
152 BOOST_CHECK_EQUAL( I3__8D< C2___8D , false);
153
154 BOOST_CHECK_EQUAL( C2__7I < C2__7I , false);
155 BOOST_CHECK_EQUAL( C2__7I < C2___8D , false);
156
157 BOOST_CHECK_EQUAL( C2___8D< C2___8D , false);
158 }
159
160 template <class T>
161 void interval_equal_4_bicremental_continuous_types()
162 {
163 typedef typename icl::interval<T>::type IntervalT;
164 T v3 = make<T>(3);
165 T v7 = make<T>(7);
166 BOOST_CHECK_EQUAL(IntervalT(), IntervalT(v7,v3));
167
168 //I: (I)nside = closed bound
169 //O: (O)utside = open bound
170 IntervalT I3_7I = icl::interval<T>::closed(v3,v7);
171 IntervalT I3_7D = icl::interval<T>::right_open(v3,v7);
172 IntervalT C3_7I = icl::interval<T>::left_open(v3,v7);
173 IntervalT C3_7D = icl::interval<T>::open(v3,v7);
174
175 BOOST_CHECK_EQUAL( I3_7I , I3_7I );
176 BOOST_CHECK_EQUAL( I3_7I == I3_7D, false );
177 BOOST_CHECK_EQUAL( I3_7I == C3_7D, false );
178 BOOST_CHECK_EQUAL( I3_7I == C3_7D, false );
179 BOOST_CHECK_EQUAL( I3_7I != I3_7D, true );
180 BOOST_CHECK_EQUAL( I3_7I != C3_7D, true );
181 BOOST_CHECK_EQUAL( I3_7I != C3_7D, true );
182
183 BOOST_CHECK_EQUAL( I3_7D , I3_7D );
184 BOOST_CHECK_EQUAL( I3_7D == C3_7I, false );
185 BOOST_CHECK_EQUAL( I3_7D == C3_7D, false );
186 BOOST_CHECK_EQUAL( I3_7D != C3_7I, true );
187 BOOST_CHECK_EQUAL( I3_7D != C3_7D, true );
188
189 BOOST_CHECK_EQUAL( C3_7I , C3_7I );
190 BOOST_CHECK_EQUAL( C3_7I == C3_7D, false );
191 BOOST_CHECK_EQUAL( C3_7I != C3_7D, true );
192
193 BOOST_CHECK_EQUAL( C3_7D, C3_7D );
194 }
195
196 template <class T>
197 void interval_touches_4_bicremental_types()
198 {
199 typedef typename icl::interval<T>::type IntervalT;
200 T v3 = make<T>(3);
201 T v7 = make<T>(7);
202 T v9 = make<T>(9);
203
204 IntervalT I3_7D = icl::interval<T>::right_open(v3,v7);
205 IntervalT I7_9I = icl::interval<T>::closed(v7,v9);
206 BOOST_CHECK_EQUAL( icl::touches(I3_7D, I7_9I), true );
207
208 IntervalT I3_7I = icl::interval<T>::closed(v3,v7);
209 IntervalT C7_9I = icl::interval<T>::left_open(v7,v9);
210 BOOST_CHECK_EQUAL( icl::touches(I3_7I, C7_9I), true );
211
212 BOOST_CHECK_EQUAL( icl::touches(I3_7D, C7_9I), false );
213 BOOST_CHECK_EQUAL( icl::touches(I3_7I, I7_9I), false );
214 }
215
216 template <class T>
217 void interval_touches_4_integral_types()
218 {
219 typedef typename icl::interval<T>::type IntervalT;
220 T v3 = make<T>(3);
221 T v6 = make<T>(6);
222 T v7 = make<T>(7);
223 T v9 = make<T>(9);
224
225 IntervalT I3_6I = icl::interval<T>::closed(v3,v6);
226 IntervalT I7_9I = icl::interval<T>::closed(v7,v9);
227 BOOST_CHECK_EQUAL( icl::touches(I3_6I, I7_9I), true );
228
229 IntervalT I3_7D = icl::interval<T>::right_open(v3,v7);
230 IntervalT C6_9I = icl::interval<T>::left_open(v6,v9);
231 BOOST_CHECK_EQUAL( icl::touches(I3_7D, C6_9I), true );
232 }
233
234 template <class T>
235 void interval_infix_intersect_4_bicremental_types()
236 {
237 typedef typename icl::interval<T>::type IntervalT;
238
239 IntervalT section;
240 IntervalT I3_7D = I_D(3,7);
241
242 IntervalT I0_3D = I_D(0,3);
243 section = I3_7D & I0_3D;
244 BOOST_CHECK_EQUAL( icl::disjoint(I0_3D, I3_7D), true );
245 BOOST_CHECK_EQUAL( icl::is_empty(section), true );
246 BOOST_CHECK_EQUAL( section, IntervalT() );
247
248 IntervalT I0_5D = I_D(0,5);
249 section = I3_7D & I0_5D;
250 BOOST_CHECK_EQUAL( section, I_D(3,5) );
251
252 IntervalT I0_9D = I_D(0,9);
253 section = I3_7D & I0_9D;
254 BOOST_CHECK_EQUAL( section, I3_7D );
255
256 IntervalT I4_5I = I_I(4,5);
257 section = I3_7D & I4_5I;
258 BOOST_CHECK_EQUAL( section, I4_5I );
259
260 IntervalT C4_6D = C_D(4,6);
261 section = I3_7D & C4_6D;
262 BOOST_CHECK_EQUAL( section, C4_6D );
263
264 IntervalT C4_9I = C_I(4,9);
265 section = I3_7D & C4_9I;
266 BOOST_CHECK_EQUAL( section, C_D(4,7) );
267
268 IntervalT I7_9I = I_I(7,9);
269 section = I3_7D & I7_9I;
270 BOOST_CHECK_EQUAL( icl::exclusive_less(I3_7D, I7_9I), true );
271 BOOST_CHECK_EQUAL( icl::disjoint(I3_7D, I7_9I), true );
272 BOOST_CHECK_EQUAL( icl::is_empty(section), true );
273 }
274
275 template <class T>
276 void interval_subtract_4_bicremental_types()
277 {
278 typedef typename icl::interval<T>::type IntervalT;
279
280 IntervalT diff_1, diff_2;
281 IntervalT I0_3D = I_D(0,3);
282 IntervalT I2_6D = I_D(2,6);
283 IntervalT I4_7D = I_D(4,7);
284 IntervalT I6_7D = I_D(6,7);
285 IntervalT I2_4D = I_D(2,4);
286
287 diff_1 = right_subtract(I2_6D, I4_7D);
288 BOOST_CHECK_EQUAL( diff_1, I2_4D );
289
290 diff_1 = right_subtract(I0_3D, I4_7D);
291 BOOST_CHECK_EQUAL( diff_1, I0_3D );
292
293 // ---------------------------------
294 diff_1 = left_subtract(I4_7D, I2_6D);
295 BOOST_CHECK_EQUAL( diff_1, I6_7D );
296
297 diff_1 = left_subtract(I4_7D, I0_3D);
298 BOOST_CHECK_EQUAL( diff_1, I4_7D );
299 }
300
301
302 #endif // LIBS_ICL_TEST_TEST_ICL_interval_shared_hpp_JOFA_100306__