Skip to content

Commit

Permalink
Default StringMaker<FloatingPointType>::precision to max_digits10
Browse files Browse the repository at this point in the history
`max_digits10` is the number of decimal digits that the type _can_
represent, in other words, the number of decimal digits needed to
disambiguate any two floating point numbers when serialized to
a string.
  • Loading branch information
horenmar committed Apr 30, 2024
1 parent efb3968 commit ef71358
Show file tree
Hide file tree
Showing 18 changed files with 2,109 additions and 1,071 deletions.
4 changes: 2 additions & 2 deletions src/catch2/catch_tostring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ std::string StringMaker<unsigned char>::convert(unsigned char value) {
return ::Catch::Detail::stringify(static_cast<char>(value));
}

int StringMaker<float>::precision = 5;
int StringMaker<float>::precision = std::numeric_limits<float>::max_digits10;

std::string StringMaker<float>::convert(float value) {
return Detail::fpToString(value, precision) + 'f';
}

int StringMaker<double>::precision = 10;
int StringMaker<double>::precision = std::numeric_limits<double>::max_digits10;

std::string StringMaker<double>::convert(double value) {
return Detail::fpToString(value, precision);
Expand Down
406 changes: 285 additions & 121 deletions tests/SelfTest/Baselines/compact.sw.approved.txt

Large diffs are not rendered by default.

406 changes: 285 additions & 121 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions tests/SelfTest/Baselines/console.std.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -434,27 +434,31 @@ with expansion:
Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one == Approx( 9.11f ) )
with expansion:
9.1f == Approx( 9.1099996567 )
9.100000381f
==
Approx( 9.10999965667724609 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one == Approx( 9.0f ) )
with expansion:
9.1f == Approx( 9.0 )
9.100000381f == Approx( 9.0 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one == Approx( 1 ) )
with expansion:
9.1f == Approx( 1.0 )
9.100000381f == Approx( 1.0 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one == Approx( 0 ) )
with expansion:
9.1f == Approx( 0.0 )
9.100000381f == Approx( 0.0 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.double_pi == Approx( 3.1415 ) )
with expansion:
3.1415926535 == Approx( 3.1415 )
3.14159265350000005
==
Approx( 3.14150000000000018 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.str_hello == "goodbye" )
Expand All @@ -479,7 +483,9 @@ with expansion:
Condition.tests.cpp:<line number>: FAILED:
CHECK( x == Approx( 1.301 ) )
with expansion:
1.3 == Approx( 1.301 )
1.30000000000000027
==
Approx( 1.30099999999999993 )

-------------------------------------------------------------------------------
Equals string matcher
Expand Down Expand Up @@ -696,12 +702,16 @@ with expansion:
Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one != Approx( 9.1f ) )
with expansion:
9.1f != Approx( 9.1000003815 )
9.100000381f
!=
Approx( 9.10000038146972656 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.double_pi != Approx( 3.1415926535 ) )
with expansion:
3.1415926535 != Approx( 3.1415926535 )
3.14159265350000005
!=
Approx( 3.14159265350000005 )

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.str_hello != "hello" )
Expand Down Expand Up @@ -855,17 +865,17 @@ with expansion:
Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one < 9 )
with expansion:
9.1f < 9
9.100000381f < 9

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one > 10 )
with expansion:
9.1f > 10
9.100000381f > 10

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.float_nine_point_one > 9.2 )
with expansion:
9.1f > 9.2
9.100000381f > 9.19999999999999929

Condition.tests.cpp:<line number>: FAILED:
CHECK( data.str_hello > "hello" )
Expand Down Expand Up @@ -1060,7 +1070,7 @@ Exception.tests.cpp:<line number>

Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message:
3.14
3.14000000000000012

-------------------------------------------------------------------------------
Vector Approx matcher -- failing
Expand Down

0 comments on commit ef71358

Please sign in to comment.