forked from KNU-HAEDAL/bootcamp_division_homework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade.sh
executable file
·98 lines (80 loc) · 2.36 KB
/
grade.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
#!/bin/bash
# * Original Code
# * Author: kiryanchi
# * Author's Github: https://github.com/kiryanchi
DIR_PATH=`dirname $0`
IS_PASS=true
if [ "$1" == "c" ]; then
echo "C 채점을 시작합니다."
if ! (which gcc >/dev/null); then
echo "GCC가 없습니다. 채점을 종료합니다."
exit 1
fi
else
echo "Python 채점을 시작합니다."
if ! (which python3 >/dev/null); then
if ! (which python >/dev/null); then
echo "설치된 python이 없습니다. 채점을 종료합니다."
exit 1
fi
fi
fi
function python_result() {
# $1: index of problem, $2: input file, $3: output file
if ! (which python3 >/dev/null); then
result=`cat $2 | python ./python/$1.py | tr -d '\r' | tr -d '\t'`
else
result=`cat $2 | python3 ./python/$1.py | tr -d '\r' | tr -d '\t'`
fi
output=`cat $3 | tr -d '\r' | tr -d '\t'`
if [ "$result" == "$output" ]
then
echo "Success"
else
echo "Fail"
fi
}
function c_result() {
# $1: index of problem, $2: input file, $3: output file
gcc ./c/$1.c -o ./c/$1.out -w
result=`cat $2 | ./c/$1.out | tr -d '\r' | tr -d '\t'`
output=`cat $3 | tr -d '\r' | tr -d '\t'`
if [ "$result" == "$output" ]
then
echo "Success"
else
echo "Fail"
fi
}
for index_of_problem in {1..9}
do
for index_of_answer in {1..5}
do
input_file=$DIR_PATH/answer/$index_of_problem/in$index_of_answer.txt
output_file=$DIR_PATH/answer/$index_of_problem/out$index_of_answer.txt
if ! ( test -f "$input_file" ); then
echo "$input_file 존재하지 않음"
exit 1
fi
if ! ( test -f "$output_file" ); then
echo "$output_file 존재하지 않음"
exit 1
fi
if [ "$1" == "c" ]; then
result=$(c_result $index_of_problem $input_file $output_file)
else
result=$(python_result $index_of_problem $input_file $output_file)
fi
echo "TEST $index_of_problem-$index_of_answer: $result"
if [ "$result" == "Fail" ]
then
echo "[에러] $index_of_problem번 문제의 답이 틀립니다 ;("
IS_PASS=false
break
fi
done
done
echo "채점이 종료되었습니다 :)"
if [ $IS_PASS == false ]; then
exit 1
fi