#!/bin/bash

if [ "$1" = "_few" ]; then
  testLevel="few";
  shift;
else
  testLevel="normal"
fi

TIMEFORMAT=$' (%2lR real)'

normalTests="euler alexdual hilbert_deform hilbert_bigatti hilbert_slice \
             dimension primdecom intersect assoprimes minimize \
             irrdecom radical frob maxstandard optimize"

specialTests="internal idealFormats polyFormats latticeFormats messages"
params="$*"

runNormalTests () {
  action="$1"; shift;
  path="$1"; shift;
  cd test/$path;
  ../testScripts/runtests $action $params
  if [ $? != 0 ]; then exit 1; fi
  cd ../..;
}

for t in $normalTests; do
  echo -n "$t "

  runNormalTests $t specialIdeals
  if [ "$testLevel" = "few" ]; then
    if [ "$t" != "frob" ]; then
      echo;
	  continue;
    fi
  fi

  runNormalTests $t commonIdeals

  runNormalTests $t frob

  if [ "$t" == "euler" ]; then
    runNormalTests $t bigIdeals
  fi

  if [ -e "$t" ]; then
    runNormalTests $t $t
  fi

  echo
done

for t in $specialTests;
do
  echo -n "$t "
  cd test/$t
  ./runtests $*
  if [ $? != 0 ]; then exit 1; fi
  echo
  cd ../..
done

echo "All normal tests passed."
