@echo off

set problem=park
set author=od_j
rem you can set lang as dpr, java, cpp or python
set lang=java



echo Generating tests...
mkdir tests
pushd src
python generate.py
if errorlevel 1 exit
popd

echo Compiling checker...

g++ -O2 -Ie:\testlib check.cpp -o check.exe

echo Compiling validator...

g++ -O2 -Ie:\testlib validate.cpp -o validate.exe

:novalidate

echo Generating answers...

if [%lang%]==[java] javac %problem%_%author%.java -encoding utf8
if [%lang%]==[cpp] g++ -O2 %problem%_%author%.cpp -o %problem%_%author%.exe
if [%lang%]==[dpr] dcc32 -cc %problem%_%author%.dpr

for %%i in (tests\??) do (
    echo Test %%i
    copy %%i %problem%.in > nul
    if exist validate.jar (
    java -jar validate.jar < %problem%.in
    if errorlevel 1 (
        echo Validator rejects test %%i
        goto end
    )
     echo Validator accepts test %%i
    )
    if exist validate.exe (
    validate.exe < %problem%.in
    if errorlevel 1 (
        echo Validator rejects test %%i
        goto end
    )
     echo Validator accepts test %%i
    )

    if [%lang%]==[java] java -Xmx256M -Xss64M %problem%_%author%
    if [%lang%]==[cpp] %problem%_%author% 
    if [%lang%]==[dpr] %problem%_%author%
    if [%lang%]==[python] python %problem%_%author%.py

    copy %problem%.out %%i.a > nul
    echo Check %%i
    if exist check.jar (
    java -jar check.jar %%i %%i.a %%i.a | tee -a check.log
    )
    if exist check.exe (
    check %%i %%i.a %%i.a
    )
    if errorlevel 1 pause 0
)

:end