]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp
521ca644dbf33431c94a2f9ddc47f7f82ff809b8
1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
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
14 #include <boost/chrono/duration.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17 #ifdef BOOST_NO_CXX11_CONSTEXPR
18 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
20 #include <boost/static_assert.hpp>
21 #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
29 boost::chrono::minutes m
;
30 //BOOST_CONSTEXPR_ASSERT(m.count() == 0);
36 boost::chrono::minutes
m(3);
37 boost::chrono::minutes m2
= +m
;
38 BOOST_TEST(m
.count() == m2
.count());
41 BOOST_CONSTEXPR
boost::chrono::minutes
m(3);
42 BOOST_CONSTEXPR
boost::chrono::minutes
m2(+m
);
43 BOOST_CONSTEXPR_ASSERT(m
.count() == m2
.count());
48 boost::chrono::minutes
m(3);
49 boost::chrono::minutes m2
= -m
;
50 BOOST_TEST(m2
.count() == -m
.count());
53 BOOST_CONSTEXPR
boost::chrono::minutes
m(3);
54 BOOST_CONSTEXPR
boost::chrono::minutes m2
= -m
;
55 BOOST_CONSTEXPR_ASSERT(m2
.count() == -m
.count());
59 boost::chrono::hours
h(3);
60 boost::chrono::hours
& href
= ++h
;
61 BOOST_TEST(&href
== &h
);
62 BOOST_TEST(h
.count() == 4);
66 boost::chrono::hours
h(3);
67 boost::chrono::hours h2
= h
++;
68 BOOST_TEST(h
.count() == 4);
69 BOOST_TEST(h2
.count() == 3);
73 boost::chrono::hours
h(3);
74 boost::chrono::hours
& href
= --h
;
75 BOOST_TEST(&href
== &h
);
76 BOOST_TEST(h
.count() == 2);
80 boost::chrono::hours
h(3);
81 boost::chrono::hours h2
= h
--;
82 BOOST_TEST(h
.count() == 2);
83 BOOST_TEST(h2
.count() == 3);
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);
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);
103 boost::chrono::nanoseconds
ns(3);
105 BOOST_TEST(ns
.count() == 15);
109 boost::chrono::nanoseconds
ns(15);
111 BOOST_TEST(ns
.count() == 3);
113 // MODULUS ASSIGN duration
115 boost::chrono::microseconds
us(11);
116 boost::chrono::microseconds
us2(3);
118 BOOST_TEST(us
.count() == 2);
119 us
%= boost::chrono::milliseconds(3);
120 BOOST_TEST(us
.count() == 2);
122 // MODULUS ASSIGN Rep
124 boost::chrono::microseconds
us(11);
126 BOOST_TEST(us
.count() == 2);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
246 boost::chrono::nanoseconds
ns1(15);
247 boost::chrono::nanoseconds
ns2(5);
248 BOOST_TEST(ns1
/ ns2
== 3);
251 BOOST_CONSTEXPR
boost::chrono::nanoseconds
ns1(15);
252 BOOST_CONSTEXPR
boost::chrono::nanoseconds
ns2(5);
253 BOOST_CONSTEXPR_ASSERT(ns1
/ ns2
== 3);
256 boost::chrono::microseconds
us1(15);
257 boost::chrono::nanoseconds
ns2(5);
258 BOOST_TEST(us1
/ ns2
== 3000);
261 BOOST_CONSTEXPR
boost::chrono::microseconds
us1(15);
262 BOOST_CONSTEXPR
boost::chrono::nanoseconds
ns2(5);
263 BOOST_CONSTEXPR_ASSERT(us1
/ ns2
== 3000);
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);
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);
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
);
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
);
289 boost::chrono::nanoseconds
ns(15);
290 boost::chrono::nanoseconds ns2
= ns
/ 5;
291 BOOST_TEST(ns2
.count() == 3);
294 BOOST_CONSTEXPR
boost::chrono::nanoseconds
ns(15);
295 BOOST_CONSTEXPR
boost::chrono::nanoseconds ns2
= ns
/ 5;
296 BOOST_CONSTEXPR_ASSERT(ns2
.count() == 3);
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);
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);
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);
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);
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);
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);
339 boost::chrono::nanoseconds
ns(15);
340 boost::chrono::nanoseconds ns2
= ns
% 6;
341 BOOST_TEST(ns2
.count() == 3);
344 BOOST_CONSTEXPR
boost::chrono::nanoseconds
ns(15);
345 BOOST_CONSTEXPR
boost::chrono::nanoseconds ns2
= ns
% 6;
346 BOOST_CONSTEXPR_ASSERT(ns2
.count() == 3);
349 return boost::report_errors();