#!/usr/bin/env sh

frobby=$FROBBY
testhelper=../testScripts/testhelper
test="$1"
shift

if [ "$1" = "_full" ];
then
  shift;

  # Check -canon agrees with transform and that intersection is minimal.
  $testhelper transform $test.intersection $test.intersection \
    -minimize -canon
  if [ $? != 0 ]; then exit 1; fi

  # Check that intersecting the same ideals more times, along with
  # other ideals that should contain the intersection, yields the same
  # result.
  cat $test.*test $test.intersection $test.radical \
     $test.minimize $test.*test > $FROBBY_TEST_TMPDIR/$test.test
  $testhelper intersection $FROBBY_TEST_TMPDIR/$test.test $test.intersection $* -canon
  if [ $? != 0 ]; then exit 1; fi

  # Try again after a canonicalization.
  $frobby transform < $FROBBY_TEST_TMPDIR/$test.test > $FROBBY_TEST_TMPDIR/$test.test2 2>/dev/null
  $testhelper intersection $FROBBY_TEST_TMPDIR/$test.test2 $test.intersection $* -canon
  if [ $? != 0 ]; then exit 1; fi

  rm $FROBBY_TEST_TMPDIR/$test.test $FROBBY_TEST_TMPDIR/$test.test2
fi

$testhelper intersection $test.*test $test.intersection $* -canon
