-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.sh
165 lines (141 loc) · 2.67 KB
/
checker.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
#!/bin/bash
INPUT_DIR=tests/in
REF_DIR=tests/ref
OUTPUT_DIR=tests/out
mkdir -p "$OUTPUT_DIR"
SCORE=0
MAX_SCORE=120
trap ctrl_c INT
function ctrl_c() {
echo "Exiting..."
rm -rf byterun.log
rm -rf "$OUTPUT_DIR"
exit
}
print_header()
{
header="${1}"
header_len=${#header}
printf "\n"
if [ $header_len -lt 71 ]; then
padding=$(((71 - $header_len) / 2))
for ((i = 0; i < $padding; i++)); do
printf " "
done
fi
printf "= %s =\n\n" "${header}"
}
clean()
{
rm -rf byterun.log
}
function checkTest
{
clean
racket byterun.rkt "$INPUT_DIR/test_$1.in" > "$OUTPUT_DIR/test_$1.out" 2> /dev/null
if [ $? -eq 0 ]; then
`diff -Bw -u --ignore-all-space "$REF_DIR/test_$1.ref" byterun.log &> /dev/null`
DIFF_RESULT=$?
if [ $DIFF_RESULT -eq 0 ]; then
if (($1 >= 45 && $1 <= 49)); then
`diff "$REF_DIR/test_$1.out" "$OUTPUT_DIR/test_$1.out" &> /dev/null`
DIFF_RESULT=$?
if [ $DIFF_RESULT -eq 0 ]; then
result=1
SCORE=$((SCORE+$3))
echo -ne "+"$3": "
else
result=0
echo -ne "+"$3": "
fi
else
result=1
SCORE=$((SCORE+$3))
echo -ne "+"$3": "
fi
else
result=0
echo -ne "+"$3": "
fi
printf "Test $1 "
if [ "$1" -gt 9 ]; then
size=4
else
size=5
fi
for ((i = 0; i < $size; i++)); do
printf "."
done
echo -ne " $2 "
for ((i = 0; i < 56 - ${#2}; i++)); do
printf "."
done
printf " "
if [ $result -eq 1 ]; then
echo -ne "OK\n"
else
echo -ne "FAIL (files differ)\n"
diff "$REF_DIR/test_$1.ref" byterun.log
fi
else
echo -ne "-0.0: Test $1 .... $2 "
for ((i = 0; i < 56 - ${#2}; i++)); do
printf "."
done
echo -ne " "
echo -ne "FAIL (program error)\n"
fi
clean
}
print_header "Testing - Internal checker"
OUTPUT="$(racket checker.rkt)"
printf "$OUTPUT"
echo ""
score="${OUTPUT##*$'\n'}"
if [[ $score == "total"* ]]; then
score=$(echo $score | cut -d ' ' -f 2)
SCORE=${score%.*}
fi
print_header "Testing - PyPP byterun"
for i in {0..9}
do
checkTest $i "Test LOAD_CONST/STORE_FAST/LOAD_FAST" 1
done
printf "\n"
for i in {10..24}
do
checkTest $i "Test BINARY_ADD/BINARY_SUBTRACT/BINARY_MODULO" 2
done
printf "\n"
for i in {25..34}
do
checkTest $i "Test IF" 2
done
printf "\n"
for i in {35..44}
do
checkTest $i "Test FOR/WHILE" 2
done
printf "\n"
for i in {45..49}
do
checkTest $i "Bonus CALL_FUNCTION(print)" 1
done
printf "\n"
for i in {50..54}
do
checkTest $i "Bonus CALL_FUNCTION(range)" 1
done
printf "\n"
for i in {55..59}
do
checkTest $i "Bonus CALL_FUNCTION(sqrt)" 1
done
printf "\n"
for i in {60..64}
do
checkTest $i "Bonus CALL_FUNCTION(pow)" 1
done
printf "\n"
echo "Total ............... [$SCORE / $MAX_SCORE]"
rm -rf "$OUTPUT_DIR"