4 #include <cln/number.h>
9 // Michael Stoll 23. 3. 1993
10 // C++ version: Bruno Haible 1.11.1995
43 #define num_elements(array) (sizeof(array)/sizeof(array[0]))
45 #define DO_BINOP_TEST(typename,type,rtype,opname,op) \
46 static int test_##typename##_##opname (void) \
49 for (unsigned int i = 0; i < num_elements(typename##_##opname##_tests); i++) { \
50 opname##_test& test = typename##_##opname##_tests[i]; \
51 type arg1 = type(test.arg1); \
52 type arg2 = type(test.arg2); \
53 rtype computed_result = arg1 op arg2; \
54 rtype result = rtype(test.result); \
55 if (computed_result != result) { \
56 std::cerr << "Error in " #typename "_" #opname "_tests[" << i << "] !" << endl; \
57 std::cerr << "Result should be: " << result << endl; \
58 std::cerr << "Result computed : " << computed_result << endl << endl; \
65 #define DO_FLOOR_TEST(typename,type) \
66 static int test_##typename##_floor (void) \
69 for (unsigned int i = 0; i < num_elements(typename##_floor_tests); i++) { \
70 floor_test& test = typename##_floor_tests[i]; \
71 type arg1 = type(test.arg1); \
72 type arg2 = type(test.arg2); \
73 type##_div_t computed_result = floor2(arg1,arg2); \
74 cl_I result1 = cl_I(test.result1); \
75 type result2 = type(test.result2); \
76 if ((computed_result.quotient != result1) || (computed_result.remainder != result2)) { \
77 std::cerr << "Error in " #typename "_floor_tests[" << i << endl; \
78 std::cerr << "Results should be: " << result1 << ", " << result2 << endl; \
79 std::cerr << "Results computed : " << computed_result.quotient << ", " << computed_result.remainder << endl << endl; \
86 #define DO_TESTS(typename,type,qtype) \
87 DO_BINOP_TEST(typename,type,type,plus,+) \
88 DO_BINOP_TEST(typename,type,type,minus,-) \
89 DO_BINOP_TEST(typename,type,type,mul,*) \
90 DO_FLOOR_TEST(typename,type) \
91 DO_BINOP_TEST(typename,type,qtype,div,/) \
92 int test_##typename (void) \
95 error |= test_##typename##_plus(); \
96 error |= test_##typename##_minus(); \
97 error |= test_##typename##_mul(); \
98 error |= test_##typename##_floor(); \
99 error |= test_##typename##_div(); \