#!/bin/bash

set -e

nt=0
function nextTest {
  nt=$(($nt+1))
  fn=`printf '%02d' $nt`
  echo "$fn: $*"
  $* > ../tests/$fn 2>> tests.lst
}

rm -rf ../tests
mkdir ../tests

echo "[ Generate tests ]"

for i in 0{0..9}; do
	if [ -e $i.hand ]; then
		cp $i.hand ../tests/
		nt=$(($nt+1))
	fi
done
javac -encoding utf8 doall_army.java
pushd ../tests

java -cp ../src doall_army

#echo "[ Validate tests ]"
#g++ -O2 -Wall -o validate ../src/validate.cpp
#for f in {0..9}{0..9} ; do
#  if [ -e $f ] ; then
#    echo "Test $f"
#    ./validate < $f
#  fi
#done

echo "[ Generate answers ]"
pushd ../solutions
javac army_sm.java
popd

for f in {0..9}{0..9} ; do
  if [ -e $f ] ; then
    echo "Test $f"
    cp $f army.in
    java -cp ../solutions army_sm
    cp army.out $f.a
  fi
done

popd
