File: test_random.sh

package info (click to toggle)
andi 0.14-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 996 kB
  • sloc: ansic: 2,296; sh: 426; cpp: 99; makefile: 76; awk: 51
file content (71 lines) | stat: -rwxr-xr-x 2,316 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh -f

# This scripts test the accuracy of andi with random inputs. For that
# it uses the small program test_random to generate pairs of sequences
# with a given distance. By default, test_random creates a new set of
# sequences each time it is called. Thus, this test has a small, but
# non-zero probability of failing. That is a problem with Debian's
# reproducible builds effort. So this script acts as a wrapper around
# this issue.
#
# Simply calling this script via
#     % ./test/test_random.sh
# checks a new test-case every time. But with the right parameter
#     % RANDOM_SEED=1729 ./test/test_random.sh
# one specific set of sequences is validated.

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

LENGTH=100000

# If RANDOM_SEED is set, use its value. Otherwise 0 is used to signal
# to test_random that a new set of sequences shall be generated.
SEED=${RANDOM_SEED:-0}

for dist in 0.0 0.001 0.01 0.02 0.05 0.1 0.2 0.3
do
	for n in $(seq 10)
	do
		if test $SEED -ne 0; then
			SEED=$((SEED + 1))
		fi

		res=$(./test/test_fasta -s $SEED -l $LENGTH -d $dist |
			tee ./test/test_random.fasta |
			./src/andi -t 1 |
			tail -n 1 |
			awk -v dist=$dist '{print $2, dist}' |
			awk 'function abs(x){return ((x < 0.0) ? -x : x)} {print abs($1-$2) <= 0.055 && abs($1-$2) <= 0.055 * $2}')
		if test $res -ne 1; then
			echo "The last test computed a distance deviating more than five percent from its intended value."
			echo "See test_random.fasta for the used sequences."
			echo "./test/test_fasta -s $SEED -l $LENGTH -d $dist"
			head -n 1 ./test/test_random.fasta
			exit 1;
		fi
	done

	# raw
	for n in $(seq 10)
	do
		if test $SEED -ne 0; then
			SEED=$((SEED + 1))
		fi

		res=$(./test/test_fasta -r -s $SEED -l $LENGTH -d $dist |
			tee ./test/test_random.fasta |
			./src/andi -m RAW -t 1 |
			tail -n 1 |
			awk -v dist=$dist '{print $2, dist}' |
			awk 'function abs(x){return ((x < 0.0) ? -x : x)} {print abs($1-$2) <= 0.055 && abs($1-$2) <= 0.055 * $2}')
		if test $res -ne 1; then
			echo "The last test computed a distance deviating more than five percent from its intended value."
			echo "See test_random.fasta for the used sequences."
			echo "./test/test_fasta -r -s $SEED -l $LENGTH -d $dist"
			head -n 1 ./test/test_random.fasta
			exit 1;
		fi
	done
done

rm ./test/test_random.fasta