#!/bin/bash

#test/runtests $*
#if [ $? != 0 ]; then exit 1; fi

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

TIMEFORMAT=$' (%2lR real)'

pivotSplits="minimum median maximum gcd indep"
pivotActions="hilbert_slice"

labelSplits="maxlabel varlabel minlabel $pivotSplits"
labelActions="optimize irrdecom assoprimes alexdual"

frobSplits="frob $labelSplits"
frobActions="frob"

bigattiSplits="median mostNGPure mostNGGcd mostNGTight typicalPure \
  typicalGcd typicalTight typicalNGPure typicalNGGcd typicalNGTight \
  someNGPure someNGGcd someNGTight"
bigattiActions="hilbert_bigatti"

params="$*"
testhelper=../testScripts/testhelper
paths="specialIdeals commonIdeals frob"

runTests () {
  action="$1"; shift;
  splits="$*";

  echo "*** $action";

  for split in $splits; do
    echo -n " $split ";
    for path in $paths; do
      cd test/$path;
      ../testScripts/runtests $action $params -split $split;
      if [ $? != 0 ]; then exit 1; fi
      cd ../..;

      if [ "$testLevel" = "few" ]; then
        if [ "$action" != "frob" ]; then
		  break;
        fi
      fi
    done
    echo;
  done
}

for action in $bigattiActions;
do
  runTests "$action" $bigattiSplits
done

for action in $labelActions;
do
  runTests "$action" $labelSplits
done

for action in $pivotActions;
do
  runTests "$action" $pivotSplits
done

for action in $frobActions;
do
  runTests "$action" $frobSplits
done
