From eba38690cdf99fd48755c17a03b191a63aca0705 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 6 Jun 2026 19:43:06 +0100 Subject: [PATCH] Added tests for upper and lower case scintific format. --- test/test_to_string.cpp | 3 +++ test/test_to_u16string.cpp | 34 ++++++++++++++++++++++++++++++++++ test/test_to_u32string.cpp | 34 ++++++++++++++++++++++++++++++++++ test/test_to_u8string.cpp | 34 ++++++++++++++++++++++++++++++++++ test/test_to_wstring.cpp | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+) diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 17a9d982..a7fd04fa 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -677,6 +677,9 @@ namespace etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true)); CHECK(etl::string<64>(STR(" 1.00000e+3")) == s0); + etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::string<64>(STR(" 1.00000E+3")) == s0); + // Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision. etl::string<64> s1; etl::to_string(std::numeric_limits::max(), s1, Format().precision(5).width(15).right()); diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index c9b45ab3..7c26cd01 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -590,6 +590,9 @@ namespace etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true)); CHECK(etl::u16string<64>(STR(" 1.00000e+3")) == s0); + etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u16string<64>(STR(" 1.00000E+3")) == s0); + // Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision. etl::u16string<64> s1; etl::to_string(std::numeric_limits::max(), s1, Format().precision(5).width(15).right()); @@ -627,5 +630,36 @@ namespace CHECK(etl::u16string<64>(STR(" 0")) == s6); #endif } + + //************************************************************************* + TEST(test_issue_1436_case_support_for_nan_inf_in_to_string) + { + if (std::numeric_limits::is_iec559) + { + etl::u16string<64> s1; + etl::to_string(std::numeric_limits::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u16string<64>(STR(" nan")) == s1); + + etl::u16string<64> s2; + etl::to_string(std::numeric_limits::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u16string<64>(STR(" inf")) == s2); + + etl::u16string<64> s3; + etl::to_string(-std::numeric_limits::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u16string<64>(STR(" -inf")) == s3); + + etl::u16string<64> s4; + etl::to_string(std::numeric_limits::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u16string<64>(STR(" NAN")) == s4); + + etl::u16string<64> s5; + etl::to_string(std::numeric_limits::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u16string<64>(STR(" INF")) == s5); + + etl::u16string<64> s6; + etl::to_string(-std::numeric_limits::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u16string<64>(STR(" -INF")) == s6); + } + } } } // namespace diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index 22d19256..1d5bd662 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -593,6 +593,9 @@ namespace etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true)); CHECK(etl::u32string<64>(STR(" 1.00000e+3")) == s0); + etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u32string<64>(STR(" 1.00000E+3")) == s0); + // Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision. etl::u32string<64> s1; etl::to_string(std::numeric_limits::max(), s1, Format().precision(5).width(15).right()); @@ -630,5 +633,36 @@ namespace CHECK(etl::u32string<64>(STR(" 0")) == s6); #endif } + + //************************************************************************* + TEST(test_issue_1436_case_support_for_nan_inf_in_to_string) + { + if (std::numeric_limits::is_iec559) + { + etl::u32string<64> s1; + etl::to_string(std::numeric_limits::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u32string<64>(STR(" nan")) == s1); + + etl::u32string<64> s2; + etl::to_string(std::numeric_limits::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u32string<64>(STR(" inf")) == s2); + + etl::u32string<64> s3; + etl::to_string(-std::numeric_limits::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u32string<64>(STR(" -inf")) == s3); + + etl::u32string<64> s4; + etl::to_string(std::numeric_limits::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u32string<64>(STR(" NAN")) == s4); + + etl::u32string<64> s5; + etl::to_string(std::numeric_limits::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u32string<64>(STR(" INF")) == s5); + + etl::u32string<64> s6; + etl::to_string(-std::numeric_limits::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u32string<64>(STR(" -INF")) == s6); + } + } } } // namespace diff --git a/test/test_to_u8string.cpp b/test/test_to_u8string.cpp index 207b64b5..b6a69447 100644 --- a/test/test_to_u8string.cpp +++ b/test/test_to_u8string.cpp @@ -592,6 +592,9 @@ namespace etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true)); CHECK(etl::u8string<64>(STR(" 1.00000e+3")) == s0); + etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u8string<64>(STR(" 1.00000E+3")) == s0); + // Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision. etl::u8string<64> s1; etl::to_string(std::numeric_limits::max(), s1, Format().precision(5).width(15).right()); @@ -629,6 +632,37 @@ namespace CHECK(etl::u8string<64>(STR(" 0")) == s6); #endif } + + //************************************************************************* + TEST(test_issue_1436_case_support_for_nan_inf_in_to_string) + { + if (std::numeric_limits::is_iec559) + { + etl::u8string<64> s1; + etl::to_string(std::numeric_limits::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u8string<64>(STR(" nan")) == s1); + + etl::u8string<64> s2; + etl::to_string(std::numeric_limits::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u8string<64>(STR(" inf")) == s2); + + etl::u8string<64> s3; + etl::to_string(-std::numeric_limits::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::u8string<64>(STR(" -inf")) == s3); + + etl::u8string<64> s4; + etl::to_string(std::numeric_limits::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u8string<64>(STR(" NAN")) == s4); + + etl::u8string<64> s5; + etl::to_string(std::numeric_limits::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u8string<64>(STR(" INF")) == s5); + + etl::u8string<64> s6; + etl::to_string(-std::numeric_limits::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::u8string<64>(STR(" -INF")) == s6); + } + } } } // namespace diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index 0ea9166f..a0126657 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -656,6 +656,9 @@ namespace etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true)); CHECK(etl::wstring<64>(STR(" 1.00000e+3")) == s0); + etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::wstring<64>(STR(" 1.00000E+3")) == s0); + // Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision. etl::wstring<64> s1; etl::to_string(std::numeric_limits::max(), s1, Format().precision(5).width(15).right()); @@ -693,5 +696,36 @@ namespace CHECK(etl::wstring<64>(STR(" 0")) == s6); #endif } + + //************************************************************************* + TEST(test_issue_1436_case_support_for_nan_inf_in_to_string) + { + if (std::numeric_limits::is_iec559) + { + etl::wstring<64> s1; + etl::to_string(std::numeric_limits::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::wstring<64>(STR(" nan")) == s1); + + etl::wstring<64> s2; + etl::to_string(std::numeric_limits::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::wstring<64>(STR(" inf")) == s2); + + etl::wstring<64> s3; + etl::to_string(-std::numeric_limits::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false)); + CHECK(etl::wstring<64>(STR(" -inf")) == s3); + + etl::wstring<64> s4; + etl::to_string(std::numeric_limits::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::wstring<64>(STR(" NAN")) == s4); + + etl::wstring<64> s5; + etl::to_string(std::numeric_limits::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::wstring<64>(STR(" INF")) == s5); + + etl::wstring<64> s6; + etl::to_string(-std::numeric_limits::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true)); + CHECK(etl::wstring<64>(STR(" -INF")) == s6); + } + } } } // namespace