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 );
191 INFO_STR(
" given duration: ( " + std::to_string(dur_ref.count()) +
" * " + std::to_string(Period::num) +
" = " + std::to_string(dur_ref.count() * Period::num) +
" ) / " + std::to_string(Period::den) );
194 std::chrono::duration<Rep, Period> d = a.
to_duration( dur_ref );
195 INFO_STR(
" fraction-1 " + a.
toString(
true) +
" -> duration_count " + std::to_string( d_num ) +
", duration " + std::to_string( d.count() ) );
196 INFO_STR(
" resulting duration-1: ( " + std::to_string(d.count()) +
" * " + std::to_string(Period::num) +
" = " + std::to_string(d.count() * Period::num) +
" ) / " + std::to_string(Period::den) );
200 INFO_STR(
" reconverted fraction-2 " + b.
toString(
true));
201 REQUIRE( exp_count == d_num );
202 REQUIRE( exp_count == d.count() );
207 typename std::chrono::duration<Rep, Period>::rep d_count = a.to_duration_count( dur_ref );
208 auto d = a.to_auto_duration();
209 INFO_STR(
" fraction-2 " + a.
toString(
true) +
" -> duration_count " + std::to_string( d_count ) +
", duration " + std::to_string( d.count() ) );
210 INFO_STR(
" resulting duration-2: ( " + std::to_string(d.count()) +
" * " + std::to_string(Period::num) +
" = " + std::to_string(d.count() * Period::num) +
" ) / " + std::to_string(Period::den) );
211 INFO_STR(
" resulting duration-2: ( " + std::to_string(d.count()) +
" * " + std::to_string(
decltype(d)::num) +
" = " + std::to_string(d.count() *
decltype(d)::num) +
" ) / " + std::to_string(
decltype(d)::den) );
215 INFO_STR(
" reconverted fraction-2 " + b.
toString(
true));
216 REQUIRE( exp_count == d_count );
217 REQUIRE( exp_count == d.count() );
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 );
742TEST_CASE(
"Fraction Time Arithmetic Sub Test 03.2",
"[fraction][fraction_timespec][sub]" ) {
755 REQUIRE( a.
tv_sec == -5 );
770 REQUIRE( a.
tv_nsec == 600000000_i64 );
777 REQUIRE( a.
tv_nsec == -600000000_i64 );
786 INFO_STR(
" exp " + exp_sum.
toString() );
787 INFO_STR(
" a-b " + (a-b).toString() );
788 REQUIRE( ( a - b ) == exp_sum );
795 INFO_STR(
" a " + a.toString() );
796 INFO_STR(
" b " + b.toString() );
797 INFO_STR(
" exp " + exp_sum.toString() );
798 INFO_STR(
" a-b " + (a-b).toString() );
799 REQUIRE( ( a - b ) == exp_sum );
806 REQUIRE( ( a - b ) == exp_sum );
813 REQUIRE( ( a - b ) == exp_sum );
820 INFO_STR(
" a " + a.toString() );
821 INFO_STR(
" b " + b.toString() );
822 INFO_STR(
" a-b " + (a-b).toString() );
823 REQUIRE( ( a - b ) == exp_sum );
830 INFO_STR(
" a " + a.toString() );
831 INFO_STR(
" b " + b.toString() );
832 INFO_STR(
" a-b " + (a-b).toString() );
833 REQUIRE( ( a - b ) == exp_sum );
841 REQUIRE( ( a - b ) == exp_sum );
848 INFO_STR(
" a " + a.toString() );
849 INFO_STR(
" b " + b.toString() );
850 INFO_STR(
" a-b " + (a-b).toString() );
851 REQUIRE( ( a - b ) == exp_sum );
858 INFO_STR(
" a " + a.toString() );
859 INFO_STR(
" b " + b.toString() );
860 INFO_STR(
" a-b " + (a-b).toString() );
861 REQUIRE( ( a - b ) == exp_sum );
868 INFO_STR(
" a " + a.toString() );
869 INFO_STR(
" b " + b.toString() );
870 INFO_STR(
" a-b " + (a-b).toString() );
871 REQUIRE( ( a - b ) == exp_sum );
930TEST_CASE(
"Fraction Time Conversion Test 05.01",
"[fraction_timespec][time]" ) {
955 int64_t utcOffsetSec;
size_t consumedChars;
957 REQUIRE(0 == utcOffsetSec); REQUIRE( 8 == consumedChars);
960 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
963 REQUIRE(0 == utcOffsetSec); REQUIRE(22 == consumedChars);
966 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
969 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
972 REQUIRE(0 == utcOffsetSec); REQUIRE(19 == consumedChars);
975 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
996 REQUIRE(t00a - onesec == t00);
997 REQUIRE(t00b - onesec_onemilli == t00);
1039 REQUIRE(tX0 + p1h + p2m == tX1);
1040 REQUIRE(tX0 - p1h - p2m == tX2);
1047 int64_t t0_offset;
size_t consumedChars;
1099 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1103 REQUIRE(0 == t0_offset);
1104 REQUIRE(21 == consumedChars);
1108 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1112 REQUIRE(t0_offset == 60*60_i64 + 2*60_i64);
1113 REQUIRE(32 == consumedChars);
1116 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1120 REQUIRE(t0_offset == -60*60_i64 - 2*60_i64);
1121 REQUIRE(32 == consumedChars);
1126 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1130 REQUIRE(0 == t0_offset);
1131 REQUIRE(7 == consumedChars);
1136 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1140 REQUIRE(0 == t0_offset);
1141 REQUIRE(14 == consumedChars);
1146 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1150 REQUIRE(0 == t0_offset);
1151 REQUIRE(21 == consumedChars);
1154 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1157 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1158 REQUIRE(39 == consumedChars);
1161 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1164 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1165 REQUIRE(38 == consumedChars);
1168 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1172 REQUIRE(
true == t0.
isZero());
1173 REQUIRE(offset == 0);
1174 REQUIRE(0 == consumedChars);
1177 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1179 REQUIRE(
true == t0.
isZero());
1180 REQUIRE(offset == 0);
1181 REQUIRE(0 == consumedChars);
1184 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1187 REQUIRE(offset == 0);
1188 REQUIRE(30 == consumedChars);
1191 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1194 REQUIRE(offset == 0);
1195 REQUIRE(10 == consumedChars);
1198 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1201 REQUIRE(offset == 60*60_i64);
1202 REQUIRE(36 == consumedChars);