-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
89 lines (75 loc) · 1.91 KB
/
test.sh
File metadata and controls
89 lines (75 loc) · 1.91 KB
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
if [ ! -d "./tests" ]; then
echo "Error: tests directory not found!"
exit 1
fi
if [ ! -e "./a.out" ]; then
echo "Error: a.out not found!"
exit 1
fi
if [ ! -x "./a.out" ]; then
echo "Error: a.out not executable"
exit 1
fi
usage()
{
echo
echo "Usage: $0 [test]"
echo
echo "Where test is the name of the desired test"
echo
exit 1
}
# if [[ ! "$1" =~ ^[0-9]+$ ]]; then
# echo "Error: argument is not a number"
# usage
# fi
# if [ "$1" -lt "1" -o "$1" -gt "5" ]; then
# echo "Error: argument must be a number in range [1..5]"
# usage
# fi
mkdir -p ./output
if [ "$#" -gt "0" ]; then
test_file=./tests/$1
echo $test_file
name=`basename ${test_file} .txt`
expected_file=${test_file}.expected
output_file=./output/${name}.output
diff_file=./output/${name}.diff
./a.out ${taskNumber} < ${test_file} > ${output_file}
diff -Bw ${expected_file} ${output_file} > ${diff_file}
echo
if [ -s ${diff_file} ]; then
echo "${name}: Output does not match expected:"
echo "------------------------------------------------------"
cat ${diff_file}
else
echo "${name}; OK"
fi
echo "======================================================="
else
let count=0
let all=0
for test_file in $(find ./tests -type f -name "*.txt" | sort); do
all=$((all+1))
name=`basename ${test_file} .txt`
expected_file=${test_file}.expected
output_file=./output/${name}.output
diff_file=./output/${name}.diff
./a.out ${taskNumber} < ${test_file} > ${output_file}
diff -Bw ${expected_file} ${output_file} > ${diff_file}
echo
if [ -s ${diff_file} ]; then
echo "${name}: Output does not match expected:"
echo "------------------------------------------------------"
cat ${diff_file}
else
count=$((count+1))
echo "${name}; OK"
fi
echo "======================================================="
done
echo
echo "Passed $count tests out of $all for task ${taskNumber}"
echo
fi
rm -rf ./output