aboutsummaryrefslogtreecommitdiffstats
path: root/test/float.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/float.c')
-rw-r--r--test/float.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/test/float.c b/test/float.c
index 9940ff4..f95ae8c 100644
--- a/test/float.c
+++ b/test/float.c
@@ -21,23 +21,29 @@
#include "test.h"
#include "float_test_private.h"
-struct test_results float_test(void)
+int float_test(char *testname)
{
- struct test_results ret;
+ static const struct test tests[] = {
+ {"signbitf", rin_signbitf_test},
+ {"signbitd", rin_signbitd_test},
+ {"floattohexstring", rin_float_to_hexstring_test},
+ {"doubletohexstring", rin_double_to_hexstring_test},
+ {"comparefloat", rin_compare_float_test},
+ {"comparedouble", rin_compare_double_test} };
+ size_t i;
- ret = rin_signbitf_test();
- ret = rin_signbitd_test();
- ret = rin_float_to_hexstring_test();
- ret = rin_double_to_hexstring_test();
- ret = rin_compare_float_test();
- ret = rin_compare_double_test();
+ for (i = 0; i < arrlen(tests); ++i) {
+ if (!strcmp(testname, tests[i].name)) {
+ return tests[i].testfunc();
+ }
+ }
- return ret;
+ return EXIT_FAILURE;
}
-static struct test_results rin_signbitf_test(void)
+static int rin_signbitf_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const float in[] = { 1.0f, -1.0f, 987656.4321f, -987656.4321f };
static const uint32_t expected[] = { 0, 0x80000000u, 0, 0x80000000u };
@@ -54,9 +60,9 @@ static struct test_results rin_signbitf_test(void)
return ret;
}
-static struct test_results rin_signbitd_test(void)
+static int rin_signbitd_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const double in[] = { 1.0, -1.0, 987656.4321, -987656.4321 };
static const uint64_t expected[] = { 0, 0x8000000000000000ull, 0, 0x8000000000000000ull };
@@ -73,9 +79,9 @@ static struct test_results rin_signbitd_test(void)
return ret;
}
-static struct test_results rin_float_to_hexstring_test(void)
+static int rin_float_to_hexstring_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const float in[] = { 1.0f, -1.0f, 98765.4321f, -98765.4321f };
static const char *expected_default[] = { "0x3f800000", "0xbf800000", "0x47c0e6b7", "0xc7c0e6b7" };
@@ -102,9 +108,9 @@ static struct test_results rin_float_to_hexstring_test(void)
}
-static struct test_results rin_double_to_hexstring_test(void)
+static int rin_double_to_hexstring_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const double in[] = { 1.0, -1.0, 98765.4321, -98765.4321 };
static const char *expected_default[] = { "0x3ff0000000000000", "0xbff0000000000000", "0x40f81cd6e9e1b08a", "0xc0f81cd6e9e1b08a" };
@@ -130,9 +136,9 @@ static struct test_results rin_double_to_hexstring_test(void)
return ret;
}
-static struct test_results rin_compare_float_test(void)
+static int rin_compare_float_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const float a[] = { 0.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 98765.4321f, 98765.4321f, 98765.4321f };
static const float b[] = { -0.0f, 1.0f, 1.0f, 1.0000001f, -9.8f, 1.000001f, 98765.436f, 98777.7777f, -98765.4321f };
@@ -151,9 +157,9 @@ static struct test_results rin_compare_float_test(void)
}
-static struct test_results rin_compare_double_test(void)
+static int rin_compare_double_test(void)
{
- struct test_results ret;
+ int ret;
size_t i;
static const double a[] = { 0.0, 1.0, -1.0, 1.0, -1.0f, 1.0, 98765.4321, 98765.4321, 98765.4321 };
static const double b[] = { -0.0, 1.0, 1.0, 1.0000000000000003, -9.8f, 1.000001, 98765.43210000002, 98777.7777, -98765.4321 };