diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-08-18 17:49:37 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2021-09-15 13:41:12 -0500 |
commit | 5d03c0e0b628bda8220aabe5f16abf5bfe8e1eec (patch) | |
tree | 4dbcbd4c7a1efc2797f39df3b54fffceea31e499 /tests | |
parent | e902347a8cefbced8898dfc9f000afdf3be0d36a (diff) |
Fix String::num_real and String test cases when compiling with doubles
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_string.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/test_string.h b/tests/test_string.h index bcedaa0db7..c1b7220fdb 100644 --- a/tests/test_string.h +++ b/tests/test_string.h @@ -355,13 +355,23 @@ TEST_CASE("[String] Number to string") { CHECK(String::num(-0.0) == "-0"); // Includes sign even for zero. CHECK(String::num(3.141593) == "3.141593"); CHECK(String::num(3.141593, 3) == "3.142"); - CHECK(String::num_real(3.141593) == "3.141593"); CHECK(String::num_scientific(30000000) == "3e+07"); CHECK(String::num_int64(3141593) == "3141593"); CHECK(String::num_int64(0xA141593, 16) == "a141593"); CHECK(String::num_int64(0xA141593, 16, true) == "A141593"); CHECK(String::num(42.100023, 4) == "42.1"); // No trailing zeros. + // String::num_real tests. + CHECK(String::num_real(3.141593) == "3.141593"); + CHECK(String::num_real(3.141) == "3.141"); // No trailing zeros. +#ifdef REAL_T_IS_DOUBLE + CHECK_MESSAGE(String::num_real(Math_PI) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double."); + CHECK_MESSAGE(String::num_real(3.1415f) == "3.14149999618530", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double)."); +#else + CHECK_MESSAGE(String::num_real(Math_PI) == "3.141593", "Prints the appropriate amount of digits for real_t = float."); + CHECK_MESSAGE(String::num_real(3.1415f) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float."); +#endif // REAL_T_IS_DOUBLE + // Checks doubles with many decimal places. CHECK(String::num(0.0000012345432123454321, -1) == "0.00000123454321"); // -1 uses 14 as sane default. CHECK(String::num(0.0000012345432123454321) == "0.00000123454321"); // -1 is the default value. |