#!/bin/bash
set -e

pkg=rdp-readseq

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 *

echo -e "\e[93m\e[1mTest 1\e[0m"
rdp-readseq random-sample -n 2 -s 25 random.fa random-sample
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
rdp-readseq reverse-comp -i random.fa -o reverse-comp
echo "de07af6b256364aee08e500d595bf4f0  reverse-comp" >> checksums
md5sum --check checksums

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

echo -e "\e[93m\e[1mTest 3\e[0m"
rdp-readseq rm-dupseq -d -i random.fa -o rm-dupseq
echo "d978407aaee481974d60be19ba88be81  rm-dupseq" >> checksums
md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"
rdp-readseq split random.fa split 3
echo "5e7e68143bd6c75810222dad4f7fafdf  split/0_random.fa" >> checksums
echo "a38c212d74660b3b8b7978b34a65969a  split/1_random.fa" >> checksums
md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5\e[0m"
rdp-readseq to-fasta random.fq > to-fasta
echo "c1a68f563e86516970219a34ace03f18  to-fasta" >> checksums
md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 6\e[0m"
rdp-readseq to-fastq random.fq > to-fastq
echo "1a8570b3f4122f5131b0983c2d98653f  to-fastq" >> checksums
md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 7\e[0m"
rdp-readseq select-seqs ids select-seqs fasta keep random.fa
echo "b13a011f049ecbb73988bc9ba53e587d  select-seqs" >> checksums
md5sum --check checksums
echo -e "\e[92m\e[1mPassed\e[0m"
echo
