aboutsummaryrefslogtreecommitdiff
path: root/tests/tests.c
diff options
context:
space:
mode:
authorMartin Baƙinka <marun1@email.cz>2021-05-03 12:43:54 +0200
committerGitHub <noreply@github.com>2021-05-03 13:43:54 +0300
commit0c88e55fa8f132e8ac15426911d155f136078302 (patch)
tree03fc1b22c0582bd57ae3a14095d3d9c9f949f0c9 /tests/tests.c
parent4ea8f3ff12da61a5ceba690bf1e39d9385b42880 (diff)
downloadlibfixmath-0c88e55fa8f132e8ac15426911d155f136078302.tar.gz
fixed division, undefined behaviors and some improvements (#33)
* testing using ctest * emove old testing script * added github workflow CI * updated CI * added unit test for macros * F16() and F16C() are both rounding allways, so fix16_from_dbl should as well * added tests for strign operations, but these functions are in my opinion unreliable and tests are failing * removed old unittests * removed old unittests from cmake * problem with division using gcc * improved benchmark * clarification of problem with division * attempt to fix * fixed some undefined behaviors, fixed division
Diffstat (limited to 'tests/tests.c')
-rw-r--r--tests/tests.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/tests/tests.c b/tests/tests.c
index cef9710..d06ee26 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -1,7 +1,9 @@
#include "tests.h"
#include "tests_basic.h"
#include "tests_lerp.h"
+#include "tests_macros.h"
#include "tests_sqrt.h"
+#include "tests_str.h"
#include <stdio.h>
const fix16_t testcases[] = {
@@ -32,14 +34,41 @@ const fix16_t testcases[] = {
// Tiny random numbers
-171, -359, 491, 844, 158, -413, -422, -737, -575, -330, -376, 435, -311,
- 116, 715, -1024, -487, 59, 724, 993
-};
+ 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");
+ printf("\033[1;34m\nVARIANT: \033[39m" STR2(PREFIX) "\033[0m\n");
+#if 0
+ fix16_t a = 65536;
+ fix16_t b = -2147483648;
+ fix16_t result = fix16_div(a, b);
+
+ double fa = fix16_to_dbl(a);
+ double fb = fix16_to_dbl(b);
+ double fresult = fa / fb;
+
+ double max = fix16_to_dbl(fix16_maximum);
+ double min = fix16_to_dbl(fix16_minimum);
+
+ printf("result %i, %.20f\n", result, fix16_to_dbl(result));
+ printf("fresult %i, %.20f\n", fix16_from_dbl(fresult), fresult);
+
+ if ((fa / fb) > max || (fa / fb) < min)
+ {
+#ifndef FIXMATH_NO_OVERFLOW
+ ASSERT_EQ_INT(result, fix16_overflow);
+#endif
+ }
+ else
+ {
+ ASSERT_NEAR_DOUBLE(fresult, fix16_to_dbl(result),
+ fix16_to_dbl(fix16_eps), "%i / %i \n", a, b);
+ }
+
+#else
TEST(test_abs());
TEST(test_add());
TEST(test_mul());
@@ -47,5 +76,8 @@ int main()
TEST(test_sub());
TEST(test_sqrt());
TEST(test_lerp());
+ TEST(test_macros());
+ //TEST(test_str());
+#endif
return 0;
}