diff options
| author | Martin BaĆinka <marun1@email.cz> | 2021-04-29 08:40:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-29 09:40:06 +0300 |
| commit | 35eb7753d29a9ad14b145a09c057a88131d6ede0 (patch) | |
| tree | ebe2b69d32e12126c8a1e49c5e1d0012044c2bfa /tests/tests_sqrt.c | |
| parent | 951f522b13b1ea0068345369a98d18d862b29582 (diff) | |
New unittests (#28)
Refactor unittests
Diffstat (limited to 'tests/tests_sqrt.c')
| -rw-r--r-- | tests/tests_sqrt.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/tests_sqrt.c b/tests/tests_sqrt.c new file mode 100644 index 0000000..8faf016 --- /dev/null +++ b/tests/tests_sqrt.c @@ -0,0 +1,37 @@ +#include "tests_sqrt.h" +#include "tests.h" + +int test_sqrt_specific() +{ + ASSERT_EQ_INT(fix16_sqrt(fix16_from_int(16)), fix16_from_int(4)); + ASSERT_EQ_INT(fix16_sqrt(fix16_from_int(100)), fix16_from_int(10)); + ASSERT_EQ_INT(fix16_sqrt(fix16_from_int(1)), fix16_from_int(1)); +#ifndef FIXMATH_NO_ROUNDING + ASSERT_EQ_INT(fix16_sqrt(214748302), 3751499); + ASSERT_EQ_INT(fix16_sqrt(214748303), 3751499); + ASSERT_EQ_INT(fix16_sqrt(214748359), 3751499); + ASSERT_EQ_INT(fix16_sqrt(214748360), 3751500); +#endif + return 0; +} + +int test_sqrt_short() +{ + for (unsigned i = 0; i < TESTCASES_COUNT; ++i) + { + fix16_t a = testcases[i]; + double fa = fix16_to_dbl(a); + fix16_t result = fix16_sqrt(a); + double fresult = sqrt(fa); + ASSERT_NEAR_DOUBLE(fresult, fix16_to_dbl(result), fix16_to_dbl(1), + "in: %f", fa); + } + return 0; +} + +int test_sqrt() +{ + TEST(test_sqrt_specific()); + TEST(test_sqrt_short()); + return 0; +} |
