-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautograder.sh
41 lines (40 loc) · 1.17 KB
/
autograder.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
#!/bin/bash
[ -e results.txt ] && rm results.txt
touch test.txt
if [ ! -d "./submissions" ]
then
mkdir submissions
fi
if [ ! -f "results.txt" ]
then
touch results.txt
fi
unzip ./submissions.zip -d submissions
args=$(head -n 1 sampleInput.txt)
for file in ./submissions/*.cpp; do
echo "Processing submission ${file##*/}"
sed -i 's/^#include/\n#include <math.h>\n#include/g' $file
sed -i '0,/^int main()/s//int main(int argc, char** argv)/' $file
MAIN=$(grep -n "int main" $file | cut -d: -f1)
CIN=$(tail -n +$MAIN $file | grep -in "cin >> n" | head -1 | cut -d: -f1)
LAST=$(($MAIN + $CIN))
sed -i "$MAIN,$LAST s/cin >> n/\/\/cin >> n;\n\tn = atoi(argv[1])/" $file
output=$(g++ $file 2>&1)
if [[ $? != 0 ]];
then
echo "${file##*/} DOESN'T, COMPILE" >> results.txt
else
./a.out $args > test.txt
diff_lines=`diff test.txt \
expectedOutput.txt\
--ignore-space-change --ignore-case | egrep -c "^<|^>"`
if [ $diff_lines == 0 ]
then
echo "${file##*/}, CORRECT" >> results.txt
else
diff_files=$((diff_files+1))
echo "${file##*/}, INCORRECT" >> results.txt
fi
fi
done
rm test.txt