-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecker
executable file
·195 lines (155 loc) · 3.01 KB
/
checker
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
187
188
189
190
191
192
193
194
195
#!/bin/bash
#SETTINGS
detailed=true
usage() {
echo "Usage: first argument is program being checked; second argument is correct program to check answers."
echo "Each of next arguments should contain tests. It may be name of file or name of directory with files. Each file should contain input for one test."
}
under_test="$1"
reliable_test="$2"
#STATISTICS
tests="0"
succ="0"
unsucc="0"
miss="0"
fcrash="0"
scrash="0"
#COLORS
R="\e[00;31m"
Y="\e[01;33m"
G="\e[00;32m"
N="\e[00m"
declare -a result
add_result() {
result=("${result[@]}" "$1")
}
if [ "$#" -le "1" ]
then
usage
exit 1
elif [ "$#" -eq "2" ]
then
echo "You should provide at least one test"
echo ""
usage
exit 2
fi
if [ ! -x "$under_test" ]
then
echo "First argument is incorrect"
echo ""
usage
exit 3
fi
if [ ! -x "$reliable_test" ]
then
echo "Second argument is incorrect"
echo ""
usage
exit 3
fi
check_file() {
let "tests++"
local_result="$1"
if $detailed
then
echo "Testing on input $1:"
echo "----------INPUT BEGINS"
cat "$1"
echo "----------INPUT ENDS"
echo
fi
first=$(cat "$1" | "$under_test")
first_exit="$?"
if $detailed
then
echo "Program $under_test ended with exit code $first_test"
echo "----------OUTPUT BEGINS"
echo "$first"
echo "----------OUTPUT ENDS"
echo
fi
second=$(cat "$1" | "$reliable_test")
second_exit="$?"
if $detailed
then
echo "Program $reliable_test ended with exit code $second_test"
echo "----------OUTPUT BEGINS"
echo "$second"
echo "----------OUTPUT ENDS"
echo
fi
if [ "$first_exit" -eq "0" -a "$second_exit" -eq "0" ]
then
if [ "$first" = "$second" ]
then
let "succ++"
local_result="$local_result\t${G}OK${N}"
echo -e "Test ${G}OK${N}"
else
let "unsucc++"
let "miss++"
local_result="$local_result\t${Y}FAILED\tincorrect result${N}"
echo -e "Test ${Y}FAILED: INCORECT RESULT${N}"
fi
else
let "unsucc++"
local_result="$local_result\t${R}ERROR"
echo -e "Testing ${R}ERROR"
if [ "$first_exit" -ne "0" ]
then
let "fcrash++"
local_result="$local_result\tfirst program crashed"
echo "First program crashed"
fi
if [ "$second_exit" -ne "0" ]
then
let "scrash++"
local_result="$local_result\tsecond program crashed"
echo "Second program crashed"
fi
echo -e "${N}"
local_result="$local_result${N}"
fi
local_result="$local_result\n"
echo
echo
add_result "$local_result"
}
check_dir() {
for file in $(ls -1 "$1")
do
check_file "$1/$file"
done
}
recursive_check() {
if [ -d "$1" ]
then
for file in $(ls -1 "$1")
do
recursive_check "$1/$file"
done
else
check_file "$1"
fi
}
shift 2
for arg in $@
do
recursive_check "$arg"
done
echo
echo
echo "-----------------------------------"
echo
echo "Summary:"
echo -e -n " ${result[@]}"
echo
echo "Statistics: $tests test(s)"
echo -e "\t$succ successful"
echo -e "\t$unsucc unsuccessful"
echo "Unsuccessful tests statistics:"
echo -e "\t$miss wrong results"
echo -e "\t$fcrash crashes of first program"
echo -e "\t$scrash crashes of second program"
exit 0