#!/bin/bash
set -e

pkg=ntcard
CUR_DIR=`pwd`

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a ${CUR_DIR}/debian/tests/*.gz "${AUTOPKGTEST_TMP}"
cp -a ${CUR_DIR}/data/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

zcat test-reads.fq.gz |sed -n '1~4s/^@/>/p;2~4p' > test-reads.fa

echo "Test 1"
ntcard -k 12 -p test-read test-reads.fq.gz
[ -s test-read_k12.hist ] || exit 1

# Due to rounding errors, there might be difference on other arches, for now check only on amd64
if [ "$dpkg-architecture -qDEB_HOST_ARCH" = "amd64" ]
then
	diff -q test_k12.hist test_k12.hist.good
fi

rm -f test-read_k12.hist
echo "PASS"

echo "Test 2"
ntcard -k 12 -p test-fa test-reads.fa
[ -s test-fa_k12.hist ] || exit 1
rm -f test-fa_k12.hist
echo "PASS"

echo "Test 3"
ntcard -k 12 -p test-gap -g 2 test-reads.fq.gz
[ -s test-gap_k12.hist ] || exit 1

# Due to rounding errors, there might be difference on other arches, for now check only on amd64
if [ "$dpkg-architecture -qDEB_HOST_ARCH" = "amd64" ]
then
	diff -q test-gap_k12.hist test-gap_k12.hist.good
fi

rm -f test-gap_k12.hist
echo "PASS"

echo "Test 4"
ntcard -k 12 -p test-fa-gap -g 2 test-reads.fa
[ -s test-fa-gap_k12.hist ] || exit 1
rm -f test-fa-gap_k12.hist
echo "PASS"
