diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2022-01-14 21:17:01 -0600 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2022-01-15 00:21:49 -0600 |
commit | 13939734e05e231f63e5bd7275d182491600e206 (patch) | |
tree | 3e5c5da9606e57de58ff941d65f4804299547f92 /tests/core | |
parent | c1e78f749e1adef54265d702d43fd82d773359ea (diff) |
Replace String::num_real code with a wrapper around String::num
Diffstat (limited to 'tests/core')
-rw-r--r-- | tests/core/math/test_vector2.h | 19 | ||||
-rw-r--r-- | tests/core/math/test_vector3.h | 19 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 8 |
3 files changed, 45 insertions, 1 deletions
diff --git a/tests/core/math/test_vector2.h b/tests/core/math/test_vector2.h index 7dd14736e8..cb447acd17 100644 --- a/tests/core/math/test_vector2.h +++ b/tests/core/math/test_vector2.h @@ -246,6 +246,25 @@ TEST_CASE("[Vector2] Operators") { CHECK_MESSAGE( Vector2(Vector2i(1, 2)) == Vector2(1, 2), "Vector2 constructed from Vector2i should work as expected."); + + CHECK_MESSAGE( + ((String)decimal1) == "(2.3, 4.9)", + "Vector2 cast to String should work as expected."); + CHECK_MESSAGE( + ((String)decimal2) == "(1.2, 3.4)", + "Vector2 cast to String should work as expected."); + CHECK_MESSAGE( + ((String)Vector2(9.8, 9.9)) == "(9.8, 9.9)", + "Vector2 cast to String should work as expected."); +#ifdef REAL_T_IS_DOUBLE + CHECK_MESSAGE( + ((String)Vector2(Math_PI, Math_TAU)) == "(3.14159265358979, 6.28318530717959)", + "Vector2 cast to String should print the correct amount of digits for real_t = double."); +#else + CHECK_MESSAGE( + ((String)Vector2(Math_PI, Math_TAU)) == "(3.141593, 6.283185)", + "Vector2 cast to String should print the correct amount of digits for real_t = float."); +#endif // REAL_T_IS_DOUBLE } TEST_CASE("[Vector2] Other methods") { diff --git a/tests/core/math/test_vector3.h b/tests/core/math/test_vector3.h index 97da035046..136a531946 100644 --- a/tests/core/math/test_vector3.h +++ b/tests/core/math/test_vector3.h @@ -271,6 +271,25 @@ TEST_CASE("[Vector3] Operators") { CHECK_MESSAGE( Vector3(Vector3i(1, 2, 3)) == Vector3(1, 2, 3), "Vector3 constructed from Vector3i should work as expected."); + + CHECK_MESSAGE( + ((String)decimal1) == "(2.3, 4.9, 7.8)", + "Vector3 cast to String should work as expected."); + CHECK_MESSAGE( + ((String)decimal2) == "(1.2, 3.4, 5.6)", + "Vector3 cast to String should work as expected."); + CHECK_MESSAGE( + ((String)Vector3(9.7, 9.8, 9.9)) == "(9.7, 9.8, 9.9)", + "Vector3 cast to String should work as expected."); +#ifdef REAL_T_IS_DOUBLE + CHECK_MESSAGE( + ((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888)", + "Vector3 cast to String should print the correct amount of digits for real_t = double."); +#else + CHECK_MESSAGE( + ((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.718282, 1.414214, 1.732051)", + "Vector3 cast to String should print the correct amount of digits for real_t = float."); +#endif // REAL_T_IS_DOUBLE } TEST_CASE("[Vector3] Other methods") { diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 2f611c26a9..baab5ddfe7 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -355,11 +355,17 @@ TEST_CASE("[String] Number to string") { CHECK(String::num(42.100023, 4) == "42.1"); // No trailing zeros. // String::num_real tests. + CHECK(String::num_real(1.0) == "1.0"); + CHECK(String::num_real(1.0, false) == "1"); + CHECK(String::num_real(9.9) == "9.9"); + CHECK(String::num_real(9.99) == "9.99"); + CHECK(String::num_real(9.999) == "9.999"); + CHECK(String::num_real(9.9999) == "9.9999"); 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)."); + CHECK_MESSAGE(String::num_real(3.1415f) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero."); #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."); |