#!/bin/bash 

if [ "${#}" -lt 1 ];
then
	echo usage: ./test num
	echo where num is the number of which test you want to run
	exit 2
fi

exec 2> err

mainX=main1

echo -n "### test ${1}"
cp test${1} $mainX
rm -rf a.out
gcc -std=c99 -include stdbool.h test.c
if [ "${?}" -eq 0 ];
then
	rm -f out err
	./a.out > out 2> err
	if [ "${?}" -eq "0" ];
	then
		out1=`grep pass out | wc -l`
		out2=`grep fail out | wc -l`
#		echo "  passed $out1 tests"#
#		echo "  failed $out2 tests"
		echo "   grade = $(( 4 - (4*$out2)/($out1 + $out2))) / 4"
	else
		echo "   grade = 0 / 4"
	fi
else
	echo "  compile error"
fi
