#!/bin/bash


export PYTHONPATH=$PYTHONPATH:$PWD/../../pyCmpl/lib:$PWD/../../cmplServer
export PYTHONSTARTUP=$PWD/../../pyCmpl/lib/pyCmpl/pyCmplShell.py

if  [[ $OSTYPE == *msys* ]] ; then
	export CMPLBINARY=$PWD/../../Cmpl/bin/cmpl.exe
	export PythonBin=$PWD/../../Cmpl/Thirdparty/pypy/pypy $*
else
	export CMPLBINARY=$PWD/../../Cmpl/bin/cmpl
	export PythonBin=python 
fi

if (test -f jCmplTest/dist/jCmplTest.jar); then 

	touch diet-local.time
	touch diet-remote.time
	touch shortest-path.time

	echo "######### start jCmpl tests ##############################"
	
	if  [[ $OSTYPE != *msys* ]] ; then
		./cmplServerTest -start 9999
		echo "CmplServer has started"
		remote=1
	else
		remote=0
	fi

	java -jar jCmplTest/dist/jCmplTest.jar $remote
	
	echo "Check test files"
	./test-jCmpl diet-local
	./test-jCmpl shortest-path-local
	./test-jCmpl cuttingStock
	./test-jCmpl prodmix
	
	
	if  [[ $OSTYPE != *msys* ]] ; then
		./test-jCmpl diet-remote
		./test-jCmpl shortest-path-remote-threads
		./cmplServerTest -stop 9999
	fi 
	
	echo "done"
	echo "######### jCmpl tests done ##############################"

else 
	echo "Cannot find jCmplTest/dist/JCmplTest.jar. Please build it before running the jCmpl tests"
fi