#!/bin/bash
set -e

pkg="peptidebuilder"
CUR_DIR=`pwd`

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}/examples/* $AUTOPKGTEST_TMP
cd $AUTOPKGTEST_TMP
mv -f reconstructed_RMSDs.txt test.txt

echo "Test 1"
cd $AUTOPKGTEST_TMP
python3 simpleExample.py
[ -s example.pdb ] || exit 1 
cat example.pdb
echo "PASS"

echo "Test 2"
python3 evaluation.py 2>/dev/null
for f in PDBs/Aligned*.pdb PDBs/AllAngles*.pdb PDBs/Backbone*.pdb PDBs/PhiPsi*.pdb
do
	echo $f
	[ -s $f ] || exit 1
	rm -f $f
done

# The diff might not work as ecpected on architectures other than amd64
if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "amd64" ]
then
	echo "diff expected and generated"
	diff -u reconstructed_RMSDs.txt test.txt
fi
[ -s reconstructed_RMSDs.txt ] || exit 1
echo "PASS"
