aboutsummaryrefslogtreecommitdiff
path: root/tests/tests.c
diff options
context:
space:
mode:
authorMartin Baƙinka <marun1@email.cz>2021-04-29 08:40:06 +0200
committerGitHub <noreply@github.com>2021-04-29 09:40:06 +0300
commit35eb7753d29a9ad14b145a09c057a88131d6ede0 (patch)
treeebe2b69d32e12126c8a1e49c5e1d0012044c2bfa /tests/tests.c
parent951f522b13b1ea0068345369a98d18d862b29582 (diff)
downloadlibfixmath-35eb7753d29a9ad14b145a09c057a88131d6ede0.tar.gz
New unittests (#28)
Refactor unittests
Diffstat (limited to 'tests/tests.c')
-rw-r--r--tests/tests.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/tests.c b/tests/tests.c
new file mode 100644
index 0000000..cef9710
--- /dev/null
+++ b/tests/tests.c
@@ -0,0 +1,51 @@
+#include "tests.h"
+#include "tests_basic.h"
+#include "tests_lerp.h"
+#include "tests_sqrt.h"
+#include <stdio.h>
+
+const fix16_t testcases[] = {
+ // Small numbers
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10,
+
+ // Integer numbers
+ 0x10000, -0x10000, 0x20000, -0x20000, 0x30000, -0x30000, 0x40000, -0x40000,
+ 0x50000, -0x50000, 0x60000, -0x60000,
+
+ // Fractions (1/2, 1/4, 1/8)
+ 0x8000, -0x8000, 0x4000, -0x4000, 0x2000, -0x2000,
+
+ // Problematic carry
+ 0xFFFF, -0xFFFF, 0x1FFFF, -0x1FFFF, 0x3FFFF, -0x3FFFF,
+
+ // Smallest and largest values
+ 0x7FFFFFFF, 0x80000000,
+
+ // Large random numbers
+ 831858892, 574794913, 2147272293, -469161054, -961611615, 1841960234,
+ 1992698389, 520485404, 560523116, -2094993050, -876897543, -67813629,
+ 2146227091, 509861939, -1073573657,
+
+ // Small random numbers
+ -14985, 30520, -83587, 41129, 42137, 58537, -2259, 84142, -28283, 90914,
+ 19865, 33191, 81844, -66273, -63215, -44459, -11326, 84295, 47515, -39324,
+
+ // Tiny random numbers
+ -171, -359, 491, 844, 158, -413, -422, -737, -575, -330, -376, 435, -311,
+ 116, 715, -1024, -487, 59, 724, 993
+};
+
+unsigned stack_depth = 0;
+
+int main()
+{
+ printf("\033[1;34m\nVARIANT: \033[39m"STR2(PREFIX)"\033[0m\n");
+ TEST(test_abs());
+ TEST(test_add());
+ TEST(test_mul());
+ TEST(test_div());
+ TEST(test_sub());
+ TEST(test_sqrt());
+ TEST(test_lerp());
+ return 0;
+}