#!/bin/sh
# autopkgtest check: Run sumaclust on three different chains with a threshold 
# of 0.97 to check that only two clusters are created.
# (C) 2020 Pierre Gruet.
# Author: Pierre Gruet <pgtdebian@free.fr>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > inputThreeDifferent.fasta
>SEQ_TEST1
CCAGATCTAGCTAGCTAGCTACAGCATCGACATCAGCACTCAGCACTCAG
>SEQ_TEST2
TCAGATCTAGCTAGCTAGCTACAGCATCGACATCAGCACTCAGCACTCAG
>SEQ_TEST3
TTTCAGATCTAGCAAGCGAGCTGACTTACAGCATCGACATCAGCACTCAGCACTCAGTGAT
EOF

sumaclust -t 0.97 inputThreeDifferent.fasta 2>&1 | \
  sed -n '/clusters/ s/.*Done : 100 \% *//p' | \
  sed -n 's/ clusters.*//p' | \
  grep -q "2"

if [ $? -ne 0 ]; then
  exit 1
fi

