Skip to content

Commit

Permalink
derandomize unit tests
Browse files Browse the repository at this point in the history
Make the unit tests reproducible by giving an external seed. Required
for Debian packaging.
  • Loading branch information
kloetzl committed Mar 5, 2018
1 parent ce65144 commit 394c3b4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 16 deletions.
15 changes: 12 additions & 3 deletions test/low_homo.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/bin/bash -f

./test/test_fasta -l 100000 > a.fa
./test/test_fasta -l 100000 > b.fa
./test/test_fasta -l 100 > both.fa
SEED=${RANDOM_SEED:-0}
SEED2=0
SEED3=0
if test $SEED -ne 0; then
SEED=$((SEED + 1))
SEED2=$((SEED + 2))
SEED3=$((SEED + 3))
fi

./test/test_fasta -s $SEED -l 100000 > a.fa
./test/test_fasta -s $SEED2 -l 100000 > b.fa
./test/test_fasta -s $SEED3 -l 100 > both.fa

cat both.fa a.fa | awk -vRS='>' '{if($1 == "S0")print ">"$0 > "S0.fa"}'
cat both.fa b.fa | awk -vRS='>' '{if($1 == "S1")print ">"$0 > "S1.fa"}'
Expand Down
12 changes: 10 additions & 2 deletions test/nan.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/bash -f

./test/test_fasta -l 10000 > a.fa
./test/test_fasta -l 10000 > b.fa
SEED=${RANDOM_SEED:-0}
SEED2=0
if test $SEED -ne 0; then
SEED=$((SEED + 1))
SEED2=$((SEED + 2))
fi


./test/test_fasta -s $SEED -l 10000 > a.fa
./test/test_fasta -s $SEED2 -l 10000 > b.fa

# this is expected to trigger the nan warning
./src/andi -j a.fa b.fa 2>&1 | grep 'nan'
Expand Down
15 changes: 12 additions & 3 deletions test/test_extra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
# Test if andi exists, and can be executed
./src/andi --version > /dev/null || exit 1

SEED=${RANDOM_SEED:-0}
SEED2=0
SEED3=0
if test $SEED -ne 0; then
SEED=$((SEED + 1))
SEED2=$((SEED + 2))
SEED3=$((SEED + 3))
fi

# Test andi for more than just two sequences at a time
./test/test_fasta -l 100000 -d 0.01 -d 0.01 -d 0.01 -d 0.01 | ./src/andi > /dev/null || exit 1
./test/test_fasta -s $SEED -l 100000 -d 0.01 -d 0.01 -d 0.01 -d 0.01 | ./src/andi > /dev/null || exit 1

# Test low-memory mode
./test/test_fasta -l 10000 > test_extra.fasta
./test/test_fasta -s $SEED2 -l 10000 > test_extra.fasta
./src/andi test_extra.fasta > extra.out
./src/andi test_extra.fasta --low-memory > extra_low_memory.out
diff extra.out extra_low_memory.out || exit 1

# Test file of filenames
./test/test_fasta -l 10000 > test_extra.fasta
./test/test_fasta -s $SEED3 -l 10000 > test_extra.fasta
echo "$PWD/test_extra.fasta" > fof.txt
./src/andi test_extra.fasta > extra.out
./src/andi --file-of-filenames fof.txt > fof.out
Expand Down
40 changes: 32 additions & 8 deletions test/test_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

./src/andi --help > /dev/null || exit 1

SEED=${RANDOM_SEED:-0}
SEED2=0
SEED3=0
if test $SEED -ne 0; then
SEED=$((SEED + 1))
SEED2=$((SEED + 2))
SEED3=$((SEED + 3))
fi

# Simple join test
./test/test_fasta -l 1000 -L 1000 -d 0.1 > p1.fasta
./test/test_fasta -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -l 10000 -L 10000 -d 0.1 > p3.fasta
./test/test_fasta -s $SEED -l 1000 -L 1000 -d 0.1 > p1.fasta
./test/test_fasta -s $SEED2 -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -s $SEED3 -l 10000 -L 10000 -d 0.1 > p3.fasta

head -qn 2 p1.fasta p2.fasta p3.fasta > S0.fasta
tail -qn 2 p1.fasta p2.fasta p3.fasta > S1.fasta
Expand All @@ -25,9 +34,16 @@ if test $RES -ne 1; then
exit 1;
fi

SEED=${RANDOM_SEED:-0}
SEED2=0
if test $SEED -ne 0; then
SEED=$((SEED + 5))
SEED2=$((SEED + 6))
fi

#unbalanced number of contigs
./test/test_fasta -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -l 10000 -L 10000 -d 0.1 > p3.fasta
./test/test_fasta -s $SEED -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -s $SEED2 -l 10000 -L 10000 -d 0.1 > p3.fasta

head -qn 2 p3.fasta > S0.fasta
tail -qn 2 p2.fasta p3.fasta > S1.fasta
Expand All @@ -47,11 +63,19 @@ if test $RES -ne 1; then
exit 1;
fi

SEED=${RANDOM_SEED:-0}
SEED2=0
SEED3=0
if test $SEED -ne 0; then
SEED=$((SEED + 11))
SEED2=$((SEED + 12))
SEED3=$((SEED + 13))
fi

#unbalanced number of contigs 2
./test/test_fasta -l 1000 -L 1000 -d 0.1 > p1.fasta
./test/test_fasta -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -l 10000 -L 10000 -d 0.1 > p3.fasta
./test/test_fasta -s $SEED -l 1000 -L 1000 -d 0.1 > p1.fasta
./test/test_fasta -s $SEED2 -l 1000 -L 1000 -d 0.1 > p2.fasta
./test/test_fasta -s $SEED3 -l 10000 -L 10000 -d 0.1 > p3.fasta

head -qn 2 p1.fasta p3.fasta > S0.fasta
tail -qn 2 p1.fasta p2.fasta p3.fasta > S1.fasta
Expand Down

0 comments on commit 394c3b4

Please sign in to comment.