tests/test_json.c

changeset 1063
e453e717876e
parent 1060
0a7c1bb2372d
child 1072
c89283cd559b
--- a/tests/test_json.c	Sat Dec 28 17:31:28 2024 +0100
+++ b/tests/test_json.c	Sat Dec 28 17:32:36 2024 +0100
@@ -30,7 +30,7 @@
 #include "cx/test.h"
 
 #include "cx/json.h"
-#include "cx/mempool.h"
+#include "cx/compare.h"
 
 CX_TEST(test_json_init_default) {
     CxJson json;
@@ -86,12 +86,12 @@
         CxJsonValue *longitude = cxJsonObjGet(position, "longitude");
         CX_TEST_ASSERT(cxJsonIsNumber(longitude));
         CX_TEST_ASSERT(!cxJsonIsInteger(longitude));
-        CX_TEST_ASSERT(cxJsonAsDouble(longitude) == -94.7099);
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(longitude), -94.7099));
         CX_TEST_ASSERT(cxJsonAsInteger(longitude) == -94);
         CxJsonValue *latitude = cxJsonObjGet(position, "latitude");
         CX_TEST_ASSERT(cxJsonIsNumber(latitude));
         CX_TEST_ASSERT(!cxJsonIsInteger(latitude));
-        CX_TEST_ASSERT(cxJsonAsDouble(latitude) == 51.5539);
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(latitude), 51.5539));
         CX_TEST_ASSERT(cxJsonAsInteger(latitude) == 51);
 
         CxJsonValue *timestamp = cxJsonObjGet(obj, "timestamp");
@@ -352,21 +352,21 @@
         result = cxJsonNext(&json, &v);
         CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
         CX_TEST_ASSERT(cxJsonIsNumber(v));
-        CX_TEST_ASSERT(cxJsonAsDouble(v) == 3.1415);
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(v), 3.1415));
         cxJsonValueFree(v);
 
         cxJsonFill(&json, "-47.11e2 ");
         result = cxJsonNext(&json, &v);
         CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
         CX_TEST_ASSERT(cxJsonIsNumber(v));
-        CX_TEST_ASSERT(cxJsonAsDouble(v) == -4711.0);
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(v), -4711.0));
         cxJsonValueFree(v);
 
         cxJsonFill(&json, "0.815e-3 ");
         result = cxJsonNext(&json, &v);
         CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
         CX_TEST_ASSERT(cxJsonIsNumber(v));
-        CX_TEST_ASSERT(cxJsonAsDouble(v) == 0.000815);
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(v), 0.000815));
         cxJsonValueFree(v);
 
         cxJsonFill(&json, "1.23E4 ");
@@ -382,7 +382,8 @@
         CX_TEST_ASSERT(result == CX_JSON_NO_ERROR);
         CX_TEST_ASSERT(cxJsonIsNumber(v));
         // be as precise as possible
-        CX_TEST_ASSERT(cxJsonAsDouble(v) == 1.8446744073709552e+19);
+        // TODO: this might produce format error / out of range in future implementations
+        CX_TEST_ASSERT(0 == cx_vcmp_double(cxJsonAsDouble(v), 1.8446744073709552e+19));
         cxJsonValueFree(v);
     }
     cxJsonDestroy(&json);

mercurial