diff --git a/src/testing.h b/src/testing.h
index d22af4c2cc610788b24b8cef0b50268a3e7752a4..84a1242953284309fe015df0ee6c43d95e6ba434 100644 (file)
--- a/src/testing.h
+++ b/src/testing.h
static int fail_count__ = 0;
static int check_count__ = 0;
+#ifndef DBL_PRECISION
+# define DBL_PRECISION 1e-12
+#endif
+
#define DEF_TEST(func) static int test_##func ()
#define RUN_TEST(func) do { \
#define OK1(cond, text) do { \
_Bool result = (cond); \
printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count__, text); \
+ if (!result) { return -1; } \
} while (0)
#define OK(cond) OK1(cond, #cond)
} while (0)
#define DBLEQ(expect, actual) do { \
- if ((isnan (expect) && !isnan (actual)) || ((expect) != (actual))) {\
+ double e = (expect); double a = (actual); \
+ if (isnan (e) && !isnan (a)) { \
printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
- ++check_count__, #actual, expect, actual); \
+ ++check_count__, #actual, e, a); \
+ return (-1); \
+ } else if (!isnan (e) && (((e-a) < -DBL_PRECISION) || ((e-a) > DBL_PRECISION))) { \
+ printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \
+ ++check_count__, #actual, e, a); \
return (-1); \
} \
- printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, expect); \
+ printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, e); \
} while (0)
#define CHECK_NOT_NULL(expr) do { \