From c88c775d231832bcc361455a5074a62ca8df2780 Mon Sep 17 00:00:00 2001 From: Krzysztof Gabis Date: Sun, 23 Nov 2014 12:39:47 +0100 Subject: [PATCH] Fixed floating point number comparison in tests (using fabs). --- tests.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) mode change 100755 => 100644 tests.c diff --git a/tests.c b/tests.c old mode 100755 new mode 100644 index 123815a..b00566c --- a/tests.c +++ b/tests.c @@ -29,11 +29,13 @@ #include #include #include +#include #define TEST(A) printf("%-72s-",#A); \ if(A){puts(" OK");tests_passed++;} \ else{puts(" FAIL");tests_failed++;} #define STREQ(A, B) ((A) && (B) ? strcmp((A), (B)) == 0 : 0) +#define EPSILON 0.000001 void test_suite_1(void); /* Test 3 files from json.org + serialization*/ void test_suite_2(JSON_Value *value); /* Test correctness of parsed values */ @@ -108,7 +110,7 @@ void test_suite_2(JSON_Value *root_value) { TEST(STREQ(json_object_get_string(root_object, "surrogate string"), "loremš¯„˛ipsumš¯¨§lorem")); TEST(json_object_get_number(root_object, "positive one") == 1.0); TEST(json_object_get_number(root_object, "negative one") == -1.0); - TEST(json_object_get_number(root_object, "hard to parse number") == -0.000314); + TEST(fabs(json_object_get_number(root_object, "hard to parse number") - (-0.000314)) < EPSILON); TEST(json_object_get_boolean(root_object, "boolean true") == 1); TEST(json_object_get_boolean(root_object, "boolean false") == 0); TEST(json_value_get_type(json_object_get_value(root_object, "null")) == JSONNull);