#!/bin/bash

echo "Usage: 'gen_ans_cpp.sh' or 'gen_ans_cpp.sh docheck'"
echo "Generate answers"

source ./include.sh

prob=blacktree
sol=../solutions/blacktree_nk_nlog2n
ext=cpp

echo "problem = $prob"
echo "solution = $sol.$ext"

compile_cpp $sol.$ext $sol

if [[ $1 == "docheck" ]] ; then
  compile_cpp check.cpp check
fi

for i in `ls -v ???` ; do
  echo "Test $i"
  echo "gen line: `cat $i.l`"
  time ./$sol <$i >$i.a || exit;
  if [[ $1 == "docheck" ]] ; then
    ./check $i $i.a $i.a || exit 1
  fi
  echo -ne "\n=========================\n"
done

rm -f $prob.{in,out}
rm -f sol

testdir=../tests/
echo "-- Move tests to $testdir"
rm -f -r $testdir
mkdir $testdir || exit
mv ??? $testdir/ || exit
mv ???.l $testdir/ || exit
mv ???.g $testdir/ || exit
mv ???.a $testdir/ || exit
