#!/bin/bash
set -e

pkg=dicelab

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cd "${AUTOPKGTEST_TMP}"

# The input example taken on the website
cat <<EOF >testInputWebsite
count >10
    sum
        keep high 2
            3#d6;
EOF

#Calling dicelab
dicelab -c -f testInputWebsite > testOutputWebsite

# Does the output match what we expect, according to the website?

grep -q '0[[:blank:]]0.8009' testOutputWebsite
if [ $? -ne 0 ]; then
  echo "Distribution is wrong at point 0"
  exit 1
fi

grep -q '1[[:blank:]]0.19907' testOutputWebsite
if [ $? -ne 0 ]; then
  echo "Distribution is wrong at point 1"
  exit 1
fi
