-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·105 lines (102 loc) · 5.55 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
test_() {
expected="$1"
input="$2"
./mdcc -e "$input" > tmp.s
gcc -arch x86_64 -o tmp tmp.s
./tmp
actual="$?"
if [ "$actual" == "$expected" ]; then
echo "$input => $actual"
else
echo "$input => $expected expected, but got $actual"
exit 1
fi
}
NL=$'\n'
test_ 1 "int main() { return 1;}"
test_ 3 "int main() {return 1 + 2;}"
test_ 6 "int main() { return 3 * 2;}"
test_ 2 "int main() {return 4 / 2;}"
test_ 14 "int main() { return 3*2 + 2*4;}"
test_ 6 "int main() {return (1+2) * (5-3);}"
test_ 3 "int main() { 4 / 2; return 2 + 1;}"
test_ 3 "int main() { int a = 3; return a;}"
test_ 7 "int main() { int a = 1 + 2 * 3; return a;}"
test_ 2 "int main() { int a = 1; return a + 1;}"
test_ 1 "int z() { return 1; } int main() { return z(); }"
test_ 3 "int z() { return 1; } int main() { return z() * 2 + 1; }"
test_ 2 "int main() { int a = 1; int b = 2; return b; }"
test_ 3 "int main() { int test1 = 1; int test2 = 2; int test3 = 3; int test4 = 4; int test5 = 5; return test3; }"
test_ 48 "int main() { return '0'; }"
test_ 97 "int main() { int a = 'a'; return a;}"
test_ 2 "int main() { int a = 1; a = 2; return a;}"
test_ 1 "int main() { int a = 1; int *b = &a; return *b; }"
test_ 2 "int main() { int a = 1; a *= 2; return a; }"
test_ 1 "int main() { int a = 2; a /= 2; return a; }"
test_ 2 "int main() { int a = 1; a += 1; return a; }"
test_ 1 "int main() { int a = 2; a -= 1; return a; }"
test_ 2 "int main() { int a = 1; { a = 2; } return a;}"
test_ 1 "int main() { int a = 1; { int a = 2; } return a;}"
test_ 1 "int z(int a) { return a; } int main() { return z(1); }"
test_ 44 "int sum(int a, int b, int c, int d, int e, int f) { return a*b + c*d + e*f; } int main() { return sum(1, 2, 3, 4, 5, 6); }"
test_ 123 "int main() { return 123;}"
test_ 1 "int main() { if (1) { return 1; } return 0;}"
test_ 0 "int main() { if (0) { return 1; } return 0;}"
test_ 2 "int main() { if (0) { return 1;} else { return 2;} return 3;}"
test_ 2 "int main() { int a = 1; if (a-1) { return 1; } else if (a) { return 2; } else { return 3; }}"
test_ 0 "int main() { int a = 1; int b = 1; if (a == b) { return 0; } else { return 1; }}"
test_ 1 "int main() { int a = 1; int b = 2; if (a == b) { return 0; } else { return 1; }}"
test_ 1 "int main() { int a = 1; int b = 1; if (a != b) { return 0; } else { return 1; }}"
test_ 0 "int main() { int a = 1; int b = 2; if (a != b) { return 0; } else { return 1; }}"
test_ 1 "int main() { int a; return 1; }"
test_ 1 "int main() { int a[1]; return 1; }"
test_ 1 "int main() { int a[2]; a[1] = 1; return a[1]; }"
test_ 3 "int main() { int a[2]; a[0] = 1; a[1] = 2; return a[0]+a[1]; }"
test_ 6 "int main() { int a[2][2]; a[0][0] = 1; a[0][1] = 2; a[1][1] = 3; return a[0][0] + a[0][1] + a[1][1]; }"
# test_ 6 "int main() { int a[2][2][1]; a[0][0][0] = 1; a[0][1][0] = 2; a[1][0][0] = 3; return a[0][0][0] + a[0][1][0] + a[1][0][0]; }"
test_ 1 "int f(int a[1]) { return a[0]; } int main() {int a[1]; a[0] = 1; return f(a); }"
test_ 1 "int f(int a[2]) { return a[1]; } int main() {int a[2]; a[1] = 1; return f(a); }"
test_ 1 "int f(int a[2][2]) { return a[1][0]; } int main() {int a[2][2]; a[1][0] = 1; return f(a); }"
test_ 2 "int f(int *a) { *a = 2; return 0; } int main() { int a; a = 1; f(&a); return a;}"
test_ 2 "int main() { int a; int b; for (a = 0; a != 3; a = a + 1) {b = a;} return b; }"
test_ 1 "int main() { int a[1]; int i = 0; for (i = 0; i != 1; i = i + 1) { a[i] = 1; } return a[0]; }"
test_ 1 "int main() { int a[2][2]; a[1][1] = 1; return a[1][1]; }"
test_ 2 "int main() { int a[2][2]; int i; int j; for (i = 0; i != 2; i = i + 1) { for (j = 0; j != 2; j = j + 1) { a[i][j] = i + j; }} return a[1][1]; }"
test_ 1 "int main() { int a; a = 3; while (a != 1) { a = a - 1; } return a; }"
test_ 1 "int main() { int a = 11; a = a % 10; return a;}"
test_ 1 "int main() { return 1 < 2; }"
test_ 0 "int main() { return 2 < 1; }"
test_ 1 "int main() { return 2 > 1; }"
test_ 0 "int main() { return 1 > 2; }"
test_ 4 "int main() { return 1 << 2; }"
test_ 1 "int main() { return 4 >> 2; }"
test_ 4 "int main() { int a = 1; a <<= 2; return a; }"
test_ 1 "int main() { int a = 4; a >>= 2; return a; }"
test_ 1 "int main() { return 2 && 3; }"
test_ 0 "int main() { return 2 && 0; }"
test_ 1 "int main() { return 2 || 0; }"
test_ 0 "int main() { return 0 || 0; }"
test_ 4 "int main() { return 7 & 4; }"
test_ 4 "int main() { int a = 7; a &= 4; return a; }"
test_ 7 "int main() { return 2 | 5; }"
test_ 7 "int main() { int a = 2; a |= 5; return a; }"
test_ 3 "int main() { return 6 ^ 5; }";
test_ 3 "int main() { int a = 6; a ^= 5; return a; }";
test_ 2 "int main() { int a = 1; int b = ++a; return b; }"
test_ 1 "int main() { int a = 2; int b = --a; return b; }"
test_ 3 "int main() { int a = 1; int b = a++; return a+b; }"
test_ 3 "int main() { int a = 1; int b = a++; return a+b; }"
test_ 3 "int main() { int a = 1; int b = 1; a = a++ + ++b; return a; }"
test_ 3 "int main() { int a = 2; int b = a--; return a+b; }"
test_ 1 "int main() { int a = 255; a += 2; return a == 257; }"
test_ 1 "int main() { char a = 255; a += 2; return a == 1; }"
test_ 1 "int main() { char a = 255; a++; a++; return a == 1; }"
test_ 1 "int f(char a) { return a+2; } int main() { return f(255) == 1; }"
test_ 2 "int main() { char a = 1; char b = a + 1; return b;}"
test_ 1 "int main() { char a = 1; char *b = &a; return *b; }"
test_ 1 "int main() { int a = /** a =** 2;/* **/1; return a; }"
test_ 1 "int main() { int a = 1; // a = 2;${NL} return a; }"
test_ 6 "int main() { int a[3] = {1, 2, 3}; return a[0]+a[1]+a[2]; }"
test_ 6 "int main() { int a[] = {1, 2, 3}; return a[0]+a[1]+a[2]; }"
echo OK