summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-01 20:16:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-03-01 20:16:39 -0500
commit59618293f47374b14dd75d52bec873488eb3d6c9 (patch)
tree8ea56ba4167f77974569e67470a189897849bda2
parent2f08f7cc4b9c7ad2f0a33b5367c2f3fd4ae4ed7e (diff)
add double test (printing is not cool at the moment)
-rw-r--r--test.c7
-rw-r--r--test.h5
2 files changed, 11 insertions, 1 deletions
diff --git a/test.c b/test.c
index 01a6dd5..5a009fc 100644
--- a/test.c
+++ b/test.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdarg.h>
+#include <float.h>
unsigned int total_passed = 0;
unsigned int total_failed = 0;
@@ -87,6 +88,12 @@ void test_int_equals_imp(const char *expression, int result, int expected)
print_result(result == expected, "%s == %d", expression, expected);
}
+void test_double_imp(const char *expression, double result, double expected)
+{
+ int success = (result - expected < DBL_EPSILON);
+ print_result(success, "%s == %d", expression, (int)expected);
+}
+
void test_void_imp(const char *expression)
{
putchar('?');
diff --git a/test.h b/test.h
index 357a26c..43d7512 100644
--- a/test.h
+++ b/test.h
@@ -7,6 +7,9 @@ void testing_end(void);
void test_int_equals_imp(const char*, int, int);
#define test_int_equals(expression, expected) test_int_equals_imp(#expression, expression, expected)
+void test_double_imp(const char*, double, double);
+#define test_double(expression, expected) test_double_imp(#expression, expression, expected)
+
void test_void_imp(const char*);
#define test_void(expression) ((void)expression), test_void_imp(#expression)
@@ -15,7 +18,7 @@ void test_bool_imp(const char *, int, int);
#define test_true(expression) test_bool_imp(#expression, expression, 1)
#define test_min(expression, min) test_bool_imp(#expression, min < 0 ? expression <= min : expression >= min, 1)
#define test_max(expression, max) test_bool_imp(#expression, 0 < expression && expression <= max, 1)
-#define test_defined(expression) test_false(expression & 0)
+#define test_defined(expression) test_false(expression * 0)
void test_string_imp(const char*, const char*, const char*);
#define test_string(expression, string) test_string_imp(#expression, expression, string)