-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·186 lines (177 loc) · 2.79 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
try() {
expected="$1"
input="$2"
./9cc "$input" > tmp.s
gcc -c foo.c
gcc -o tmp tmp.s foo.o
./tmp
actual="$?"
if [ "$actual" == "$expected" ]; then
echo "$input => $actual"
else
echo "$input => $expected expected, but got $actual"
exit 1
fi
}
try 0 "main() {return 0;}"
try 21 "main() {return 5+20-4;}"
try 47 "main() {return 5+6*7;}"
try 15 "main() {return 5*(9-6);}"
try 4 "main() {return (3+5)/2;}"
try 9 "main() {return -3*-3;}"
try 1 "main() {return 1 < 3;}"
try 0 "main() {return 1 > 3;}"
try 1 "main() {return 1 <= 4;}"
try 4 "main() {return (1 >= 5) + 4 * 1;}"
try 1 "main() {return 1 == 1;}"
try 0 "main() {return 1 != 1;}"
try 3 "main() {a = 5; b=-2; return a+b;}"
try 3 "main() {foo= 5; bar=-2; ans=foo+bar; return ans;}"
try 14 "main() {
a = 3;
b = 5 * 6 - 8;
return a + b / 2;}"
try 4 "main() {
i = 1; num = 3; if (i == 1)
num = 4;
return num;
}"
try 3 "main() {
i = 0; num = 3; if (i == 1)
num = 4;
return num;
}"
try 5 "main() {
i = 0; num = 3; if (i == 1)
num = 4;
else
num=5;
return num;
}"
try 3 "main() {i = 1; n=3; while (i < n)
i = i+1;
return i;
}"
try 100 "main() {i = 1; n=100; while (i < n)
i = i+1;
return i;
}"
try 4 "main() {ans = 0; n=5; for (i=1;i<n;i = i+2)
ans = ans + i;
return ans;
}"
try 6 "main() {
i = 0; n=4; ans = 0; while (i < n) {
ans = ans + i;
i = i + 1;
}
return ans;
}"
try 1 "main() {i = 0; n=4; if (i < n) {
i = i + 2;
i = i - 1;
}
return i;
}"
try 5 "
main() {
n = 3;
if (n==0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return 5;
}
}
"
try 1 "
main() {
n = 1;
if (n==0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return 5;
}
}
"
try 1 "main() {foo(); return 1;}"
try 1 "main() {fooo(3, 4); return 1;}"
try 55 "
main() {m = 1;
n = 10;
acc = 0;
for (i = m; i <= n; i = i + 1)
acc = acc + i;
return acc;}"
try 9 "sum() {
a = 3;
b = 6;
return a+b;
}
main() {
return sum();
}
"
try 9 "sum(m, n) {
return m+n;
}
main() {
return sum(3,6);
}
"
try 55 "
sum(m, n) {
acc = 0;
for (i = m; i <= n; i = i + 1)
acc = acc + i;
return acc;
}
main() {
return sum(1, 10);
}
"
try 7 "
sum(n) {
if (n==3) {
return 3;
}
if (n==4) {
return 4;
}
return sum(3) + sum(4);
}
main() {
return sum(0);
}
"
try 120 "
factorial(n) {
if(n == 0) {
return 1;
} else {
return n * factorial(n-1);
}
}
main() {
return factorial(5);
}
"
try 5 "
fibbonacci(n) {
if(n == 0){
return 0;
} else if(n == 1) {
return 1;
} else {
return fibbonacci(n-1) + fibbonacci(n-2);
}
}
main() {
return fibbonacci(5);
}
"
echo Ok