-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·45 lines (42 loc) · 1.39 KB
/
test.sh
File metadata and controls
executable file
·45 lines (42 loc) · 1.39 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
#Compile the code
# if the file ${cmd} exits then remove it
cmd=main
if [ -f ${cmd} ]; then
rm ${cmd}
fi
g++ -std=c++11 *.cpp -o ${cmd}
# if the file ${cmd} does not exit then exit the test
if [ ! -f ${cmd} ]; then
echo -e "\033[1;91mCompile FAILED.\033[0m"
exit
fi
# clean folder
for casenum in `seq 1 1 9`; do
if [ -f ${casenum}.out ]; then
rm ${casenum}.out
fi
if [ -f ${casenum}.stderr ]; then
rm ${casenum}.stderr
fi
if [ -f ${casenum}.stdcout ]; then
rm ${casenum}.stdcout
fi
done
# Run the code
for casenum in `seq 1 1 9`; do
./${cmd} "input=input${casenum}.txt;output=output${casenum}.txt" 1>${casenum}.stdcout 2>${casenum}.stderr
# compare output1.txt with ans1.txt, output the difference to 1.diff
diff -iBwu ans${casenum}.txt output${casenum}.txt > ${casenum}.diff
# if diff returns nothing, it means you pass the test case (Your output file 1.out is correct)
if [ $? -ne 0 ]; then
# display "test case 1 FAILED" to the screen. The word "FAILED" is highlighted in Red color
echo -e "Test case ${casenum} \033[1;91mFAILED.\033[0m"
else
# display "test case 1 PASSED" to the screen. The word "PASSED" is highlighted in Green color
echo -e "Test case ${casenum} \033[1;92mPASSED.\033[0m"
# remove the file 1.diff
rm -f ${casenum}.diff
rm -f ${casenum}.stderr
rm -f ${casenum}.stdcout
fi
done