From 421300c27123ca647772dc6d9bd0cabf7f5f9c99 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 23 Jul 2025 19:39:13 +0200 Subject: refactor: src & pragma once --- include/testing.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 include/testing.h (limited to 'include/testing.h') diff --git a/include/testing.h b/include/testing.h new file mode 100644 index 0000000..9e0c022 --- /dev/null +++ b/include/testing.h @@ -0,0 +1,24 @@ +#include + +#define t_assert(fact) \ + if (!(fact)) { \ + fprintf(stderr, "Assertion failed: %s at %s:%d in %s()\n", #fact, \ + __FILE__, __LINE__, __func__); \ + return 1; \ + } + +#define t_assert_equal(a, b) \ + if (!(a == b)) { \ + fprintf(stderr, \ + "Assertion failed: %d (%s) != %d (%s) at %s:%d in %s()\n", \ + (i32)a, #a, (i32)b, #b, __FILE__, __LINE__, __func__); \ + return 1; \ + } + +#define t_assert_fequal(a, b) \ + if ((a - b) > 1e-6 || (b - a) > 1e-6) { \ + fprintf(stderr, \ + "Assertion failed: %f (%s) != %f (%s) at %s:%d in %s()\n", a, \ + #a, b, #b, __FILE__, __LINE__, __func__); \ + return 1; \ + } -- cgit v1.3