@echo off

set problem=garden
set author=pkun

cd src
echo Compiling sources...

g++ -O2 -Wl,--stack=67108864 GenTests.cpp -o GenTests.exe || goto GenCmpErr
g++ -O2 -Wl,--stack=67108864 ValidateTest.cpp -o validateTest.exe || goto ValCmpErr

echo Sources compiled successfully.

echo Generating tests...

GenTests.exe || goto GenErr

cd ..

echo Validating Tests...

for %%i in (tests\??) do (
	echo Test %%~ni
	CALL src\validateTest.exe <%%i || goto ValidationErr
)

echo Tests validated successfully.

echo Generating answers...

echo Compiling solution...

g++ -O2 -Wl,--stack=67108864 %problem%_%author%.cpp -o %problem%_%author%.exe || goto SolCmpErr

echo Compiling checker...

g++ -O2 -Wl,--stack=67108864 check.cpp -o check.exe || goto ChkCmpErr


for %%i in (tests\??) do (
	echo Test %%~ni
	copy %%i %problem%.in > nul
	CALL %problem%_%author%.exe
	copy %problem%.out %%i.a > nul
	CALL check %%i %%i.a %%i.a || goto CheckErr
)

echo Answers generated sucsessfully.
goto END

:GenCmpErr
echo Cannot compile generator
goto TERM
:ValCmpErr
echo Cannot compile validator
goto TERM
:SolCmpErr
echo Cannot compile solution
goto TERM
:ChkCmpErr
echo Cannot compile checker
goto TERM
:ValidationErr
echo Cannot validate tests
goto TERM
:GenErr
echo Cannot generate tests
goto TERM
:CheckErr
echo Jury's answer is incorrect
goto TERM
:TERM
echo Terminated!

:END


