89 const bool show_double =
true;
90 INFO_STR(
"max(a "+a.
toString(show_double)+
", b "+b.
toString(show_double)+
") = "+
max(a,b).toString(show_double));
91 INFO_STR(
"min(a "+a.
toString(show_double)+
", b "+b.
toString(show_double)+
") = "+
min(a,b).toString(show_double));
92 INFO_STR(
"a "+a.
toString(show_double)+
" + b "+b.
toString(show_double)+
" = "+(a+b).toString(show_double));
93 INFO_STR(
"a "+a.
toString(show_double)+
" - b "+b.
toString(show_double)+
" = "+(a-b).toString(show_double));
94 INFO_STR(
"a "+a.
toString(show_double)+
" * b "+b.
toString(show_double)+
" = "+(a*b).toString(show_double));
95 INFO_STR(
"a "+a.
toString(show_double)+
" / b "+b.
toString(show_double)+
" = "+(a/b).toString(show_double));
97 const double epsilon = std::numeric_limits<double>::epsilon();
100 if( std::abs( ad - bd ) <= epsilon ) {
102 REQUIRE( !(a != b) );
105 }
else if( std::abs( ad - bd ) > epsilon ) {
107 REQUIRE( !(a == b) );
108 if( ad - bd < -epsilon ) {
124 REQUIRE_MSG(
"exp "+
to_string(exp_max)+
" == has "+
to_string(has_max), exp_max == has_max );
125 REQUIRE_MSG(
"exp "+
to_string(exp_min)+
" == has "+
to_string(has_min), exp_min == has_min );
126 REQUIRE( has_max >= has_min );
127 REQUIRE( has_min <= has_max );
131 const double exp_double = a.
to_double() + b.to_double();
132 const double has_double = has_sum.
to_double();
133 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
134 REQUIRE_MSG(
"exp "+
to_string(exp_sum)+
" == has "+
to_string(has_sum), exp_sum == has_sum );
138 const double exp_double = a.
to_double() - b.to_double();
139 const double has_double = has_diff.
to_double();
140 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
141 REQUIRE_MSG(
"exp "+
to_string(exp_diff)+
" == has "+
to_string(has_diff), exp_diff == has_diff );
145 const double exp_double = a.
to_double() * b.to_double();
146 const double has_double = has_mul.
to_double();
147 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
148 REQUIRE_MSG(
"exp "+
to_string(exp_mul)+
" == has "+
to_string(has_mul), exp_mul == has_mul);
153 const double has_double = has_div.
to_double();
154 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
155 REQUIRE_MSG(
"exp "+
to_string(exp_div)+
" == has "+
to_string(has_div), exp_div == has_div);
162 for(count = 0; i < lim; i+=step, ++count) { }
165 REQUIRE( 10 == count );
169 REQUIRE( i == lim + step );
171 if( !std::is_unsigned_v<int_type> ) {
176 for(count = 0; i > lim; i-=step, ++count) { }
179 REQUIRE( 10 == count );
183 REQUIRE( i == lim - step );
427TEST_CASE(
"Fraction Arithmetic Test 02",
"[integer][fraction]" ) {
512 const std::chrono::milliseconds::rep exp_count = 100;
514 test_duration(a, std::chrono::milliseconds::zero(), exp_count);
517 const std::chrono::nanoseconds::rep exp_count = -50;
519 test_duration(a, std::chrono::nanoseconds::zero(), exp_count);
522 const std::chrono::hours::rep exp_count = 24;
529 REQUIRE( 1_i64 / fps == refresh_rate );
530 REQUIRE( fps == 1_i64 / refresh_rate );
531 REQUIRE( 2_i64 * fps == 1_i64 / ( refresh_rate / 2_i64 ) );
534 REQUIRE( 1_m / 2_one == 500_one * 1_u );
541 REQUIRE( 60_s == 1_min );
544 REQUIRE( 24_h == 1_d );
550 REQUIRE( m == h/4_i64 );
557 REQUIRE( 1000_s == a );
558 REQUIRE( 1000_ns == b );
560 fraction_i64 exp_c ( 1'000'000'000lu + 1lu, 1'000'000lu );
561 REQUIRE( exp_c == c );
616TEST_CASE(
"Fraction Time Arithmetic Add Test 03.1",
"[fraction][fraction_timespec][add]" ) {
617 const int64_t ns_per_sec = 1'000'000'000_i64;
626 INFO_STR(
" a+b " + (a+b).toString() );
627 REQUIRE( ( a + b ) == exp_sum );
636 INFO_STR(
" a-b " + (a-b).toString() );
637 REQUIRE( ( a - b ) == exp_sum );
646 INFO_STR(
" a-b " + (a-b).toString() );
647 REQUIRE( ( a - b ) == exp_sum );
654 REQUIRE( ( a + b ) == exp_sum );
663 INFO_STR(
" a+b " + (a+b).toString() );
664 REQUIRE( ( a + b ) == exp_sum );
673 INFO_STR(
" a+b " + (a+b).toString() );
674 REQUIRE( ( a + b ) == exp_sum );
681 INFO_STR(
" a " + a.toString() );
682 INFO_STR(
" b " + b.toString() );
683 INFO_STR(
" a+b " + (a+b).toString() );
684 REQUIRE( ( a + b ) == exp_sum );
691 INFO_STR(
" a " + a.toString() );
692 INFO_STR(
" b " + b.toString() );
693 INFO_STR(
" a+b " + (a+b).toString() );
694 REQUIRE( ( a + b ) == exp_sum );
701 REQUIRE( ( a + b ) == exp_sum );
708 REQUIRE( ( a + b ) == exp_sum );
715 INFO_STR(
" a " + a.toString() );
716 INFO_STR(
" b " + b.toString() );
717 INFO_STR(
" a+b " + (a+b).toString() );
718 REQUIRE( ( a + b ) == exp_sum );
725 INFO_STR(
" a " + a.toString() );
726 INFO_STR(
" b " + b.toString() );
727 INFO_STR(
" a+b " + (a+b).toString() );
728 REQUIRE( ( a + b ) == exp_sum );
735 INFO_STR(
" a " + a.toString() );
736 INFO_STR(
" b " + b.toString() );
737 INFO_STR(
" a+b " + (a+b).toString() );
738 REQUIRE( ( a + b ) == exp_sum );
930TEST_CASE(
"Fraction Time Conversion Test 05.01",
"[fraction_timespec][time]" ) {
959 int64_t utcOffsetSec;
size_t consumedChars;
962 REQUIRE(0 == utcOffsetSec); REQUIRE( 8 == consumedChars);
964 REQUIRE(t00 == zero);
968 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
970 REQUIRE(tt == onesec);
971 REQUIRE(tt - onesec == zero);
975 REQUIRE(0 == utcOffsetSec);
976 REQUIRE(22 == consumedChars);
978 REQUIRE(tt == onesec_onedeci);
979 REQUIRE(tt - onesec_onedeci == zero);
983 REQUIRE(0 == utcOffsetSec);
984 REQUIRE(24 == consumedChars);
986 REQUIRE(tt == onesec_onedeci);
987 REQUIRE(tt - onesec_onedeci == zero);
991 REQUIRE(0 == utcOffsetSec);
992 REQUIRE(30 == consumedChars);
994 REQUIRE(tt == onesec_onedeci);
995 REQUIRE(tt - onesec_onedeci == zero);
999 REQUIRE(0 == utcOffsetSec);
1000 REQUIRE(24 == consumedChars);
1002 REQUIRE(tt == onesec_onemilli);
1003 REQUIRE(tt - onesec_onemilli == zero);
1007 REQUIRE(0 == utcOffsetSec);
1008 REQUIRE(30 == consumedChars);
1010 REQUIRE(tt == onesec_onemilli);
1011 REQUIRE(tt - onesec_onemilli == zero);
1015 REQUIRE(0 == utcOffsetSec);
1016 REQUIRE(27 == consumedChars);
1018 REQUIRE(tt == onesec_onemicro);
1019 REQUIRE(tt - onesec_onemicro == zero);
1023 REQUIRE(0 == utcOffsetSec);
1024 REQUIRE(30 == consumedChars);
1026 REQUIRE(tt == onesec_onemicro);
1027 REQUIRE(tt - onesec_onemicro == zero);
1031 REQUIRE(0 == utcOffsetSec);
1032 REQUIRE(30 == consumedChars);
1034 REQUIRE(tt == onesec_onenano);
1035 REQUIRE(tt - onesec_onenano == zero);
1039 REQUIRE(0 == utcOffsetSec);
1040 REQUIRE(30 == consumedChars);
1042 REQUIRE(tt == onesec_decimillimicronano);
1043 REQUIRE(tt - onesec_decimillimicronano == zero);
1047 int64_t utcOffsetSec;
size_t consumedChars;
1050 REQUIRE(0 == utcOffsetSec); REQUIRE( 8 == consumedChars);
1054 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
1057 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
1060 REQUIRE(0 == utcOffsetSec); REQUIRE(19 == consumedChars);
1063 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
1079 REQUIRE(tX0 == t00);
1080 REQUIRE(tX1 == t01);
1081 REQUIRE(tX1 == t03);
1082 REQUIRE(tX2 == t02);
1083 REQUIRE(tX2 == t04);
1125 REQUIRE(tX0 + p1h + p2m == tX1);
1126 REQUIRE(tX0 - p1h - p2m == tX2);
1133 int64_t t0_offset;
size_t consumedChars;
1185 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1189 REQUIRE(0 == t0_offset);
1190 REQUIRE(21 == consumedChars);
1194 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1198 REQUIRE(t0_offset == 60*60_i64 + 2*60_i64);
1199 REQUIRE(32 == consumedChars);
1202 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1206 REQUIRE(t0_offset == -60*60_i64 - 2*60_i64);
1207 REQUIRE(32 == consumedChars);
1212 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1216 REQUIRE(0 == t0_offset);
1217 REQUIRE(7 == consumedChars);
1222 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1226 REQUIRE(0 == t0_offset);
1227 REQUIRE(14 == consumedChars);
1232 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1236 REQUIRE(0 == t0_offset);
1237 REQUIRE(21 == consumedChars);
1240 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1243 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1244 REQUIRE(39 == consumedChars);
1247 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1250 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1251 REQUIRE(38 == consumedChars);
1254 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1258 REQUIRE(
true == t0.
isZero());
1259 REQUIRE(offset == 0);
1260 REQUIRE(0 == consumedChars);
1263 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1265 REQUIRE(
true == t0.
isZero());
1266 REQUIRE(offset == 0);
1267 REQUIRE(0 == consumedChars);
1270 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1273 REQUIRE(offset == 0);
1274 REQUIRE(30 == consumedChars);
1277 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1280 REQUIRE(offset == 0);
1281 REQUIRE(10 == consumedChars);
1284 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1287 REQUIRE(offset == 60*60_i64);
1288 REQUIRE(36 == consumedChars);