#!/bin/bash
source ./include.sh
./clean.sh

echo Compiling...
if [ -e ../solutions/$1.cpp ] ; then
	g++ -O2 -Wall ../solutions/$1.cpp -o ./$1.exe
fi
if [ -e ../solutions/$1.c ] ; then
	gcc -O2 -Wall ../solutions/$1.c -o ./$1.exe
fi
if [ -e ../solutions/$1.d ] ; then
	dmd -O -wi ../solutions/$1.d
fi
if [ -e ./$1.java ] ; then
	javac ./$1.java -d .
fi
if [ -e ../check.cpp ] ; then
	g++ -O2 -Wall ../check.cpp -o ../check.exe
fi

echo Testing solution...
rm -f $PROBLEM.out
export fullname=$1
#echo $fullname
export solname=${fullname##*/}
#echo $solname
for t in ../tests/??? ; do
	echo Test $t
	cp $t $PROBLEM.in
	if [ -e ./$1.py ] ; then
		python ./$1.py
	elif [ -e $solname.class ] ; then
		java -cp . -Xmx128M -Xss32M $solname
	else
		./$1.exe
	fi
	if [ -e ../check.exe ] ; then
		../check.exe $PROBLEM.in $PROBLEM.out $t.a
	fi
	mv $PROBLEM.out ../tests/$t.b
#	rm -f $PROBLEM.out
done
