Last active
August 29, 2015 14:07
-
-
Save potpath/890c64291a5f8c0983fd to your computer and use it in GitHub Desktop.
Simple grader written in shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ext=sol | |
if [ "$#" -lt 1 ] | |
then | |
echo "Usage: $0 [executable] code [input_output_solution_folder]" | |
exit 1 | |
fi | |
if [ -x "`which "$1"`" ] | |
then | |
bin=$1 | |
shift | |
else | |
bin=java | |
fi | |
code=$1 | |
if [ "$#" -lt 2 ] | |
then | |
folder=. | |
else | |
folder=$2 | |
fi | |
THR=1 #Time Limit | |
sum=0 | |
nCase=0 | |
nT=0 | |
nWrong=0 | |
max=0 | |
IFS=$'\n' | |
for input in `find "$folder" -name '*.in' | sort --version-sort` | |
do | |
let nCase++ | |
sol="${input%in}$ext" | |
time=`{ timeout "$THR" /usr/bin/time -f%e "$bin" "$code" < "$input" > /tmp/a; } 2>&1` | |
if [ ! "$time" ] | |
then | |
echo -n T | |
let nT++ | |
else | |
if ! diff --ignore-trailing-space "$sol" /tmp/a >/dev/null | |
then | |
echo -n - | |
let nWrong++ | |
else | |
#basename "$input" | |
#echo $time | |
sum=`bc <<< "$sum+$time"` | |
if [ `bc <<< "$max < $time"` -eq 1 ] | |
then | |
max="$time" | |
fi | |
if [ `bc <<< "$THR < $time"` -eq 0 ] | |
then | |
echo -n P | |
fi | |
fi | |
fi | |
done | |
rm /tmp/a 2>/dev/null | |
echo | |
#echo sum: $sum | |
echo mean: `bc -l <<< "$sum /( $nCase - $nT )"` | |
echo max: $max | |
echo number of test case: $nCase | |
echo number of T case: $nT | |
echo number of - case: $nWrong |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment