7 // Michael Stoll 23. 3. 1993
8 // C++ version: Bruno Haible 1.11.1995
41 #define num_elements(array) (sizeof(array)/sizeof(array[0]))
43 #define DO_BINOP_TEST(typename,type,rtype,opname,op) \
44 static int test_##typename##_##opname (void) \
47 for (unsigned int i = 0; i < num_elements(typename##_##opname##_tests); i++) { \
48 opname##_test& test = typename##_##opname##_tests[i]; \
49 type arg1 = type(test.arg1); \
50 type arg2 = type(test.arg2); \
51 rtype computed_result = arg1 op arg2; \
52 rtype result = rtype(test.result); \
53 if (computed_result != result) { \
54 fprint(cl_stderr, "Error in " #typename "_" #opname "_tests["); \
55 fprintdecimal(cl_stderr, i); \
56 fprint(cl_stderr, "] !\n"); \
57 fprint(cl_stderr, "Result should be: "); \
58 fprint(cl_stderr, result); \
59 fprint(cl_stderr, "\n"); \
60 fprint(cl_stderr, "Result computed : "); \
61 fprint(cl_stderr, computed_result); \
62 fprint(cl_stderr, "\n"); \
63 fprint(cl_stderr, "\n"); \
70 #define DO_FLOOR_TEST(typename,type) \
71 static int test_##typename##_floor (void) \
74 for (unsigned int i = 0; i < num_elements(typename##_floor_tests); i++) { \
75 floor_test& test = typename##_floor_tests[i]; \
76 type arg1 = type(test.arg1); \
77 type arg2 = type(test.arg2); \
78 type##_div_t computed_result = floor2(arg1,arg2); \
79 cl_I result1 = cl_I(test.result1); \
80 type result2 = type(test.result2); \
81 if ((computed_result.quotient != result1) || (computed_result.remainder != result2)) { \
82 fprint(cl_stderr, "Error in " #typename "_floor_tests["); \
83 fprintdecimal(cl_stderr, i); \
84 fprint(cl_stderr, "] !\n"); \
85 fprint(cl_stderr, "Results should be: "); \
86 fprint(cl_stderr, result1); \
87 fprint(cl_stderr, ", "); \
88 fprint(cl_stderr, result2); \
89 fprint(cl_stderr, "\n"); \
90 fprint(cl_stderr, "Results computed : "); \
91 fprint(cl_stderr, computed_result.quotient); \
92 fprint(cl_stderr, ", "); \
93 fprint(cl_stderr, computed_result.remainder); \
94 fprint(cl_stderr, "\n"); \
95 fprint(cl_stderr, "\n"); \
102 #define DO_TESTS(typename,type,qtype) \
103 DO_BINOP_TEST(typename,type,type,plus,+) \
104 DO_BINOP_TEST(typename,type,type,minus,-) \
105 DO_BINOP_TEST(typename,type,type,mul,*) \
106 DO_FLOOR_TEST(typename,type) \
107 DO_BINOP_TEST(typename,type,qtype,div,/) \
108 int test_##typename (void) \
111 error |= test_##typename##_plus(); \
112 error |= test_##typename##_minus(); \
113 error |= test_##typename##_mul(); \
114 error |= test_##typename##_floor(); \
115 error |= test_##typename##_div(); \