mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 08:26:04 +08:00
Added tests for upper and lower case scintific format.
This commit is contained in:
parent
c34197ab2b
commit
eba38690cd
@ -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<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
|
||||
@ -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<double>::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<double>::is_iec559)
|
||||
{
|
||||
etl::u16string<64> s1;
|
||||
etl::to_string(std::numeric_limits<double>::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<double>::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<double>::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<double>::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<double>::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<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u16string<64>(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -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<double>::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<double>::is_iec559)
|
||||
{
|
||||
etl::u32string<64> s1;
|
||||
etl::to_string(std::numeric_limits<double>::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<double>::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<double>::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<double>::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<double>::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<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u32string<64>(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -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<double>::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<double>::is_iec559)
|
||||
{
|
||||
etl::u8string<64> s1;
|
||||
etl::to_string(std::numeric_limits<double>::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<double>::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<double>::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<double>::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<double>::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<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u8string<64>(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -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<double>::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<double>::is_iec559)
|
||||
{
|
||||
etl::wstring<64> s1;
|
||||
etl::to_string(std::numeric_limits<double>::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<double>::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<double>::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<double>::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<double>::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<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::wstring<64>(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user