fixed lots of warnings in testprograms
[libfirm] / ir / be / test / if.c
1 #include <stdio.h>
2 #include <assert.h>
3
4 int test1(int a)
5 {
6         return a == 0;
7 }
8
9 int test2(int a, int b)
10 {
11         return a == b;
12 }
13
14 int test2a(int a, int b)
15 {
16         return a != b;
17 }
18
19 int test3(int a, int b)
20 {
21         return a == 0 && b + 1 < 10;
22 }
23
24 int test4(int a, int b)
25 {
26         return a == 0 || b + 1 < 10;
27 }
28
29 int test5(int a, int b)
30 {
31         return a > b ? a : b - 1;
32 }
33
34 int test6(int a, int b)
35 {
36         return a < 0 ? -1 : (a > 0 ? 1 : 0);
37 }
38
39 int test6a(int a, int b)
40 {
41         if(a < b)
42                 ;
43         else
44                 ;
45
46         return 0;
47 }
48
49 int test7(int a, int b)
50 {
51         int i, res = 0;
52
53         for(i = 0; i < a; ++i)
54                 res += i * b;
55
56         return res;
57 }
58
59 int test8(int a, int b, int c)
60 {
61         return a < b ? (a < c ? a : c) : (b < c ? b : c);
62 }
63
64 int test9(int a, int b)
65 {
66         return a ? b : b;
67 }
68
69 int main()
70 {
71 #define TU(t,a,s)       printf("%s(%d) = %d (should be %d)\n", \
72                            #t, a, t(a), s); \
73                     assert(t(a) == s);
74
75 #define TB(t,a,b,s)     printf("%s(%d,%d) = %d (should be %d)\n", \
76                             #t, a, b, t(a,b), s); \
77                     assert(t(a,b) == s);
78
79 #define TT(t,a,b,c,s)   printf("%s(%d,%d,%d) = %d (should be %d)\n", \
80                             #t, a, b, c, t(a,b,c), s); \
81                     assert(t(a,b,c) == s);
82
83
84         TU(test1, 0, 1);
85         TU(test1, 42, 0);
86
87         TB(test2, 0, 0, 1);
88         TB(test2, -23, -23, 1);
89         TB(test2, 0, 42, 0);
90         TB(test2, -1, 0, 0);
91
92         TB(test2a, 0, 0, 0);
93         TB(test2a, -23, -23, 0);
94         TB(test2a, 0, 42, 1);
95         TB(test2a, -1, 0, 1);
96
97         TB(test3, 0, 8, 1);
98         TB(test3, 0, -200, 1);
99         TB(test3, 0, 10, 0);
100         TB(test3, 42, 8, 0);
101         TB(test3, -1, -200, 0);
102         TB(test3, -1, 10, 0);
103
104         TB(test4, 0, 8, 1);
105         TB(test4, 0, -200, 1);
106         TB(test4, 0, 10, 1);
107         TB(test4, 42, 8, 1);
108         TB(test4, -1, -200, 1);
109         TB(test4, -1, 10, 0);
110
111         TB(test5, 42, -1, 42);
112         TB(test5, 1, 0, 1);
113         TB(test5, 0, 1, 0);
114         TB(test5, -1, 42, 41);
115
116         TB(test6, -5, 42, -1);
117         TB(test6, -20, -1, -1);
118         TB(test6, 20, -1, 1);
119         TB(test6a, 42, -1, 0);
120
121         TB(test7, 3, 2, 6);
122
123         TT(test8, 0, 2, 3, 0);
124         TT(test8, 0, 2, 1, 0);
125         TT(test8, -1, 42, 5, -1);
126         TT(test8, -7, 4, -42, -42);
127         TT(test8, 0, 2, -1, -1);
128         TT(test8, 24, 123, 7, 7);
129
130         TB(test9, 3, 2, 2);
131         TB(test9, -42, -42, -42);
132
133         return 0;
134 }