1 #include <cl_integer.h>
2 #include <cl_integer_io.h>
7 fprint(cl_stderr,"Assertion failed! File "); \
8 fprint(cl_stderr,__FILE__); \
9 fprint(cl_stderr,", line "); \
10 fprintdecimal(cl_stderr,__LINE__); \
11 fprint(cl_stderr,".\n"); \
21 #define num_elements(array) (sizeof(array)/sizeof(array[0]))
23 // Note: This macro differs slightly from the one in "exam.h".
24 #define DO_BINOP_TEST(typename,type,rtype,opname) \
25 static int test_##typename##_##opname (void) \
28 for (unsigned int i = 0; i < num_elements(typename##_##opname##_tests); i++) { \
29 opname##_test& test = typename##_##opname##_tests[i]; \
30 type arg1 = type(test.arg1); \
31 type arg2 = type(test.arg2); \
32 rtype computed_result = opname(arg1,arg2); \
33 rtype result = rtype(test.result); \
34 if (computed_result != result) { \
35 fprint(cl_stderr, "Error in " #typename "_" #opname "_tests["); \
36 fprintdecimal(cl_stderr, i); \
37 fprint(cl_stderr, "] !\n"); \
38 fprint(cl_stderr, "Result should be: "); \
39 fprint(cl_stderr, result); \
40 fprint(cl_stderr, "\n"); \
41 fprint(cl_stderr, "Result computed : "); \
42 fprint(cl_stderr, computed_result); \
43 fprint(cl_stderr, "\n"); \
44 fprint(cl_stderr, "\n"); \
51 static gcd_test integer_gcd_tests[] = {
52 { "123456789", "345", "3" },
53 { "345", "123456789", "3" },
56 { "2523533737", "855322739", "1" },
57 { "855322739", "2523533737", "1" },
58 { "101611479673163974026724715741235467160607959655653420075620", "533177863832047932237026621580126811198495699416238676294977", "1" },
59 { "30729415811", "323233683197", "31071199" },
60 { "77874422", "32223899", "1" },
61 { "974507656412513757857315037382926980395082974811562770185617915360", "-1539496810360685510909469177732386446833404488164283", "1" }
64 DO_BINOP_TEST(integer,cl_I,cl_I,gcd)
69 error |= test_integer_gcd();
81 cl_I g = xgcd(a,b, &u,&v);
84 ASSERT(u == -9206830);
85 ASSERT(v == 22249839);
92 cl_I g = xgcd(a,b, &u,&v);
95 ASSERT(u == 77165803);
96 ASSERT(v == -138134388);
99 cl_I a = "#x80000000";
100 cl_I b = "#x-C0000000";
103 cl_I g = xgcd(a,b, &u,&v);
104 ASSERT(g == (cl_I)"#x40000000");
105 ASSERT(g == a*u+b*v);
110 cl_I a = "974507656412513757857315037382926980395082974811562770185617915360";
111 cl_I b = "-1539496810360685510909469177732386446833404488164283";
114 cl_I g = xgcd(a,b, &u,&v);
116 ASSERT(g == a*u+b*v);