From 59551b47e48d3c6e12f64204258f292db16c6264 Mon Sep 17 00:00:00 2001 From: ConnorClancyDeakin Date: Sun, 27 Jul 2025 21:35:02 +1000 Subject: [PATCH 1/8] Added to json unit test to include set/read number in float and double --- coresdk/src/test/unit_tests/unit_test_json.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index f6bc1b98..ef9ba318 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -117,7 +117,18 @@ TEST_CASE("json can be created and read", "[json]") REQUIRE("#00ff00ff" == color_to_string(deserialized_clr)); } + SECTION("Json can be created and read with different number types") + { + json number_types = create_json(); + + json_set_number(number_types, "float", static_cast(21.2)); + json_set_number(number_types, "double", static_cast(30.1)); + REQUIRE(json_read_number(number_types, "float") == static_cast(21.2)); + REQUIRE(json_read_number_as_double(number_types, "double") == static_cast(30.1)); + + free_json(number_types); + } free_json(person); free_all_json(); } \ No newline at end of file From 1add3e3366711d1ccb71daa19069c0cf6a798bd0 Mon Sep 17 00:00:00 2001 From: ConnorClancyDeakin Date: Sun, 10 Aug 2025 22:21:21 +1000 Subject: [PATCH 2/8] Fixed capitilisation of json to match rest of test --- coresdk/src/test/unit_tests/unit_test_json.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index ef9ba318..d6cd5aa2 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -117,7 +117,7 @@ TEST_CASE("json can be created and read", "[json]") REQUIRE("#00ff00ff" == color_to_string(deserialized_clr)); } - SECTION("Json can be created and read with different number types") + SECTION("json can be created and read with different number types") { json number_types = create_json(); From f76ace52f01b1e2a62de31494897f235a9ff4859 Mon Sep 17 00:00:00 2001 From: ConnorClancyDeakin Date: Sat, 20 Sep 2025 22:32:10 +1000 Subject: [PATCH 3/8] Update coresdk/src/test/unit_tests/unit_test_json.cpp Co-authored-by: Daniel Carroll <6995669+dijidiji@users.noreply.github.com> --- coresdk/src/test/unit_tests/unit_test_json.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index d6cd5aa2..c908a626 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -124,8 +124,8 @@ TEST_CASE("json can be created and read", "[json]") json_set_number(number_types, "float", static_cast(21.2)); json_set_number(number_types, "double", static_cast(30.1)); - REQUIRE(json_read_number(number_types, "float") == static_cast(21.2)); - REQUIRE(json_read_number_as_double(number_types, "double") == static_cast(30.1)); + REQUIRE_THAT(json_read_number(number_types, "float"), WithinRel(21.2f)); + REQUIRE_THAT(json_read_number_as_double(number_types, "double"), WithinRel(30.1)); free_json(number_types); } From d1cfc437d7bd8d2a0748ebdeeaa72f84f48f0cd5 Mon Sep 17 00:00:00 2001 From: ConnorClancyDeakin Date: Sat, 20 Sep 2025 22:32:23 +1000 Subject: [PATCH 4/8] Update coresdk/src/test/unit_tests/unit_test_json.cpp Co-authored-by: Daniel Carroll <6995669+dijidiji@users.noreply.github.com> --- coresdk/src/test/unit_tests/unit_test_json.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index c908a626..73e83116 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -117,7 +117,7 @@ TEST_CASE("json can be created and read", "[json]") REQUIRE("#00ff00ff" == color_to_string(deserialized_clr)); } - SECTION("json can be created and read with different number types") +TEST_CASE("json can be created and read with different number types", "[json_read_number][json_read_number_as_double]") { json number_types = create_json(); From 8bef975b259b29d30672f56cc4489e3686c70dbf Mon Sep 17 00:00:00 2001 From: ConnorClancyDeakin Date: Sat, 20 Sep 2025 22:32:31 +1000 Subject: [PATCH 5/8] Update coresdk/src/test/unit_tests/unit_test_json.cpp Co-authored-by: Daniel Carroll <6995669+dijidiji@users.noreply.github.com> --- coresdk/src/test/unit_tests/unit_test_json.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index 73e83116..1f011a8f 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -121,8 +121,8 @@ TEST_CASE("json can be created and read with different number types", "[json_rea { json number_types = create_json(); - json_set_number(number_types, "float", static_cast(21.2)); - json_set_number(number_types, "double", static_cast(30.1)); + json_set_number(number_types, "float", 21.2f); + json_set_number(number_types, "double", 30.1); REQUIRE_THAT(json_read_number(number_types, "float"), WithinRel(21.2f)); REQUIRE_THAT(json_read_number_as_double(number_types, "double"), WithinRel(30.1)); From d2a1e759ddbed94ad3338505e72ce9a450926b4b Mon Sep 17 00:00:00 2001 From: rory-cd Date: Thu, 20 Nov 2025 13:37:42 +1100 Subject: [PATCH 6/8] Add required 'using' directive and fix nested test cases --- coresdk/src/test/unit_tests/unit_test_json.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index 1f011a8f..881c2e33 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -13,6 +13,7 @@ #include "color.h" using namespace splashkit_lib; +using Catch::Matchers::WithinRel; json create_person() { @@ -117,7 +118,12 @@ TEST_CASE("json can be created and read", "[json]") REQUIRE("#00ff00ff" == color_to_string(deserialized_clr)); } + + free_all_json(); +} + TEST_CASE("json can be created and read with different number types", "[json_read_number][json_read_number_as_double]") +{ { json number_types = create_json(); @@ -129,6 +135,4 @@ TEST_CASE("json can be created and read with different number types", "[json_rea free_json(number_types); } - free_json(person); - free_all_json(); } \ No newline at end of file From efcfa15b3e5e18ec9e3fe179bd17b306c7fa3d25 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Wed, 3 Dec 2025 14:08:00 +1100 Subject: [PATCH 7/8] Fix test case as per review - Remove unnecessary braces - Add newline at end of file - Add generic [json] tag - Revert removal of free_json(person) - Add edge case testing --- .../src/test/unit_tests/unit_test_json.cpp | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index 881c2e33..24f09bec 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -119,20 +119,66 @@ TEST_CASE("json can be created and read", "[json]") REQUIRE("#00ff00ff" == color_to_string(deserialized_clr)); } + free_json(person); free_all_json(); } -TEST_CASE("json can be created and read with different number types", "[json_read_number][json_read_number_as_double]") +TEST_CASE("json can be created and read with different number types", "[json][json_read_number][json_read_number_as_double]") { + json number_types = create_json(); + + SECTION("can read values correctly") { - json number_types = create_json(); - json_set_number(number_types, "float", 21.2f); - json_set_number(number_types, "double", 30.1); - REQUIRE_THAT(json_read_number(number_types, "float"), WithinRel(21.2f)); + json_set_number(number_types, "double", 30.1); REQUIRE_THAT(json_read_number_as_double(number_types, "double"), WithinRel(30.1)); - - free_json(number_types); } -} \ No newline at end of file + + SECTION("handles non-existent keys") + { + REQUIRE_FALSE(json_has_key(number_types, "nonExistent")); + REQUIRE(json_read_number(number_types, "nonExistent") == 0.0f); + REQUIRE(json_read_number_as_double(number_types, "nonExistent") == 0.0); + } + + SECTION("handles reading strings as numbers") + { + json_set_string(number_types, "numericString", "21.2"); + json_set_string(number_types, "nonNumericString", "Foo"); + // Read as float + REQUIRE_THAT(json_read_number(number_types, "numericString"), WithinRel(21.2f)); + REQUIRE(json_read_number(number_types, "nonNumericString") == 0.0f); + // Read as double + REQUIRE_THAT(json_read_number_as_double(number_types, "numericString"), WithinRel(21.2)); + REQUIRE(json_read_number_as_double(number_types, "nonNumericString") == 0.0); + } + + SECTION("correctly handles very large numbers") + { + // Handles largest possible float + float max_f = std::numeric_limits::max(); + json_set_number(number_types, "maxFloat", max_f); + REQUIRE_THAT(json_read_number(number_types, "maxFloat"), WithinRel(max_f)); + + // Handles largest possible double + double max_d = std::numeric_limits::max(); + json_set_number(number_types, "maxDouble", max_d); + REQUIRE_THAT(json_read_number_as_double(number_types, "maxDouble"), WithinRel(max_d)); + } + + SECTION("correctly handles very small numbers") + { + // Handles smallest possible float + float min_f = std::numeric_limits::min(); + json_set_number(number_types, "minFloat", min_f); + REQUIRE_THAT(json_read_number(number_types, "minFloat"), WithinRel(min_f)); + + // Handles smallest possible double + double min_d = std::numeric_limits::min(); + json_set_number(number_types, "minDouble", min_d); + REQUIRE_THAT(json_read_number_as_double(number_types, "minDouble"), WithinRel(min_d)); + } + + free_json(number_types); +} From f58afdbde58160fac74adf44c84274998c43b925 Mon Sep 17 00:00:00 2001 From: rory-cd Date: Wed, 3 Dec 2025 14:49:43 +1100 Subject: [PATCH 8/8] Fix: Remove string conversion test Non-numeric types should be converted to 0.0, regardless of whether they are numeric (e.g. "2.1") --- coresdk/src/test/unit_tests/unit_test_json.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/coresdk/src/test/unit_tests/unit_test_json.cpp b/coresdk/src/test/unit_tests/unit_test_json.cpp index 24f09bec..40057923 100644 --- a/coresdk/src/test/unit_tests/unit_test_json.cpp +++ b/coresdk/src/test/unit_tests/unit_test_json.cpp @@ -142,15 +142,10 @@ TEST_CASE("json can be created and read with different number types", "[json][js REQUIRE(json_read_number_as_double(number_types, "nonExistent") == 0.0); } - SECTION("handles reading strings as numbers") + SECTION("handles reading non-numeric types") { - json_set_string(number_types, "numericString", "21.2"); - json_set_string(number_types, "nonNumericString", "Foo"); - // Read as float - REQUIRE_THAT(json_read_number(number_types, "numericString"), WithinRel(21.2f)); + json_set_string(number_types, "string", "21.2"); REQUIRE(json_read_number(number_types, "nonNumericString") == 0.0f); - // Read as double - REQUIRE_THAT(json_read_number_as_double(number_types, "numericString"), WithinRel(21.2)); REQUIRE(json_read_number_as_double(number_types, "nonNumericString") == 0.0); }