11 #define BOOST_TEST_MODULE ( intervals_test )
12 #include <boost/test/unit_test.hpp>
22 #include <type_traits>
26 struct static_assert_type {
28 explicit static_assert_type(U)
30 static_assert(std::is_same_v<T, U>);
35 struct static_assert_type<T&> {
37 explicit static_assert_type(U&)
39 static_assert(std::is_same_v<T&, U&>);
53 (!util::quantities::concepts::details::has_category_v<ObjectWithoutCategory>);
55 ( util::quantities::concepts::details::has_category_v<ObjectWithCategory>);
129 static_assert(!util::quantities::concepts::is_interval_v<double>);
131 (!util::quantities::concepts::is_interval_v<ObjectWithoutCategory>);
132 static_assert(!util::quantities::concepts::is_interval_v<ObjectWithCategory>);
142 static_assert(!util::quantities::concepts::is_point_v<double>);
144 (!util::quantities::concepts::is_point_v<ObjectWithoutCategory>);
145 static_assert(!util::quantities::concepts::is_point_v<ObjectWithCategory>);
155 static_assert(!util::quantities::concepts::is_interval_or_point_v<double>);
157 (!util::quantities::concepts::is_interval_or_point_v<ObjectWithoutCategory>);
158 static_assert(!util::quantities::concepts::is_interval_or_point_v<ObjectWithCategory>);
174 using namespace util::quantities::time_literals;
183 static_assert(ct1.value() == 2.0);
186 static_assert(ct2.value() == 6.0);
189 static_assert(ct3.value() == -4.0);
197 using namespace util::quantities::time_literals;
206 static_assert( t1 == 6_us );
207 static_assert( t1 == 6000_ns );
208 static_assert( 6_us == t1 );
209 static_assert( 6000_ns == t1 );
210 static_assert( t1 == t1s );
211 static_assert(!(t1 == 5_us ));
212 static_assert(!(t1 == 5_ns ));
213 static_assert(!(5_us == t1 ));
214 static_assert(!(5_ns == t1 ));
215 static_assert(!(t1 == t2 ));
217 static_assert(!(t1 != 6_us ));
218 static_assert(!(t1 != 6000_ns));
219 static_assert(!(6_us != t1 ));
220 static_assert(!(6000_ns != t1 ));
221 static_assert(!(t1 != t1s ));
222 static_assert( t1 != 5_us );
223 static_assert( t1 != 5_ns );
224 static_assert( 5_us != t1 );
225 static_assert( 5_ns != t1 );
226 static_assert( t1 != t2 );
228 static_assert( t1 >= 6_us );
229 static_assert( t1 >= 6000_ns );
230 static_assert( 6_us >= t1 );
231 static_assert( 6000_ns >= t1 );
232 static_assert( t1 >= t1s );
233 static_assert( t1 >= 5_us );
234 static_assert( t1 >= 5000_ns );
235 static_assert(!(5_us >= t1 ));
236 static_assert(!(5000_ns >= t1 ));
237 static_assert(!(t1 >= 8_us ));
238 static_assert(!(t1 >= 8000_ns));
239 static_assert( 8_us >= t1 );
240 static_assert( 8000_ns >= t1 );
241 static_assert( t1 >= t2 );
243 static_assert(!(t1 > 6_us ));
244 static_assert(!(t1 > 6000_ns));
245 static_assert(!(6_us > t1 ));
246 static_assert(!(6000_ns > t1 ));
247 static_assert(!(t1 > t1s ));
248 static_assert( t1 > 5_us );
249 static_assert( t1 > 5000_ns );
250 static_assert(!(5_us > t1 ));
251 static_assert(!(5000_ns > t1 ));
252 static_assert(!(t1 > 8_us ));
253 static_assert(!(t1 > 8000_ns));
254 static_assert( 8_us > t1 );
255 static_assert( 8000_ns > t1 );
256 static_assert( t1 > t2 );
258 static_assert( t1 <= 6_us );
259 static_assert( t1 <= 6000_ns );
260 static_assert( 6000_ns <= t1 );
261 static_assert( t1 <= t1s );
262 static_assert(!(t1 <= 5_us ));
263 static_assert(!(t1 <= 5000_ns));
264 static_assert( 5_us <= t1 );
265 static_assert( 5000_ns <= t1 );
266 static_assert( t1 <= 8_us );
267 static_assert( t1 <= 8000_ns );
268 static_assert(!(8_us <= t1 ));
269 static_assert(!(8000_ns <= t1 ));
270 static_assert(!(t1 <= t2 ));
272 static_assert(!(t1 < 6_us ));
273 static_assert(!(t1 < 6000_ns));
274 static_assert(!(6_us < t1 ));
275 static_assert(!(6000_ns < t1 ));
276 static_assert(!(t1 < t1s ));
277 static_assert(!(t1 < 5_us ));
278 static_assert(!(t1 < 5000_ns));
279 static_assert( 5_us < t1 );
280 static_assert( 5000_ns < t1 );
281 static_assert( t1 < 8_us );
282 static_assert( t1 < 8000_ns );
283 static_assert(!(8_us < t1 ));
284 static_assert(!(8000_ns < t1 ));
285 static_assert(!(t1 < t2 ));
293 using namespace util::quantities::time_literals;
301 static_assert(std::is_same_v<microseconds::quantity_t, util::quantities::microsecond>);
302 static_assert(std::is_same_v<microseconds::unit_t, util::quantities::microsecond::unit_t>);
304 static_assert(t1.quantity() == 6_us );
305 static_assert(t2.quantity() == -4_us );
306 static_assert(t1.value() == 6.0 );
307 static_assert(t2.value() == -4000.0 );
314 using namespace util::quantities::time_literals;
322 static_assert_type<microseconds>{ct1 + -4000.0_ns};
323 static_assert(ct1 + -4000.0_ns == 2_us);
325 static_assert_type<microseconds>{ct1 + ct2};
326 static_assert(ct1 + ct2 == 2_us);
328 static_assert_type<microseconds>{ct1 - -4000.0_ns};
329 static_assert(ct1 - -4000.0_ns == 10_us);
331 static_assert_type<microseconds>{ct1 - ct2};
332 static_assert(ct1 - ct2 == 10_us);
334 static_assert_type<microseconds>{+ct1};
335 static_assert(+ct1 == 6_us);
337 static_assert_type<microseconds>{-ct1};
338 static_assert(-ct1 == -6_us);
340 static_assert_type<microseconds>{ct1.abs()};
341 static_assert(ct1.abs() == 6_us);
342 static_assert(ct2.abs() == 4_us);
344 static_assert_type<microseconds>{ct1 * 3.0};
345 static_assert(ct1 * 3.0 == 6_us * 3.0);
347 static_assert_type<microseconds>{3.0 * ct1};
348 static_assert(3.0 * ct1 == 6_us * 3.0);
350 static_assert_type<microseconds>{ct1 / 2.0};
351 static_assert(ct1 / 2.0 == 6_us / 2.0);
356 decltype(
auto) incr = (t1 += 2000_ns);
357 static_assert_type<microseconds&>{incr};
358 BOOST_TEST(t1 == 8_us);
359 BOOST_TEST(&incr == &t1);
361 decltype(
auto) incr2 = (t1 += t2);
362 static_assert_type<microseconds&>{incr2};
363 BOOST_TEST(t1 == 4_us);
364 BOOST_TEST(t2 == -4_us);
365 BOOST_TEST(&incr2 == &t1);
367 decltype(
auto) decr = (t1 -= 2000_ns);
368 static_assert_type<microseconds&>{decr};
369 BOOST_TEST(t1 == 2_us);
370 BOOST_TEST(&decr == &t1);
372 decltype(
auto) decr2 = (t1 -= t2);
373 static_assert_type<microseconds&>{decr2};
374 BOOST_TEST(t1 == 6_us);
375 BOOST_TEST(t2 == -4_us);
376 BOOST_TEST(&decr2 == &t1);
378 decltype(
auto) expand = (t1 *= 2);
379 static_assert_type<microseconds&>{expand};
380 BOOST_TEST(t1 == 12_us);
381 BOOST_TEST(&expand == &t1);
383 decltype(
auto) shrink = (t1 /= 2);
384 static_assert_type<microseconds&>{shrink};
385 BOOST_TEST(t1 == 6_us);
386 BOOST_TEST(&shrink == &t1);
396 using namespace util::quantities::time_literals;
405 static_assert(ct1.value() == 2.0);
408 static_assert(ct2.value() == 6.0);
411 static_assert(ct3.value() == -4.0);
418 using namespace util::quantities::time_literals;
423 constexpr
nanosecond const t2 { -4
'000'000.0_ps };
427 static_assert( t1 == 6_us );
428 static_assert( t1 == 6000_ns );
429 static_assert( 6_us == t1 );
430 static_assert( 6000_ns == t1 );
431 static_assert( t1 == t1s );
432 static_assert(!(t1 == 5_us ));
433 static_assert(!(t1 == 5_ns ));
434 static_assert(!(5_us == t1 ));
435 static_assert(!(5_ns == t1 ));
436 static_assert(!(t1 == t2 ));
438 static_assert(!(t1 != 6_us ));
439 static_assert(!(t1 != 6000_ns));
440 static_assert(!(6_us != t1 ));
441 static_assert(!(6000_ns != t1 ));
442 static_assert(!(t1 != t1s ));
443 static_assert( t1 != 5_us );
444 static_assert( t1 != 5_ns );
445 static_assert( 5_us != t1 );
446 static_assert( 5_ns != t1 );
447 static_assert( t1 != t2 );
449 static_assert( t1 >= 6_us );
450 static_assert( t1 >= 6000_ns );
451 static_assert( 6_us >= t1 );
452 static_assert( 6000_ns >= t1 );
453 static_assert( t1 >= t1s );
454 static_assert( t1 >= 5_us );
455 static_assert( t1 >= 5000_ns );
456 static_assert(!(5_us >= t1 ));
457 static_assert(!(5000_ns >= t1 ));
458 static_assert(!(t1 >= 8_us ));
459 static_assert(!(t1 >= 8000_ns));
460 static_assert( 8_us >= t1 );
461 static_assert( 8000_ns >= t1 );
462 static_assert( t1 >= t2 );
464 static_assert(!(t1 > 6_us ));
465 static_assert(!(t1 > 6000_ns));
466 static_assert(!(6_us > t1 ));
467 static_assert(!(6000_ns > t1 ));
468 static_assert(!(t1 > t1s ));
469 static_assert( t1 > 5_us );
470 static_assert( t1 > 5000_ns );
471 static_assert(!(5_us > t1 ));
472 static_assert(!(5000_ns > t1 ));
473 static_assert(!(t1 > 8_us ));
474 static_assert(!(t1 > 8000_ns));
475 static_assert( 8_us > t1 );
476 static_assert( 8000_ns > t1 );
477 static_assert( t1 > t2 );
479 static_assert( t1 <= 6_us );
480 static_assert( t1 <= 6000_ns );
481 static_assert( 6_us <= t1 );
482 static_assert( 6000_ns <= t1 );
483 static_assert( t1 <= t1s );
484 static_assert(!(t1 <= 5_us ));
485 static_assert(!(t1 <= 5000_ns));
486 static_assert( 5_us <= t1 );
487 static_assert( 5000_ns <= t1 );
488 static_assert( t1 <= 8_us );
489 static_assert( t1 <= 8000_ns );
490 static_assert(!(8_us <= t1 ));
491 static_assert(!(8000_ns <= t1 ));
492 static_assert(!(t1 <= t2 ));
494 static_assert(!(t1 < 6_us ));
495 static_assert(!(t1 < 6000_ns));
496 static_assert(!(6_us < t1 ));
497 static_assert(!(6000_ns < t1 ));
498 static_assert(!(t1 < t1s ));
499 static_assert(!(t1 < 5_us ));
500 static_assert(!(t1 < 5000_ns));
501 static_assert( 5_us < t1 );
502 static_assert( 5000_ns < t1 );
503 static_assert( t1 < 8_us );
504 static_assert( t1 < 8000_ns );
505 static_assert(!(8_us < t1 ));
506 static_assert(!(8000_ns < t1 ));
507 static_assert(!(t1 < t2 ));
515 using namespace util::quantities::time_literals;
523 static_assert(std::is_same_v<microsecond::quantity_t, util::quantities::microsecond>);
524 static_assert(std::is_same_v<microsecond::unit_t, util::quantities::microsecond::unit_t>);
526 static_assert(t1.quantity() == 6_us );
527 static_assert(t2.quantity() == -4_us );
528 static_assert(t1.value() == 6.0 );
529 static_assert(t2.value() == -4000.0 );
537 using namespace util::quantities::time_literals;
545 static_assert_type<microsecond>{cp1 + 3000_ns};
546 static_assert(cp1 + 3000_ns == 9_us);
548 static_assert_type<microsecond>{cp1 + ct};
549 static_assert(cp1 + ct == 9_us);
551 static_assert_type<microsecond>{cp1 - 3000_ns};
552 static_assert(cp1 - 3000_ns == 3_us);
554 static_assert_type<microsecond>{cp1 - ct};
555 static_assert(cp1 - ct == 3_us);
557 static_assert_type<microsecond>{+cp1};
558 static_assert(+cp1 == 6_us);
560 static_assert_type<microsecond>{-cp1};
561 static_assert(-cp1 == -6_us);
567 decltype(
auto) incr = (
p1 += 2000_ns);
568 static_assert_type<microsecond&>{incr};
569 BOOST_TEST(
p1 == 8_us);
570 BOOST_TEST(&incr == &
p1);
572 decltype(
auto) incr2 = (
p1 += t);
573 static_assert_type<microsecond&>{incr2};
574 BOOST_TEST(
p1 == 11_us);
575 BOOST_TEST(t == 3_us);
576 BOOST_TEST(&incr2 == &
p1);
578 decltype(
auto) decr = (
p1 -= 2000_ns);
579 static_assert_type<microsecond&>{decr};
580 BOOST_TEST(
p1 == 9_us);
581 BOOST_TEST(&decr == &
p1);
583 decltype(
auto) decr2 = (
p1 -= t);
584 static_assert_type<microsecond&>{decr2};
585 BOOST_TEST(
p1 == 6_us);
586 BOOST_TEST(t == 3_us);
587 BOOST_TEST(&decr2 == &
p1);
589 decltype(
auto) diff = (
p1 - p2);
590 static_assert_type<util::quantities::intervals::microseconds>{diff};
591 BOOST_TEST(
p1 == 6_us);
592 BOOST_TEST(p2 == -4_us);
593 BOOST_TEST(diff == 10_us);
void test_point_comparisons()
void test_interval_construction()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
microsecond microseconds
Alias for common language habits.
constexpr bool is_quantity_v
Trait: true if Q is a Quantity specialization.
constexpr bool is_interval_v
Trait: true if IV is a Interval specialization.
Defines point and interval variables based on quantities.
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
void test_point_operations()
constexpr bool has_unit_v
Trait: true if U is a ScaledUnit-based object.
An interval (duration, length, distance) between two quantity points.
void test_interval_operations()
constexpr bool has_quantity_v
Trait: true if Q is a Quantity-based object.
constexpr bool has_category_v
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Functions to help debugging by instrumenting code.
void test_point_construction()
Dimensioned variables representing space or time quantities.
nanosecond_as<> nanosecond
Type of time stored in nanoseconds, in double precision.
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
void test_point_queries()
constexpr bool is_interval_or_point_v
Trait: true if PT is a specialization of Interval or Point.
void test_interval_queries()
constexpr bool is_point_v
Trait: true if PT is a Point specialization.
physics associatedGroupsWithLeft p1
nanosecond nanoseconds
Alias for common language habits.
void test_interval_comparisons()