]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / chrono / test / duration / arithmetic_pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Adaptation to Boost of the libcxx
10 // Copyright 2010 Vicente J. Botet Escriba
11 // Distributed under the Boost Software License, Version 1.0.
12 // See http://www.boost.org/LICENSE_1_0.txt
13
14 #include <boost/chrono/duration.hpp>
15
16 #include <boost/detail/lightweight_test.hpp>
17 #ifdef BOOST_NO_CXX11_CONSTEXPR
18 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
19 #else
20 #include <boost/static_assert.hpp>
21 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
22 #endif
23
24 int main()
25 {
26 // Default construct
27 {
28 //BOOST_CONSTEXPR
29 boost::chrono::minutes m;
30 //BOOST_CONSTEXPR_ASSERT(m.count() == 0);
31 (void)m;
32 }
33
34 // UNARY PLUS
35 {
36 boost::chrono::minutes m(3);
37 boost::chrono::minutes m2 = +m;
38 BOOST_TEST(m.count() == m2.count());
39 }
40 {
41 BOOST_CONSTEXPR boost::chrono::minutes m(3);
42 BOOST_CONSTEXPR boost::chrono::minutes m2(+m);
43 BOOST_CONSTEXPR_ASSERT(m.count() == m2.count());
44 }
45
46 // UNARY MINUS
47 {
48 boost::chrono::minutes m(3);
49 boost::chrono::minutes m2 = -m;
50 BOOST_TEST(m2.count() == -m.count());
51 }
52 {
53 BOOST_CONSTEXPR boost::chrono::minutes m(3);
54 BOOST_CONSTEXPR boost::chrono::minutes m2 = -m;
55 BOOST_CONSTEXPR_ASSERT(m2.count() == -m.count());
56 }
57 // PRE INCREMENT
58 {
59 boost::chrono::hours h(3);
60 boost::chrono::hours& href = ++h;
61 BOOST_TEST(&href == &h);
62 BOOST_TEST(h.count() == 4);
63 }
64 // POST INCREMENT
65 {
66 boost::chrono::hours h(3);
67 boost::chrono::hours h2 = h++;
68 BOOST_TEST(h.count() == 4);
69 BOOST_TEST(h2.count() == 3);
70 }
71 // PRE DECREMENT
72 {
73 boost::chrono::hours h(3);
74 boost::chrono::hours& href = --h;
75 BOOST_TEST(&href == &h);
76 BOOST_TEST(h.count() == 2);
77 }
78 // POST DECREMENT
79 {
80 boost::chrono::hours h(3);
81 boost::chrono::hours h2 = h--;
82 BOOST_TEST(h.count() == 2);
83 BOOST_TEST(h2.count() == 3);
84 }
85 // PLUS ASSIGN
86 {
87 boost::chrono::seconds s(3);
88 s += boost::chrono::seconds(2);
89 BOOST_TEST(s.count() == 5);
90 s += boost::chrono::minutes(2);
91 BOOST_TEST(s.count() == 125);
92 }
93 // MINUS ASSIGN
94 {
95 boost::chrono::seconds s(3);
96 s -= boost::chrono::seconds(2);
97 BOOST_TEST(s.count() == 1);
98 s -= boost::chrono::minutes(2);
99 BOOST_TEST(s.count() == -119);
100 }
101 // TIMES ASSIGN
102 {
103 boost::chrono::nanoseconds ns(3);
104 ns *= 5;
105 BOOST_TEST(ns.count() == 15);
106 }
107 // DIVIDE ASSIGN
108 {
109 boost::chrono::nanoseconds ns(15);
110 ns /= 5;
111 BOOST_TEST(ns.count() == 3);
112 }
113 // MODULUS ASSIGN duration
114 {
115 boost::chrono::microseconds us(11);
116 boost::chrono::microseconds us2(3);
117 us %= us2;
118 BOOST_TEST(us.count() == 2);
119 us %= boost::chrono::milliseconds(3);
120 BOOST_TEST(us.count() == 2);
121 }
122 // MODULUS ASSIGN Rep
123 {
124 boost::chrono::microseconds us(11);
125 us %= 3;
126 BOOST_TEST(us.count() == 2);
127 }
128 // PLUS
129 {
130 boost::chrono::seconds s1(3);
131 boost::chrono::seconds s2(5);
132 boost::chrono::seconds r = s1 + s2;
133 BOOST_TEST(r.count() == 8);
134 }
135 {
136 BOOST_CONSTEXPR boost::chrono::seconds s1(3);
137 BOOST_CONSTEXPR boost::chrono::seconds s2(5);
138 BOOST_CONSTEXPR boost::chrono::seconds r = s1 + s2;
139 BOOST_CONSTEXPR_ASSERT(r.count() == 8);
140 }
141 {
142 boost::chrono::seconds s1(3);
143 boost::chrono::microseconds s2(5);
144 boost::chrono::microseconds r = s1 + s2;
145 BOOST_TEST(r.count() == 3000005);
146 }
147 {
148 BOOST_CONSTEXPR boost::chrono::seconds s1(3);
149 BOOST_CONSTEXPR boost::chrono::microseconds s2(5);
150 BOOST_CONSTEXPR boost::chrono::microseconds r = s1 + s2;
151 BOOST_CONSTEXPR_ASSERT(r.count() == 3000005);
152 }
153 {
154 boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
155 boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
156 boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 + s2;
157 BOOST_TEST(r.count() == 75);
158 }
159 {
160 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
161 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
162 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 + s2;
163 BOOST_CONSTEXPR_ASSERT(r.count() == 75);
164 }
165 {
166 boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
167 boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
168 boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 + s2;
169 BOOST_TEST(r.count() == 75);
170 }
171 {
172 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
173 BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
174 BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 + s2;
175 BOOST_CONSTEXPR_ASSERT(r.count() == 75);
176 }
177
178 // MINUS
179 {
180 boost::chrono::seconds s1(3);
181 boost::chrono::seconds s2(5);
182 boost::chrono::seconds r = s1 - s2;
183 BOOST_TEST(r.count() == -2);
184 }
185 {
186 BOOST_CONSTEXPR boost::chrono::seconds s1(3);
187 BOOST_CONSTEXPR boost::chrono::seconds s2(5);
188 BOOST_CONSTEXPR boost::chrono::seconds r = s1 - s2;
189 BOOST_CONSTEXPR_ASSERT(r.count() == -2);
190 }
191 {
192 boost::chrono::seconds s1(3);
193 boost::chrono::microseconds s2(5);
194 boost::chrono::microseconds r = s1 - s2;
195 BOOST_TEST(r.count() == 2999995);
196 }
197 {
198 BOOST_CONSTEXPR boost::chrono::seconds s1(3);
199 BOOST_CONSTEXPR boost::chrono::microseconds s2(5);
200 BOOST_CONSTEXPR boost::chrono::microseconds r = s1 - s2;
201 BOOST_CONSTEXPR_ASSERT(r.count() == 2999995);
202 }
203 {
204 boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
205 boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
206 boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 - s2;
207 BOOST_TEST(r.count() == -15);
208 }
209 {
210 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
211 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
212 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 - s2;
213 BOOST_CONSTEXPR_ASSERT(r.count() == -15);
214 }
215 {
216 boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
217 boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
218 boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 - s2;
219 BOOST_TEST(r.count() == -15);
220 }
221 {
222 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(3);
223 BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
224 BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<1, 15> > r = s1 - s2;
225 BOOST_CONSTEXPR_ASSERT(r.count() == -15);
226 }
227
228 // TIMES rep
229 {
230 boost::chrono::nanoseconds ns(3);
231 boost::chrono::nanoseconds ns2 = ns * 5;
232 BOOST_TEST(ns2.count() == 15);
233 boost::chrono::nanoseconds ns3 = 6 * ns2;
234 BOOST_TEST(ns3.count() == 90);
235 }
236 {
237 BOOST_CONSTEXPR boost::chrono::nanoseconds ns(3);
238 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns * 5;
239 BOOST_CONSTEXPR_ASSERT(ns2.count() == 15);
240 BOOST_CONSTEXPR boost::chrono::nanoseconds ns3 = 6 * ns2;
241 BOOST_CONSTEXPR_ASSERT(ns3.count() == 90);
242 }
243
244 // DIVIDE duration
245 {
246 boost::chrono::nanoseconds ns1(15);
247 boost::chrono::nanoseconds ns2(5);
248 BOOST_TEST(ns1 / ns2 == 3);
249 }
250 {
251 BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15);
252 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5);
253 BOOST_CONSTEXPR_ASSERT(ns1 / ns2 == 3);
254 }
255 {
256 boost::chrono::microseconds us1(15);
257 boost::chrono::nanoseconds ns2(5);
258 BOOST_TEST(us1 / ns2 == 3000);
259 }
260 {
261 BOOST_CONSTEXPR boost::chrono::microseconds us1(15);
262 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5);
263 BOOST_CONSTEXPR_ASSERT(us1 / ns2 == 3000);
264 }
265 {
266 boost::chrono::duration<int, boost::ratio<2, 3> > s1(30);
267 boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
268 BOOST_TEST(s1 / s2 == 6);
269 }
270 {
271 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(30);
272 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s2(5);
273 BOOST_CONSTEXPR_ASSERT(s1 / s2 == 6);
274 }
275 {
276 boost::chrono::duration<int, boost::ratio<2, 3> > s1(30);
277 boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
278 //BOOST_TEST(s1 / s2 == 20. / 3);
279 BOOST_TEST(3 * s1 == 20 * s2);
280 }
281 {
282 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s1(30);
283 BOOST_CONSTEXPR boost::chrono::duration<double, boost::ratio<3, 5> > s2(5);
284 //BOOST_CONSTEXPR_ASSERT(s1 / s2 == 20. / 3);
285 BOOST_TEST(3 * s1 == 20 * s2);
286 }
287 // DIVIDE rep
288 {
289 boost::chrono::nanoseconds ns(15);
290 boost::chrono::nanoseconds ns2 = ns / 5;
291 BOOST_TEST(ns2.count() == 3);
292 }
293 {
294 BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15);
295 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns / 5;
296 BOOST_CONSTEXPR_ASSERT(ns2.count() == 3);
297 }
298
299 // MODULUS duration
300
301 {
302 boost::chrono::nanoseconds ns1(15);
303 boost::chrono::nanoseconds ns2(6);
304 boost::chrono::nanoseconds r = ns1 % ns2;
305 BOOST_TEST(r.count() == 3);
306 }
307 {
308 BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15);
309 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(6);
310 BOOST_CONSTEXPR boost::chrono::nanoseconds r = ns1 % ns2;
311 BOOST_CONSTEXPR_ASSERT(r.count() == 3);
312 }
313 {
314 boost::chrono::microseconds us1(15);
315 boost::chrono::nanoseconds ns2(28);
316 boost::chrono::nanoseconds r = us1 % ns2;
317 BOOST_TEST(r.count() == 20);
318 }
319 {
320 BOOST_CONSTEXPR boost::chrono::microseconds us1(15);
321 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(28);
322 BOOST_CONSTEXPR boost::chrono::nanoseconds r = us1 % ns2;
323 BOOST_CONSTEXPR_ASSERT(r.count() == 20);
324 }
325 {
326 boost::chrono::duration<int, boost::ratio<3, 5> > s1(6);
327 boost::chrono::duration<int, boost::ratio<2, 3> > s2(3);
328 boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 % s2;
329 BOOST_TEST(r.count() == 24);
330 }
331 {
332 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<3, 5> > s1(6);
333 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<2, 3> > s2(3);
334 BOOST_CONSTEXPR boost::chrono::duration<int, boost::ratio<1, 15> > r = s1 % s2;
335 BOOST_CONSTEXPR_ASSERT(r.count() == 24);
336 }
337 // MODULUS rep
338 {
339 boost::chrono::nanoseconds ns(15);
340 boost::chrono::nanoseconds ns2 = ns % 6;
341 BOOST_TEST(ns2.count() == 3);
342 }
343 {
344 BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15);
345 BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns % 6;
346 BOOST_CONSTEXPR_ASSERT(ns2.count() == 3);
347 }
348
349 return boost::report_errors();
350 }