#!/bin/sh
#
# Testing RNAfold (equilibrium probabilities)

echo 1..3 # Number of tests to be executed.

RETURN=0

failed () {
    RETURN=1
    if [ "x$1" != "x" ]
    then
        echo "not ok - $1"
    else
        echo "not ok"
    fi
}

passed () {
    if [ "x$1" != "x" ]
    then
        echo "ok - $1"
    else
        echo "ok"
    fi
}


# Test partition function folding (centroid, MEA, base pair- and stack probabilities)
testname="Partition function (centroid, MEA)"
RNAfold --noPS -p --MEA < ${DATADIR}/rnafold.small.seq > rnafold_pf.fold
diff=$(${DIFF} -ru -I frequency ${RNAFOLD_RESULTSDIR}/rnafold.small.pf.gold rnafold_pf.fold)
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

testname="Partition function (base pair probabilities)"
RNAfold --noPS -p2 --auto-id --id-prefix="rnafold_pf_test" < ${DATADIR}/rnafold.small.seq > rnafold_pf.fold
for file in rnafold_pf_test_00*dp.ps
do
  diff=$(${DIFF} -ru -I CreationDate -I Creator -I Program ${RNAFOLD_RESULTSDIR}/${file} ${file})
  if [ "x${diff}" != "x" ] ; then break; fi
done
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

testname="Partition function (stack probabilities)"
for file in rnafold_pf_test_00*dp2.ps
do
  diff=$(${DIFF} -ru -I CreationDate -I Creator -I Program ${RNAFOLD_RESULTSDIR}/${file} ${file})
  if [ "x${diff}" != "x" ] ; then break; fi
done
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

# clean up
rm rnafold_pf.fold dot.ps
rm rnafold_pf_test_00*dp.ps rnafold_pf_test_00*dp2.ps

exit ${RETURN}
