91 const bool show_double =
true;
94 INFO_STR(
"a "+a.
to_string(show_double)+
" + b "+b.
to_string(show_double)+
" = "+(a+b).to_string(show_double));
95 INFO_STR(
"a "+a.
to_string(show_double)+
" - b "+b.
to_string(show_double)+
" = "+(a-b).to_string(show_double));
96 INFO_STR(
"a "+a.
to_string(show_double)+
" * b "+b.
to_string(show_double)+
" = "+(a*b).to_string(show_double));
97 INFO_STR(
"a "+a.
to_string(show_double)+
" / b "+b.
to_string(show_double)+
" = "+(a/b).to_string(show_double));
99 const double epsilon = std::numeric_limits<double>::epsilon();
102 if( std::abs( ad - bd ) <= epsilon ) {
104 REQUIRE( !(a != b) );
107 }
else if( std::abs( ad - bd ) > epsilon ) {
109 REQUIRE( !(a == b) );
110 if( ad - bd < -epsilon ) {
126 REQUIRE_MSG(
"exp "+
to_string(exp_max)+
" == has "+
to_string(has_max), exp_max == has_max );
127 REQUIRE_MSG(
"exp "+
to_string(exp_min)+
" == has "+
to_string(has_min), exp_min == has_min );
128 REQUIRE( has_max >= has_min );
129 REQUIRE( has_min <= has_max );
133 const double exp_double = a.
to_double() + b.to_double();
134 const double has_double = has_sum.
to_double();
135 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
136 REQUIRE_MSG(
"exp "+
to_string(exp_sum)+
" == has "+
to_string(has_sum), exp_sum == has_sum );
140 const double exp_double = a.
to_double() - b.to_double();
141 const double has_double = has_diff.
to_double();
142 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
143 REQUIRE_MSG(
"exp "+
to_string(exp_diff)+
" == has "+
to_string(has_diff), exp_diff == has_diff );
147 const double exp_double = a.
to_double() * b.to_double();
148 const double has_double = has_mul.
to_double();
149 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
150 REQUIRE_MSG(
"exp "+
to_string(exp_mul)+
" == has "+
to_string(has_mul), exp_mul == has_mul);
155 const double has_double = has_div.
to_double();
156 REQUIRE_MSG(
"exp "+std::to_string(exp_double)+
" == has "+std::to_string(has_double),
abs( exp_double - has_double ) <= std::numeric_limits<double>::epsilon() );
157 REQUIRE_MSG(
"exp "+
to_string(exp_div)+
" == has "+
to_string(has_div), exp_div == has_div);
164 for(count = 0; i < lim; i+=step, ++count) { }
167 REQUIRE( 10 == count );
171 REQUIRE( i == lim + step );
173 if( !std::is_unsigned_v<int_type> ) {
178 for(count = 0; i > lim; i-=step, ++count) { }
181 REQUIRE( 10 == count );
185 REQUIRE( i == lim - step );
193 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) );
196 std::chrono::duration<Rep, Period> d = a.
to_duration( dur_ref );
197 INFO_STR(
" fraction-1 " + a.
to_string(
true) +
" -> duration_count " + std::to_string( d_num ) +
", duration " + std::to_string( d.count() ) );
198 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) );
202 INFO_STR(
" reconverted fraction-2 " + b.
to_string(
true));
203 REQUIRE( exp_count == d_num );
204 REQUIRE( exp_count == d.count() );
209 typename std::chrono::duration<Rep, Period>::rep d_count = a.to_duration_count( dur_ref );
210 auto d = a.to_auto_duration();
211 INFO_STR(
" fraction-2 " + a.
to_string(
true) +
" -> duration_count " + std::to_string( d_count ) +
", duration " + std::to_string( d.count() ) );
212 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) );
213 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) );
217 INFO_STR(
" reconverted fraction-2 " + b.
to_string(
true));
218 REQUIRE( exp_count == d_count );
219 REQUIRE( exp_count == d.count() );
428TEST_CASE(
"Fraction Arithmetic Test 02",
"[integer][fraction]" ) {
513 const std::chrono::milliseconds::rep exp_count = 100;
515 test_duration(a, std::chrono::milliseconds::zero(), exp_count);
518 const std::chrono::nanoseconds::rep exp_count = -50;
520 test_duration(a, std::chrono::nanoseconds::zero(), exp_count);
523 const std::chrono::hours::rep exp_count = 24;
530 REQUIRE( 1_i64 / fps == refresh_rate );
531 REQUIRE( fps == 1_i64 / refresh_rate );
532 REQUIRE( 2_i64 * fps == 1_i64 / ( refresh_rate / 2_i64 ) );
535 REQUIRE( 1_m / 2_one == 500_one * 1_u );
542 REQUIRE( 60_s == 1_min );
545 REQUIRE( 24_h == 1_d );
551 REQUIRE( m == h/4_i64 );
558 REQUIRE( 1000_s == a );
559 REQUIRE( 1000_ns == b );
561 fraction_i64 exp_c ( 1'000'000'000lu + 1lu, 1'000'000lu );
562 REQUIRE( exp_c == c );
617TEST_CASE(
"Fraction Time Arithmetic Add Test 03.1",
"[fraction][fraction_timespec][add]" ) {
618 const int64_t ns_per_sec = 1'000'000'000_i64;
628 REQUIRE( ( a + b ) == exp_sum );
638 REQUIRE( ( a - b ) == exp_sum );
648 REQUIRE( ( a - b ) == exp_sum );
655 REQUIRE( ( a + b ) == exp_sum );
665 REQUIRE( ( a + b ) == exp_sum );
675 REQUIRE( ( a + b ) == exp_sum );
682 INFO_STR(
" a " + a.to_string() );
683 INFO_STR(
" b " + b.to_string() );
685 REQUIRE( ( a + b ) == exp_sum );
692 INFO_STR(
" a " + a.to_string() );
693 INFO_STR(
" b " + b.to_string() );
695 REQUIRE( ( a + b ) == exp_sum );
702 REQUIRE( ( a + b ) == exp_sum );
709 REQUIRE( ( a + b ) == exp_sum );
716 INFO_STR(
" a " + a.to_string() );
717 INFO_STR(
" b " + b.to_string() );
719 REQUIRE( ( a + b ) == exp_sum );
726 INFO_STR(
" a " + a.to_string() );
727 INFO_STR(
" b " + b.to_string() );
729 REQUIRE( ( a + b ) == exp_sum );
736 INFO_STR(
" a " + a.to_string() );
737 INFO_STR(
" b " + b.to_string() );
739 REQUIRE( ( a + b ) == exp_sum );
743TEST_CASE(
"Fraction Time Arithmetic Sub Test 03.2",
"[fraction][fraction_timespec][sub]" ) {
756 REQUIRE( a.
tv_sec == -5 );
771 REQUIRE( a.
tv_nsec == 600000000_i64 );
778 REQUIRE( a.
tv_nsec == -600000000_i64 );
787 INFO_STR(
" exp " + exp_sum.
to_string() );
789 REQUIRE( ( a - b ) == exp_sum );
796 INFO_STR(
" a " + a.to_string() );
797 INFO_STR(
" b " + b.to_string() );
798 INFO_STR(
" exp " + exp_sum.to_string() );
800 REQUIRE( ( a - b ) == exp_sum );
807 REQUIRE( ( a - b ) == exp_sum );
814 REQUIRE( ( a - b ) == exp_sum );
821 INFO_STR(
" a " + a.to_string() );
822 INFO_STR(
" b " + b.to_string() );
824 REQUIRE( ( a - b ) == exp_sum );
831 INFO_STR(
" a " + a.to_string() );
832 INFO_STR(
" b " + b.to_string() );
834 REQUIRE( ( a - b ) == exp_sum );
842 REQUIRE( ( a - b ) == exp_sum );
849 INFO_STR(
" a " + a.to_string() );
850 INFO_STR(
" b " + b.to_string() );
852 REQUIRE( ( a - b ) == exp_sum );
859 INFO_STR(
" a " + a.to_string() );
860 INFO_STR(
" b " + b.to_string() );
862 REQUIRE( ( a - b ) == exp_sum );
869 INFO_STR(
" a " + a.to_string() );
870 INFO_STR(
" b " + b.to_string() );
872 REQUIRE( ( a - b ) == exp_sum );
931TEST_CASE(
"Fraction Time Conversion Test 05.01",
"[fraction_timespec][time]" ) {
956 int64_t utcOffsetSec;
size_t consumedChars;
958 REQUIRE(0 == utcOffsetSec); REQUIRE( 8 == consumedChars);
961 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
964 REQUIRE(0 == utcOffsetSec); REQUIRE(22 == consumedChars);
967 REQUIRE(0 == utcOffsetSec); REQUIRE(20 == consumedChars);
970 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
973 REQUIRE(0 == utcOffsetSec); REQUIRE(19 == consumedChars);
976 REQUIRE(0 == utcOffsetSec); REQUIRE(24 == consumedChars);
997 REQUIRE(t00a - onesec == t00);
998 REQUIRE(t00b - onesec_onemilli == t00);
1040 REQUIRE(tX0 + p1h + p2m == tX1);
1041 REQUIRE(tX0 - p1h - p2m == tX2);
1048 int64_t t0_offset;
size_t consumedChars;
1100 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1104 REQUIRE(0 == t0_offset);
1105 REQUIRE(21 == consumedChars);
1109 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1113 REQUIRE(t0_offset == 60*60_i64 + 2*60_i64);
1114 REQUIRE(32 == consumedChars);
1117 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1121 REQUIRE(t0_offset == -60*60_i64 - 2*60_i64);
1122 REQUIRE(32 == consumedChars);
1127 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1131 REQUIRE(0 == t0_offset);
1132 REQUIRE(7 == consumedChars);
1137 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1141 REQUIRE(0 == t0_offset);
1142 REQUIRE(14 == consumedChars);
1147 int64_t t0_offset=987654321_i64;
size_t consumedChars=2783964772;
1151 REQUIRE(0 == t0_offset);
1152 REQUIRE(21 == consumedChars);
1155 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1158 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1159 REQUIRE(39 == consumedChars);
1162 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1165 REQUIRE(offset == 60*60_i64 + 2*60_i64);
1166 REQUIRE(38 == consumedChars);
1169 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1171 REQUIRE(
true == t0.
isZero());
1172 REQUIRE(offset == 0);
1173 REQUIRE(0 == consumedChars);
1176 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1178 REQUIRE(
true == t0.
isZero());
1179 REQUIRE(offset == 0);
1180 REQUIRE(0 == consumedChars);
1183 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1186 REQUIRE(offset == 0);
1187 REQUIRE(30 == consumedChars);
1190 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1193 REQUIRE(offset == 0);
1194 REQUIRE(10 == consumedChars);
1197 int64_t offset=987654321_i64;
size_t consumedChars=2783964772;
1200 REQUIRE(offset == 60*60_i64);
1201 REQUIRE(36 == consumedChars);