#! /bin/sh

variant="$1"
prefix="$2"
iterations="$3"
slots="$4"
wrapper="$5"

if [ "$wrapper" = "valgrind" ]; then
    cmd="valgrind -q --leak-check=yes "
else
    cmd=""
fi

cmd="${cmd}./types"
cmd="$cmd --brief"

if [ "$iterations" = "nonrandom" ]; then
    cmd="$cmd --nonrandom"
    f="nonrandom"
else
    cmd="$cmd --builtin-rng"
    f="builtin"
fi

if [ "$variant" = "hapax" ]; then
    cmd="$cmd --hapax"
    f="hapax-$f"
fi

if [ "$slots" = "raw" ]; then
    cmd="$cmd --raw-data"
    f="$f-raw"
fi

if [ "$iterations" = "nonrandom" ]; then
    cmd="$cmd 1"
else
    cmd="$cmd $iterations"
fi

if [ "$slots" != "raw" ]; then
    cmd="$cmd $slots"
    f="$f-$slots"
fi

p="check/$prefix"

echo "$cmd < $p-input"
$cmd < "$p-input" > "$p-output-$f" || exit 1
# cp "$p-output-$f" "$p-expected-$f"
cmp "$p-output-$f" "$p-expected-$f" || exit 1
