#!/bin/bash

if [ $# -lt 1 ]; then
	echo "Usage: evaluate [-g] <binary>"
	exit 1
fi

gen=0
prog=$1
if [ $1 = "-g" ]; then
	gen=1
	prog=$2
fi

echo -n "["

score=0

for ((i=1;i<11;i++)); do
	infile=bus.0$i.in
	outfile=bus.0$i.out
	if [ $i -gt 9 ]; then
		infile=bus.$i.in
		outfile=bus.$i.out
	fi
	#
	cp $infile bus.in
	if [ $gen -eq 0 ]; then
		cp $outfile bus.judge
		./run_test $prog 1> stdout 2> stderr
		result=`./eval_test`
		if [ $result = "0" ]; then
			score=`expr $score + 10`
			echo -n "."
		fi
		if [ $result = "1" ]; then
			echo -n "W"
		fi
		if [ $result = "2" ]; then
			echo -n "T"
		fi
		if [ $result = "3" ]; then
			echo -n "!"
		fi
	else
		./$prog < bus.in > $outfile
		echo -n "+"
	fi
done

echo -n "] "
if [ $gen -eq 0 ]; then
	echo "$prog gets $score points."
else
	echo "."
fi
