Default StringMaker<FloatingPointType>::precision to max_digits10

`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.
This commit is contained in:
Martin Hořeňovský
2024-04-30 16:43:05 +02:00
parent efb39689d9
commit ef713582d2
18 changed files with 2109 additions and 1071 deletions

View File

@@ -124,8 +124,8 @@ TEST_CASE("Precision of floating point stringification can be set", "[toString][
const auto oldPrecision = sm::precision;
const float testFloat = 1.12345678901234567899f;
auto str1 = sm::convert(testFloat);
sm::precision = 5;
auto str1 = sm::convert( testFloat );
// "1." prefix = 2 chars, f suffix is another char
CHECK(str1.size() == 3 + 5);

View File

@@ -29,8 +29,8 @@ TEST_CASE( "tuple<int>", "[toString][tuple]" )
TEST_CASE( "tuple<float,int>", "[toString][tuple]" )
{
typedef std::tuple<float,int> type;
CHECK( "1.2f" == ::Catch::Detail::stringify(float(1.2)) );
CHECK( "{ 1.2f, 0 }" == ::Catch::Detail::stringify(type{1.2f,0}) );
CHECK( "1.5f" == ::Catch::Detail::stringify(float(1.5)) );
CHECK( "{ 1.5f, 0 }" == ::Catch::Detail::stringify(type{1.5f,0}) );
}
TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
@@ -42,8 +42,8 @@ TEST_CASE( "tuple<string,string>", "[toString][tuple]" )
TEST_CASE( "tuple<tuple<int>,tuple<>,float>", "[toString][tuple]" )
{
typedef std::tuple<std::tuple<int>,std::tuple<>,float> type;
type value { std::tuple<int>{42}, {}, 1.2f };
CHECK( "{ { 42 }, { }, 1.2f }" == ::Catch::Detail::stringify(value) );
type value { std::tuple<int>{42}, {}, 1.5f };
CHECK( "{ { 42 }, { }, 1.5f }" == ::Catch::Detail::stringify(value) );
}
TEST_CASE( "tuple<nullptr,int,const char *>", "[approvals][toString][tuple]" ) {