#!/bin/bash
set -e

pkg=probabel

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

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"


gunzip -r *
ls -R
#do_stuff_to_test_package#

echo -e "\e[93m\e[1mTest 1\e[0m"

./example_bt.sh

echo "68c03a199e054d2571a962d5e023945c  logist_add.out.txt" >> checksums
echo "68c03a199e054d2571a962d5e023945c  logist_fv_add.out.txt" >> checksums
echo "ed3e18330990192e764646f9b47a76d3  logist_prob_2df.out.txt" >> checksums
echo "68c03a199e054d2571a962d5e023945c  logist_prob_add.out.txt" >> checksums
echo "18272da9ee07c7306a8658fb8683a644  logist_prob_domin.out.txt" >> checksums
echo "ed3e18330990192e764646f9b47a76d3  logist_prob_fv_2df.out.txt" >> checksums
echo "68c03a199e054d2571a962d5e023945c  logist_prob_fv_add.out.txt" >> checksums
echo "18272da9ee07c7306a8658fb8683a644  logist_prob_fv_domin.out.txt" >> checksums
echo "886faec17489000e013e0beeb0b2634d  logist_prob_fv_over_domin.out.txt" >> checksums
echo "85197b01f372230ec136a89df248ca7e  logist_prob_fv_recess.out.txt" >> checksums
echo "886faec17489000e013e0beeb0b2634d  logist_prob_over_domin.out.txt" >> checksums
echo "85197b01f372230ec136a89df248ca7e  logist_prob_recess.out.txt" >> checksums

md5sum --check checksums

echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"

./example_cox.sh

rm checksums
echo "e265eec53382ad7b049275649742f564  coxph_dose_add.out.txt" >> checksums
echo "e265eec53382ad7b049275649742f564  coxph_dose_fv_add.out.txt" >> checksums
echo "439b1f56bf76917d9f73ea04fbf12e10  coxph_prob_2df.out.txt" >> checksums
echo "e265eec53382ad7b049275649742f564  coxph_prob_add.out.txt" >> checksums
echo "2bfb396e615585e36647f3fd0e3a7475  coxph_prob_domin.out.txt" >> checksums
echo "439b1f56bf76917d9f73ea04fbf12e10  coxph_prob_fv_2df.out.txt" >> checksums
echo "e265eec53382ad7b049275649742f564  coxph_prob_fv_add.out.txt" >> checksums
echo "2bfb396e615585e36647f3fd0e3a7475  coxph_prob_fv_domin.out.txt" >> checksums
echo "757fa3187a3fdef308ac31b7d3416614  coxph_prob_fv_over_domin.out.txt" >> checksums
echo "7a81d14bcf571c3dc456abd90254deb9  coxph_prob_fv_recess.out.txt" >> checksums
echo "757fa3187a3fdef308ac31b7d3416614  coxph_prob_over_domin.out.txt" >> checksums
echo "7a81d14bcf571c3dc456abd90254deb9  coxph_prob_recess.out.txt" >> checksums

md5sum --check checksums

echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"

./example_mmscore.sh

rm checksums
echo "791929049d1c7950ecab01cc6450e71a  mmscore_dose_add.out.txt" >> checksums
echo "791929049d1c7950ecab01cc6450e71a  mmscore_dose_fv_add.out.txt" >> checksums
echo "b8a3e34a6398f64d1df4dd164cc0b39c  mmscore_prob_2df.out.txt" >> checksums
echo "791929049d1c7950ecab01cc6450e71a  mmscore_prob_add.out.txt" >> checksums
echo "ee050519b0612a83f9612f85d4cfaa52  mmscore_prob_domin.out.txt" >> checksums
echo "b8a3e34a6398f64d1df4dd164cc0b39c  mmscore_prob_fv_2df.out.txt" >> checksums
echo "791929049d1c7950ecab01cc6450e71a  mmscore_prob_fv_add.out.txt" >> checksums
echo "ee050519b0612a83f9612f85d4cfaa52  mmscore_prob_fv_domin.out.txt" >> checksums
echo "8dcba7570c9000230bdcad862a5fb0fd  mmscore_prob_fv_over_domin.out.txt" >> checksums
echo "dbb8fd46b55b7b391d73d059f7eccbac  mmscore_prob_fv_recess.out.txt" >> checksums
echo "8dcba7570c9000230bdcad862a5fb0fd  mmscore_prob_over_domin.out.txt" >> checksums
echo "dbb8fd46b55b7b391d73d059f7eccbac  mmscore_prob_recess.out.txt" >> checksums

md5sum --check checksums

echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"

./example_qt.sh

rm checksums
echo "28793bacdc6669f72aab25569f8ec009  height_allcov_fv_add.out.txt" >> checksums
echo "2fd1eb068363f83a5965f07f37570f87  height_base_add.out.txt" >> checksums
echo "2fd1eb068363f83a5965f07f37570f87  height_base_fv_add.out.txt" >> checksums
echo "899928574b0313b09dccba699cdd9d94  height_int1_fv_add.out.txt" >> checksums
echo "f22db745b47e9975b000c272f45c433a  height_ngp2_2df.out.txt" >> checksums
echo "2fd1eb068363f83a5965f07f37570f87  height_ngp2_add.out.txt" >> checksums
echo "53ebb5400919cbce3459b60b0490a1b9  height_ngp2_allcov_fv_2df.out.txt" >> checksums
echo "28793bacdc6669f72aab25569f8ec009  height_ngp2_allcov_fv_add.out.txt" >> checksums
echo "71246344e2f2b59dea547c301f45c180  height_ngp2_allcov_fv_domin.out.txt" >> checksums
echo "9fa7a891fd59b8cb9c99bec5ce4a881a  height_ngp2_allcov_fv_over_domin.out.txt" >> checksums
echo "b09bf47ef40977a91d6298624f8d9cc1  height_ngp2_allcov_fv_recess.out.txt" >> checksums
echo "6b2bd9c9068bbd93ae028fc967899464  height_ngp2_domin.out.txt" >> checksums
echo "f22db745b47e9975b000c272f45c433a  height_ngp2_fv_2df.out.txt" >> checksums
echo "2fd1eb068363f83a5965f07f37570f87  height_ngp2_fv_add.out.txt" >> checksums
echo "6b2bd9c9068bbd93ae028fc967899464  height_ngp2_fv_domin.out.txt" >> checksums
echo "1c4c9e0a1573be84392e75ec80f48048  height_ngp2_fv_over_domin.out.txt" >> checksums
echo "9c01531e3c01013308f2a9ab693227ed  height_ngp2_fv_recess.out.txt" >> checksums
echo "516b6052d30df298ae5d4507e50cfaae  height_ngp2_int1_fv_2df.out.txt" >> checksums
echo "899928574b0313b09dccba699cdd9d94  height_ngp2_int1_fv_add.out.txt" >> checksums
echo "83bfad80d7077ade08497453e444c7e4  height_ngp2_int1_fv_domin.out.txt" >> checksums
echo "7d5b0288ced3b044930d0d59573fd8d8  height_ngp2_int1_fv_over_domin.out.txt" >> checksums
echo "e69263eba3939d87572a76c4ec5749bb  height_ngp2_int1_fv_recess.out.txt" >> checksums
echo "1c4c9e0a1573be84392e75ec80f48048  height_ngp2_over_domin.out.txt" >> checksums
echo "9c01531e3c01013308f2a9ab693227ed  height_ngp2_recess.out.txt" >> checksums
echo "b88b24ec1f197cad0d7ee1642375f0f8  height_ngp2_robust_fv_2df.out.txt" >> checksums
echo "770ae8c5d4c5950af5cca28ea8c3be03  height_ngp2_robust_fv_add.out.txt" >> checksums
echo "0946a8b6f3193c1e5a6994e6771fc4a9  height_ngp2_robust_fv_domin.out.txt" >> checksums
echo "f4111f088959d5ae7421d990581f7506  height_ngp2_robust_fv_over_domin.out.txt" >> checksums
echo "cc30f61baf5c8eacfa2c876d1ee23a81  height_ngp2_robust_fv_recess.out.txt" >> checksums
echo "a13b9398bb6f9f4d362310508b65efe7  height_ngp2_robust_int1_fv_2df.out.txt" >> checksums
echo "bda239a9ab25d53b415575d70c0219be  height_ngp2_robust_int1_fv_add.out.txt" >> checksums
echo "c1396b25602cfabf657e66314df150b4  height_ngp2_robust_int1_fv_domin.out.txt" >> checksums
echo "780951e73361135649fa8e9a0b362c0a  height_ngp2_robust_int1_fv_over_domin.out.txt" >> checksums
echo "d605c4b52658eadd5efbfed35f17e6f4  height_ngp2_robust_int1_fv_recess.out.txt" >> checksums
echo "770ae8c5d4c5950af5cca28ea8c3be03  height_robust_fv_add.out.txt" >> checksums
echo "bda239a9ab25d53b415575d70c0219be  height_robust_int1_fv_add.out.txt" >> checksums

md5sum --check checksums

echo -e "\e[92m\e[1mPassed\e[0m"
echo