diff options
Diffstat (limited to 'src/test/test-json.c')
-rw-r--r-- | src/test/test-json.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c index 415ada22bf..d22485630a 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include <float.h> -#include <math.h> #include "alloc-util.h" #include "escape.h" @@ -9,6 +8,7 @@ #include "fileio.h" #include "json-internal.h" #include "json.h" +#include "math-util.h" #include "string-util.h" #include "strv.h" #include "tests.h" @@ -239,9 +239,7 @@ static void test_zeroes(JsonVariant *v) { assert_se(json_variant_integer(w) == 0); assert_se(json_variant_unsigned(w) == 0U); - DISABLE_WARNING_FLOAT_EQUAL; - assert_se(json_variant_real(w) == 0.0L); - REENABLE_WARNING; + assert_se(iszero_safe(json_variant_real(w))); assert_se(json_variant_is_integer(w)); assert_se(json_variant_is_unsigned(w)); @@ -511,7 +509,7 @@ static void test_float_match(JsonVariant *v) { const double delta = 0.0001; assert_se(json_variant_is_array(v)); - assert_se(json_variant_elements(v) == 9); + assert_se(json_variant_elements(v) == 11); assert_se(fabs(1.0 - (DBL_MIN / json_variant_real(json_variant_by_index(v, 0)))) <= delta); assert_se(fabs(1.0 - (DBL_MAX / json_variant_real(json_variant_by_index(v, 1)))) <= delta); assert_se(json_variant_is_null(json_variant_by_index(v, 2))); /* nan is not supported by json → null */ @@ -528,6 +526,12 @@ static void test_float_match(JsonVariant *v) { assert_se(json_variant_is_real(json_variant_by_index(v, 8)) && json_variant_is_integer(json_variant_by_index(v, 8)) && json_variant_integer(json_variant_by_index(v, 8)) == -10); + assert_se(json_variant_is_real(json_variant_by_index(v, 9)) && + !json_variant_is_integer(json_variant_by_index(v, 9))); + assert_se(fabs(1.0 - (DBL_MIN / 2 / json_variant_real(json_variant_by_index(v, 9)))) <= delta); + assert_se(json_variant_is_real(json_variant_by_index(v, 10)) && + !json_variant_is_integer(json_variant_by_index(v, 10))); + assert_se(fabs(1.0 - (-DBL_MIN / 2 / json_variant_real(json_variant_by_index(v, 10)))) <= delta); } TEST(float) { @@ -543,7 +547,9 @@ TEST(float) { JSON_BUILD_REAL(HUGE_VAL), JSON_BUILD_REAL(0), JSON_BUILD_REAL(10), - JSON_BUILD_REAL(-10))) >= 0); + JSON_BUILD_REAL(-10), + JSON_BUILD_REAL(DBL_MIN / 2), + JSON_BUILD_REAL(-DBL_MIN / 2))) >= 0); json_variant_dump(v, JSON_FORMAT_COLOR|JSON_FORMAT_PRETTY, NULL, NULL); |