From 5c0f2414cd6d988a4eab93fc21bc3b80388907e8 Mon Sep 17 00:00:00 2001
From: kobewi <kobewi4e@gmail.com>
Date: Tue, 26 Mar 2024 17:04:14 +0100
Subject: Always add decimal when printing float

---
 tests/core/math/test_aabb.h               |  2 +-
 tests/core/math/test_color.h              |  2 +-
 tests/core/math/test_rect2.h              |  2 +-
 tests/core/string/test_string.h           | 24 ++++++++++++------------
 tests/core/variant/test_variant_utility.h |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

(limited to 'tests/core')

diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h
index 741e6af5d4..eb6977fd69 100644
--- a/tests/core/math/test_aabb.h
+++ b/tests/core/math/test_aabb.h
@@ -48,7 +48,7 @@ TEST_CASE("[AABB] Constructor methods") {
 
 TEST_CASE("[AABB] String conversion") {
 	CHECK_MESSAGE(
-			String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2, -2.5), S: (4, 5, 6)]",
+			String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "[P: (-1.5, 2.0, -2.5), S: (4.0, 5.0, 6.0)]",
 			"The string representation should match the expected value.");
 }
 
diff --git a/tests/core/math/test_color.h b/tests/core/math/test_color.h
index bd2d4f40e5..3d36079102 100644
--- a/tests/core/math/test_color.h
+++ b/tests/core/math/test_color.h
@@ -140,7 +140,7 @@ TEST_CASE("[Color] Conversion methods") {
 			cyan.to_rgba64() == 0x0000'ffff'ffff'ffff,
 			"The returned 64-bit BGR number should match the expected value.");
 	CHECK_MESSAGE(
-			String(cyan) == "(0, 1, 1, 1)",
+			String(cyan) == "(0.0, 1.0, 1.0, 1.0)",
 			"The string representation should match the expected value.");
 }
 
diff --git a/tests/core/math/test_rect2.h b/tests/core/math/test_rect2.h
index c4368808a6..a93bfeb71b 100644
--- a/tests/core/math/test_rect2.h
+++ b/tests/core/math/test_rect2.h
@@ -57,7 +57,7 @@ TEST_CASE("[Rect2] Constructor methods") {
 TEST_CASE("[Rect2] String conversion") {
 	// Note: This also depends on the Vector2 string representation.
 	CHECK_MESSAGE(
-			String(Rect2(0, 100, 1280, 720)) == "[P: (0, 100), S: (1280, 720)]",
+			String(Rect2(0, 100, 1280, 720)) == "[P: (0.0, 100.0), S: (1280.0, 720.0)]",
 			"The string representation should match the expected value.");
 }
 
diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h
index 8559737e74..89e3c6c02c 100644
--- a/tests/core/string/test_string.h
+++ b/tests/core/string/test_string.h
@@ -455,9 +455,9 @@ TEST_CASE("[String] Erasing") {
 }
 
 TEST_CASE("[String] Number to string") {
-	CHECK(String::num(0) == "0");
-	CHECK(String::num(0.0) == "0"); // No trailing zeros.
-	CHECK(String::num(-0.0) == "-0"); // Includes sign even for zero.
+	CHECK(String::num(0) == "0.0"); // The method takes double, so always add zeros.
+	CHECK(String::num(0.0) == "0.0");
+	CHECK(String::num(-0.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_scientific(30000000) == "3e+07");
@@ -476,15 +476,15 @@ TEST_CASE("[String] Number to string") {
 	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(123.456789) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
-	CHECK_MESSAGE(String::num_real(-123.456789) == "-123.456789", "Prints the appropriate amount of digits for real_t = 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.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
+	CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
+	CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
+	CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
+	CHECK_MESSAGE(String::num_real(real_t(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(123.456789) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
-	CHECK_MESSAGE(String::num_real(-123.456789) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
-	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.");
+	CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
+	CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
+	CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
+	CHECK_MESSAGE(String::num_real(real_t(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.
@@ -493,7 +493,7 @@ TEST_CASE("[String] Number to string") {
 	CHECK(String::num(-0.0000012345432123454321) == "-0.00000123454321");
 	CHECK(String::num(-10000.0000012345432123454321) == "-10000.0000012345");
 	CHECK(String::num(0.0000000000012345432123454321) == "0.00000000000123");
-	CHECK(String::num(0.0000000000012345432123454321, 3) == "0");
+	CHECK(String::num(0.0000000000012345432123454321, 3) == "0.0");
 
 	// Note: When relevant (remainder > 0.5), the last digit gets rounded up,
 	// which can also lead to not include a trailing zero, e.g. "...89" -> "...9".
diff --git a/tests/core/variant/test_variant_utility.h b/tests/core/variant/test_variant_utility.h
index 93458b63f4..34b4880d51 100644
--- a/tests/core/variant/test_variant_utility.h
+++ b/tests/core/variant/test_variant_utility.h
@@ -89,7 +89,7 @@ TEST_CASE("[VariantUtility] Type conversion") {
 
 		converted = VariantUtilityFunctions::type_convert(basis, Variant::Type::STRING);
 		CHECK(converted.get_type() == Variant::Type::STRING);
-		CHECK(converted == Variant("[X: (1.2, 0, 0), Y: (0, 3.4, 0), Z: (0, 0, 5.6)]"));
+		CHECK(converted == Variant("[X: (1.2, 0.0, 0.0), Y: (0.0, 3.4, 0.0), Z: (0.0, 0.0, 5.6)]"));
 	}
 
 	{
-- 
cgit v1.2.3