@echo off

set problem=fence
set author=ge
rem you can set lang as dpr, java, cpp or python
set lang=cpp

echo Generating tests...
mkdir tests
pushd src
python gen_tests.py
if errorlevel 239 exit
popd

echo Compiling checker...
echo Standart checker hcmp.cpp from testlib

g++ -O2 -I../../lib Check.cpp -o Check.exe

if not exist Validate.cpp goto novalidate

echo Compiling validator...

g++ -O2 -I../../lib Validate.cpp -o Validate.exe

:novalidate

echo Generating answers...

g++ -O2 %problem%_%author%.cpp -o %problem%_%author%.exe

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

    %problem%_%author% 
    
    copy %problem%.out %%i.a > nul
    echo Check %%i
    check.exe %%i %%i.a %%i.a
    if errorlevel 1 pause 0
)

:end