#!/bin/sh

echo 1..6 # 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)"
RNAcofold --noPS -p --centroid --MEA < ${DATADIR}/rnacofold.small.seq > rnacofold_pf.fold
diff=$(${DIFF} -ru -I frequency ${RNACOFOLD_RESULTSDIR}/rnacofold.small.pf.gold rnacofold_pf.fold)
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

testname="Partition function (centroid, dimers, monomers)"
RNAcofold --noPS -a < ${DATADIR}/rnacofold.small.seq > rnacofold_pf.fold
diff=$(${DIFF} -ru -I frequency ${RNACOFOLD_RESULTSDIR}/rnacofold.small.pf.full.gold rnacofold_pf.fold)
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

testname="Partition function (base pair probabilities - Hetero-dimer)"
RNAcofold --noPS -a --auto-id --id-prefix="rnacofold_pf_test" < ${DATADIR}/rnacofold.small.seq > rnacofold_pf.fold
for file in ABrnacofold_pf_test_00*dp5.ps
do
  diff=$(${DIFF} -ru -I CreationDate -I Creator -I Program ${RNACOFOLD_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 (base pair probabilities - Homo-dimers)"
for file in AArnacofold_pf_test_00*dp5.ps BBrnacofold_pf_test_00*dp5.ps
do
  diff=$(${DIFF} -ru -I CreationDate -I Creator -I Program ${RNACOFOLD_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 (base pair probabilities - Monomers)"
for file in Arnacofold_pf_test_00*dp5.ps Brnacofold_pf_test_00*dp5.ps
do
  diff=$(${DIFF} -ru -I CreationDate -I Creator -I Program ${RNACOFOLD_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

# Test concentrations
testname="Partition function (concentrations)"
RNAcofold --noPS -f ${DATADIR}/rnacofold.concentrations < ${DATADIR}/rnacofold.small.seq > rnacofold_concentrations.fold
diff=$(${DIFF} -ru -I frequency ${RNACOFOLD_RESULTSDIR}/rnacofold.small.concentrations.gold rnacofold_concentrations.fold)
if [ "x${diff}" != "x" ] ; then failed "$testname"; echo -e "$diff"; else passed "$testname"; fi

# clean up
rm rnacofold_pf.fold ABdot5.ps AAdot5.ps BBdot5.ps Adot5.ps Bdot5.ps rnacofold_concentrations.fold
rm ABrnacofold_pf_test_00*dp5.ps AArnacofold_pf_test_00*dp5.ps BBrnacofold_pf_test_00*dp5.ps Arnacofold_pf_test_00*dp5.ps Brnacofold_pf_test_00*dp5.ps dot.ps

exit ${RETURN}
