@echo off
for %%i in (.) do (
    set problem_name=%%~ni
)

if not exist %problem_name%_%1.java goto usage
if not exist %problem_name%_%2.java goto usage
if exist %3 goto usage


md %3
pushd %3

call javac -classpath ../../../lib/testlib4j.jar ../Check.java -encoding utf8 -d .
call jar cf Check.jar *.class

javac ../%problem_name%_%1.java -d .
javac ../%problem_name%_%2.java -d .

rem Compile generator
javac ../src/gen_%problem_name%.java -d .

:loop

rem Launch generator
java gen_%problem_name% stress > %problem_name%.in

call java %problem_name%_%1
move %problem_name%.out %problem_name%.1
call java %problem_name%_%2
move %problem_name%.out %problem_name%.2

java -Xmx256M -Xss64M -cp ..\..\..\lib\testlib4j.jar;Check.jar ru.ifmo.testlib.CheckerFramework Check %problem_name%.in %problem_name%.1 %problem_name%.2

rem call check.exe %problem_name%.in %problem_name%.1 %problem_name%.2

if ERRORLEVEL 1 (
	set tm=%time::=.%
	set ttm=%tm:,=.%
	copy %problem_name%.in %ttm%.in 
	copy %problem_name%.1 %ttm%.1 
	copy %problem_name%.2 %ttm%.2 
	goto exit
)

goto loop

:exit
exit

:usage
echo Use: %0 suffix1 suffix2 stress_instance
echo Ex: %0 aa ab stress1
echo stress_instance should not exist. It will be used as working directory for stress testing.
echo Multiple stress test instances could be executed in parallel. After files have been copied to the test directory, process does not interfer with anything outside it's directory.
exit
