1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index 7e8898c..b1bccf3 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -126,14 +126,14 @@
test_context(NULL); \
} while (0)
-#define BUF_PARSE_TEST_F32(test, expected) \
+#define BUF_PARSE_TEST_F32(test, expected1, expected2) \
do { \
s_buf buf; \
f32 dest = -1; \
- test_context("buf_parse_f32(" # test ") -> " # expected); \
+ test_context("buf_parse_f32(" # test ") -> " # expected1); \
buf_init_1(&buf, (test)); \
TEST_EQ(buf_parse_f32(&buf, &dest), strlen(test)); \
- TEST_FLOAT_EQ(dest, (expected)); \
+ TEST_FLOAT_EQ2(dest, (expected1), (expected2)); \
buf_clean(&buf); \
test_context(NULL); \
} while (0)
@@ -789,9 +789,9 @@ void buf_parse_test_digit_dec ()
void buf_parse_test_f32()
{
- BUF_PARSE_TEST_F32("123.123", 123.123);
- BUF_PARSE_TEST_F32("3.14159", 3.14159);
- BUF_PARSE_TEST_F32("2.1e+2", 210);
+ BUF_PARSE_TEST_F32("123.123", 123.123, 123.1229934692383);
+ BUF_PARSE_TEST_F32("3.14159", 3.14159, 3.141589641571045);
+ BUF_PARSE_TEST_F32("2.1e+2", 210, 209.9999847412109);
}
void buf_parse_test_f64()
diff --git a/test/test.h b/test/test.h
index 99a595c..0cd41d3 100644
--- a/test/test.h
+++ b/test/test.h
@@ -66,6 +66,24 @@
} \
} while (0)
+#define TEST_FLOAT_EQ2(test, expected1, expected2) \
+ do { \
+ f32 tmp = (f32) (test); \
+ if (fabsf(tmp - (f32) (expected1)) <= FLT_EPSILON || \
+ fabsf(tmp - (f32) (expected2)) <= FLT_EPSILON) \
+ test_ok(); \
+ else { \
+ test_ko(); \
+ printf("\n%sAssertion failed in %s:%d %s\n" \
+ "%s == %s\n" \
+ "Expected %s got %.16g.%s\n", \
+ TEST_COLOR_KO, \
+ __FILE__, __LINE__, __func__, \
+ # test, # expected1, # expected1, tmp, \
+ TEST_COLOR_RESET); \
+ } \
+ } while (0)
+
#define TEST_DOUBLE_EQ(test, expected) \
do { \
f64 tmp = (f64) (test); \
@@ -75,7 +93,7 @@
test_ko(); \
printf("\n%sAssertion failed in %s:%d %s\n" \
"%s == %s\n" \
- "Expected %s got %f.%s\n", \
+ "Expected %s got %lf.%s\n", \
TEST_COLOR_KO, \
__FILE__, __LINE__, __func__, \
# test, # expected, # expected, tmp, \