diff options
-rw-r--r-- | test/test_node.c | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/test/test_node.c b/test/test_node.c index 1a83e4cb..81ac3378 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -19,101 +19,15 @@ #include "serd/serd.h" #include <assert.h> -#include <float.h> -#include <math.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifndef INFINITY -# define INFINITY (DBL_MAX + DBL_MAX) -#endif -#ifndef NAN -# define NAN (INFINITY - INFINITY) -#endif - #define NS_XSD "http://www.w3.org/2001/XMLSchema#" static void -test_strtod(double dbl, double max_delta) -{ - char buf[1024]; - snprintf(buf, sizeof(buf), "%f", dbl); - - const char* endptr = NULL; - const double out = serd_strtod(buf, &endptr); - const double diff = fabs(out - dbl); - - assert(diff <= max_delta); -} - -static void -test_string_to_double(void) -{ - const double expt_test_nums[] = { - 2.0E18, -5e19, +8e20, 2e+24, -5e-5, 8e0, 9e-0, 2e+0}; - - const char* expt_test_strs[] = { - "02e18", "-5e019", "+8e20", "2E+24", "-5E-5", "8E0", "9e-0", " 2e+0"}; - - for (size_t i = 0; i < sizeof(expt_test_nums) / sizeof(double); ++i) { - const double num = serd_strtod(expt_test_strs[i], NULL); - const double delta = fabs(num - expt_test_nums[i]); - assert(delta <= DBL_EPSILON); - - test_strtod(expt_test_nums[i], DBL_EPSILON); - } -} - -static void -test_double_to_node(void) -{ - const double dbl_test_nums[] = {0.0, - 9.0, - 10.0, - .01, - 2.05, - -16.00001, - 5.000000005, - 0.0000000001, - NAN, - INFINITY}; - - const char* dbl_test_strs[] = {"0.0", - "9.0", - "10.0", - "0.01", - "2.05", - "-16.00001", - "5.000000005", - "0.0000000001", - NULL, - NULL}; - - for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { - SerdNode* node = serd_new_decimal(dbl_test_nums[i], NULL); - const char* node_str = node ? serd_node_string(node) : NULL; - const bool pass = (node_str && dbl_test_strs[i]) - ? !strcmp(node_str, dbl_test_strs[i]) - : (node_str == dbl_test_strs[i]); - assert(pass); - - const size_t len = node_str ? strlen(node_str) : 0; - assert((!node && len == 0) || serd_node_length(node) == len); - - if (node) { - const SerdNode* const datatype = serd_node_datatype(node); - assert(datatype); - assert(!dbl_test_strs[i] || - !strcmp(serd_node_string(datatype), NS_XSD "decimal")); - serd_node_free(node); - } - } -} - -static void test_integer_to_node(void) { const long int_test_nums[] = {0, -0, -23, 23, -12340, 1000, -1000}; @@ -285,8 +199,6 @@ test_blank(void) int main(void) { - test_string_to_double(); - test_double_to_node(); test_integer_to_node(); test_blob_to_node(); test_node_equals(); |