#!/bin/bash

function make
{
  echo "Compile $1"
  g++ -O2 -Wall $1.cpp -o $1
}

function nextTest
{
  ti=`printf "%02d" "$nt"`
  echo "$1 > $ti"
  $1 > ../tests/$ti || exit 1
  let nt=$nt+1
  let base=$base+1
}

testdir="../tests"
programs="split gen_rand gen_chess gen_teeth gen_paint gen_quad gen_corners gen_circles gen_ladder gen_ladder_noise gen_carpet"
nt=1
prob=farmer
base=23917

echo "Clear enviroment"
rm -rf $testdir

mkdir $testdir 2>/dev/null

echo "Compiling programs"
for prog in $programs ; do
  make $prog
done

echo "Generate tests"

echo "Split small tests"
rm *.tmp
./split < tests.!!!
for i in `ls *.tmp` ; do
  nextTest "cat $i"
done
rm *.tmp

echo "Extract tests made from bmps"
7z e -o$testdir tests.zip

## tests 6-15 (20 <= N <= 40)
nextTest "./gen_rand $base 20 20 500"
nextTest "./gen_rand $base 20 30 600"
nextTest "./gen_rand $base 20 40 700"
nextTest "./gen_rand $base 30 20 800"
nextTest "./gen_rand $base 40 20 600"
nextTest "./gen_rand $base 40 40 500"
nextTest "./gen_rand $base 40 40 750"
nextTest "./gen_rand $base 40 40 999"
nextTest "./gen_chess 40 40 0 2 4"
nextTest "./gen_paint $base 40 40 10"

## tests 16-30 (60 <= n <= 300)
nextTest "./gen_rand $base 60 60 100"
nextTest "./gen_rand $base 70 70 200"
nextTest "./gen_rand $base 80 80 300"
nextTest "./gen_rand $base 90 90 400"
nextTest "./gen_rand $base 90 90 500"

nextTest "./gen_rand $base 100 100 100"
nextTest "./gen_rand $base 200 100 200"
nextTest "./gen_rand $base 300 300 500"
nextTest "./gen_rand $base 300 300 750"
nextTest "./gen_rand $base 300 300 999"

nextTest "./gen_quad $base 300 300 50"
nextTest "./gen_corners 250 250"
nextTest "./gen_circles $base 300 300"
nextTest "./gen_ladder $base 300 300 10 15"
nextTest "./gen_ladder_noise $base 300 300 10 15 30"

## tests 31-40 (500 <= N <= 2000) (big random tests)
nextTest "./gen_rand $base 500 500 300"
nextTest "./gen_rand $base 700 800 500"
nextTest "./gen_rand $base 900 800 600"
nextTest "./gen_rand $base 1100 500 400"
nextTest "./gen_rand $base 500 1500 750"

nextTest "./gen_rand $base 900 1000 500"
nextTest "./gen_rand $base 1500 1400 500"
nextTest "./gen_rand $base 2000 2000 300"
nextTest "./gen_rand $base 2000 2000 600"
nextTest "./gen_rand $base 2000 2000 900"

## tests 41-48 (500 <= N <= 2000) (big pattern tests)
nextTest "./gen_teeth 1000 1000 120 100 20"
nextTest "./gen_quad $base 2000 2000 75"
nextTest "./gen_carpet 2000 2000"
nextTest "./gen_ladder $base 2000 2000 50 60"
nextTest "./gen_ladder_noise $base 1900 1800 70 80 40"

nextTest "./gen_paint $base 1700 1800 100"
nextTest "./gen_paint $base 1700 1800 300"
nextTest "./gen_circles $base 1700 1600"

## tests 49-50 are generated by .zip file

echo "Cleaning up"
for prog in $programs ; do
  rm $prog $prog.exe 2>/dev/null
done

rm -f $prob.{in,out}
