#!/bin/bash
set -e

pkg=nthash

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 /usr/share/doc/libnthash-dev/examples/* "${AUTOPKGTEST_TMP}"
cp -a /usr/share/doc/velvet/tests/reads.fa.gz "${AUTOPKGTEST_TMP}"
cd "${AUTOPKGTEST_TMP}"
gunzip -r *

echo "Test library -- Functionality"
g++ -o sampletest example-ntiterator.cpp
./sampletest > test1
cat test1
[ -s test1 ] || exit 1
[ "$(cat test1 | wc -l)" -eq 6 ] || exit 1
echo "PASS"

echo "Test binary -- Functionality"
nttest -k50 reads.fa 2>test2
[ -s test2 ] || exit 1
cat test2
fgrep -q "kmer=50" test2
fgrep -q "ntbase" test2
rm -f test*
echo "PASS"
