Skip to content

Commit 55800c4

Browse files
author
giraffedata
committed
Add tests for 'pbmnoise'
git-svn-id: https://svn.code.sf.net/p/netpbm/code/trunk@4207 9d0c8265-081b-0410-96cb-a4ca84ce46f8
1 parent c109a66 commit 55800c4

7 files changed

+362
-0
lines changed

test/Test-Order

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ppmforge-parameters.test
2727

2828
# Generators with random components
2929

30+
pbmnoise1.test
31+
pbmnoise2.test
32+
pbmnoise-parameters.test
3033
pgmnoise.test
3134
pgmnoise-parameters.test
3235
ppmpat-random.test

test/pbmnoise-parameters.ok

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Test Invalid
2+
Expected failure 1 1
3+
Expected failure 2 1
4+
Expected failure 3 1
5+
Expected failure 4 1
6+
Expected failure 5 1
7+
Expected failure 6 1
8+
Expected failure 7 1
9+
Expected failure 8 1
10+
Expected failure 9 1
11+
Expected failure 10 1
12+
Expected failure 11 1
13+
Expected failure 12 1
14+
Expected failure 13 1
15+
Expected failure 14 1
16+
Expected failure 15 1
17+
Expected failure 16 1
18+
Expected failure 17 1
19+
Expected failure 17 1
20+
Expected failure 18 1
21+
Expected failure 19 1
22+
Expected failure 20 1
23+
Expected failure 21 1
24+
Expected failure 22 1
25+
Expected failure 23 1
26+
Expected failure 24 1

test/pbmnoise-parameters.test

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#! /bin/bash
2+
# This script tests: pbmnoise
3+
# Also requires:
4+
5+
echo "Invalid command-line argument combinations." 1>&2
6+
echo "Error messages should appear below the line." 1>&2
7+
echo "-----------------------------------------------------------" 1>&2
8+
9+
echo "Test Invalid"
10+
11+
test_out=${tmpdir}/test_out
12+
13+
# Invalid -ratio arguments
14+
15+
pbmnoise -ratio 100 100 > ${test_out} || \
16+
echo -n "Expected failure 1"
17+
test -s ${test_out}; echo " "$?
18+
rm -f ${test_out}
19+
20+
pbmnoise -ratio 0 1 100 > ${test_out} || \
21+
echo -n "Expected failure 2"
22+
test -s ${test_out}; echo " "$?
23+
rm -f ${test_out}
24+
25+
pbmnoise -ratio=1.1 100 100 > ${test_out} || \
26+
echo -n "Expected failure 3"
27+
test -s ${test_out}; echo " "$?
28+
rm -f ${test_out}
29+
30+
pbmnoise -ratio=-1 100 100 > ${test_out} || \
31+
echo -n "Expected failure 4"
32+
test -s ${test_out}; echo " "$?
33+
rm -f ${test_out}
34+
35+
pbmnoise -ratio=half 100 100 > ${test_out} || \
36+
echo -n "Expected failure 5"
37+
test -s ${test_out}; echo " "$?
38+
rm -f ${test_out}
39+
40+
pbmnoise -ratio=0/1/1 100 100 > ${test_out} || \
41+
echo -n "Expected failure 6"
42+
test -s ${test_out}; echo " "$?
43+
rm -f ${test_out}
44+
45+
pbmnoise -ratio=-1/2 100 100 > ${test_out} || \
46+
echo -n "Expected failure 7"
47+
test -s ${test_out}; echo " "$?
48+
rm -f ${test_out}
49+
50+
pbmnoise -ratio=1/0 100 100 > ${test_out} || \
51+
echo -n "Expected failure 8"
52+
test -s ${test_out}; echo " "$?
53+
rm -f ${test_out}
54+
55+
pbmnoise -ratio=/2 100 100 > ${test_out} || \
56+
echo -n "Expected failure 9"
57+
test -s ${test_out}; echo " "$?
58+
rm -f ${test_out}
59+
60+
pbmnoise -ratio=4/2 100 100 > ${test_out} || \
61+
echo -n "Expected failure 10"
62+
test -s ${test_out}; echo " "$?
63+
rm -f ${test_out}
64+
65+
pbmnoise -ratio=6/ 100 100 > ${test_out} || \
66+
echo -n "Expected failure 11"
67+
test -s ${test_out}; echo " "$?
68+
rm -f ${test_out}
69+
70+
pbmnoise -ratio=1.0/2.0 100 100 > ${test_out} || \
71+
echo -n "Expected failure 12"
72+
test -s ${test_out}; echo " "$?
73+
rm -f ${test_out}
74+
75+
# denominator must be power of 2
76+
pbmnoise -ratio=3/9 100 100 > ${test_out} || \
77+
echo -n "Expected failure 13"
78+
test -s ${test_out}; echo " "$?
79+
rm -f ${test_out}
80+
81+
pbmnoise -ratio=a/2 100 100 > ${test_out} || \
82+
echo -n "Expected failure 14"
83+
test -s ${test_out}; echo " "$?
84+
rm -f ${test_out}
85+
86+
87+
pbmnoise -ratio=2/a 100 100 > ${test_out} || \
88+
echo -n "Expected failure 15"
89+
test -s ${test_out}; echo " "$?
90+
rm -f ${test_out}
91+
92+
pbmnoise -ratio=1/-2 100 100 > ${test_out} || \
93+
echo -n "Expected failure 16"
94+
test -s ${test_out}; echo " "$?
95+
rm -f ${test_out}
96+
97+
# Denominator must be 65536 or less
98+
pbmnoise -ratio=1/65537 100 100 > ${test_out} || \
99+
echo -n "Expected failure 17"
100+
test -s ${test_out}; echo " "$?
101+
rm -f ${test_out}
102+
103+
pbmnoise -ratio=1/131072 100 100 > ${test_out} || \
104+
echo -n "Expected failure 17"
105+
test -s ${test_out}; echo " "$?
106+
rm -f ${test_out}
107+
108+
pbmnoise -endian=large 100 100 > ${test_out} || \
109+
echo -n "Expected failure 18"
110+
test -s ${test_out}; echo " "$?
111+
rm -f ${test_out}
112+
113+
pbmnoise -randomseed 100 100 > ${test_out} || \
114+
echo -n "Expected failure 19"
115+
test -s ${test_out}; echo " "$?
116+
rm -f ${test_out}
117+
118+
pbmnoise -randomseed=-1 100 100 > ${test_out} || \
119+
echo -n "Expected failure 20"
120+
test -s ${test_out}; echo " "$?
121+
rm -f ${test_out}
122+
123+
pbmnoise -randomseed=0.1 100 100 > ${test_out} || \
124+
echo -n "Expected failure 21"
125+
test -s ${test_out}; echo " "$?
126+
rm -f ${test_out}
127+
128+
pbmnoise > ${test_out} || \
129+
echo -n "Expected failure 22"
130+
test -s ${test_out}; echo " "$?
131+
rm -f ${test_out}
132+
133+
pbmnoise 100 > ${test_out} || \
134+
echo -n "Expected failure 23"
135+
test -s ${test_out}; echo " "$?
136+
rm -f ${test_out}
137+
138+
pbmnoise 100 200 300 > ${test_out} || \
139+
echo -n "Expected failure 24"
140+
test -s ${test_out}; echo " "$?
141+
rm -f ${test_out}
142+
143+

test/pbmnoise1.ok

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Test 1. Should print 242292858 962 five times
2+
242292858 962
3+
242292858 962
4+
242292858 962
5+
242292858 962
6+
242292858 962
7+
Test 2.
8+
P1 32 1 00000000000000000000000000000000
9+
P1 32 1 00010000000001000000000000000000
10+
P1 32 1 00010000000001000010000000000000
11+
P1 32 1 00010000000001000000000000000000
12+
P1 32 1 00010000000001000010010000000000
13+
P1 32 1 01010001000101000000000000000000
14+
P1 32 1 00010000000001000010100000000000
15+
P1 32 1 01010001000111000000000000100010
16+
P1 32 1 10011001000001100010010000000000
17+
P1 32 1 01010001000111000000010100100010
18+
P1 32 1 01011001000101000010100000000000
19+
P1 32 1 01010001000111000001010100100110
20+
P1 32 1 00010000000001000111110000000100
21+
P1 32 1 01010001010111001001010100100110
22+
P1 32 1 01011011000111000010101000101010
23+
P1 32 1 01010001011111011001010100110110
24+
P1 32 1 10011001001001110010011000101110
25+
P1 32 1 01010001011111011011010101110110
26+
P1 32 1 01011011000111000010111110101010
27+
P1 32 1 01010001011111011011110101110110
28+
P1 32 1 11011001010101101111110000000100
29+
P1 32 1 01011001011111011011110101110110
30+
P1 32 1 01011011000111000111111110101110
31+
P1 32 1 01011011011111011011111101111110
32+
P1 32 1 10111111101011110111111000111111
33+
P1 32 1 01011011011111011011111111111110
34+
P1 32 1 11011011010111101111111110101110
35+
P1 32 1 01011011011111011111111111111110
36+
P1 32 1 11111111111111111111111000111111
37+
P1 32 1 11011011011111111111111111111110
38+
P1 32 1 11111111111111111111111110111111
39+
P1 32 1 11111111111111111111111111111111
40+
P1 32 1 11111111111111111111111111111111
41+
Test 3. Should print 126142586 1218 four times
42+
126142586 1218
43+
126142586 1218
44+
126142586 1218
45+
126142586 1218
46+
Test 4.
47+
P1 64 1 1000010001101101101000100101001110101011010010011111001011100110
48+
P1 64 1 1000010001101101101000100101001110101011010010011111001011100110
49+
P1 64 1 0101001110100010011011011000010011100110111100100100100110101011
50+
P1 64 1 0101001110100010011011011000010011100110111100100100100110101011

test/pbmnoise1.test

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#! /bin/bash
2+
# This script tests: pbmnoise
3+
#
4+
5+
# Assumes that the random number generator is Mersenne Twister
6+
7+
echo "Test 1. Should print 242292858 962 five times"
8+
9+
for arg in "" "-ratio=1/2" "-ratio=256/512" "-ratio=32768/65536" "-pack"
10+
do
11+
pbmnoise -endian=big -randomseed=1 1088 7 ${arg} | cksum
12+
done
13+
14+
echo "Test 2."
15+
16+
for ((i=0 ; i<=32; i++))
17+
do
18+
pbmnoise -endian=little -randomseed=11 -ratio=$i/32 -plain 32 1 | \
19+
tr '\n' ' '; echo
20+
done
21+
22+
echo "Test 3. Should print 126142586 1218 four times"
23+
24+
pbmnoise -endian=big -pack -randomseed=12 -plain 19 64 | sed 2d | tr -d '\n' | cksum
25+
pbmnoise -endian=big -pack -randomseed=12 -plain 152 8 | sed 2d | tr -d '\n' | cksum
26+
pbmnoise -endian=big -pack -randomseed=12 -plain 64 19 | sed 2d | tr -d '\n' | cksum
27+
pbmnoise -endian=big -randomseed=12 -plain 64 19 | sed 2d | tr -d '\n' | cksum
28+
29+
echo "Test 4."
30+
31+
pbmnoise -endian=big -randomseed=23 64 1 -plain | tr '\n' ' '; echo
32+
( pbmnoise -endian=native -randomseed=23 64 1 -plain | tr '\n' ' '; echo
33+
pbmnoise -endian=swap -randomseed=23 64 1 -plain | tr '\n' ' '; echo
34+
) | sort -nr
35+
pbmnoise -endian=little -randomseed=23 64 1 -plain | tr '\n' ' '; echo
36+

test/pbmnoise2.ok

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Test 1. Should print OK 1, then OK 2 three times
2+
OK 1
3+
OK 2
4+
OK 2
5+
OK 2
6+
Test 2. Should print OK 1, then OK 2 three times
7+
OK 1
8+
OK 2
9+
OK 2
10+
OK 2
11+
Test 3-black. Should print 255 384 100% 100% four times
12+
255 384 100% 100%
13+
255 384 100% 100%
14+
255 384 100% 100%
15+
255 384 100% 100%
16+
Test 3-white. Should print 0 320 100% 100% three times
17+
0 320 100% 100%
18+
0 320 100% 100%
19+
0 320 100% 100%

test/pbmnoise2.test

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#! /bin/bash
2+
# This script tests: pbmnoise
3+
# Also requires: pgmhist
4+
5+
# Expected value and variance of binominal distribution:
6+
# Pb: probability of getting a black pixel (=ratio)
7+
# Pw: probability of getting a white pixel (= 1 - Pb = 1 - ratio)
8+
#
9+
# E(width, height, Pb, Pw) = width * height * Pb
10+
# V(width, height, Pb, Pw) = width * height * Pb * Pw
11+
#
12+
# When width * height is large and Pb is not too near edges
13+
# approximate with normal distribution
14+
15+
echo "Test 1. Should print OK 1, then OK 2 three times"
16+
17+
args1="-endian=big -randomseed=1"
18+
19+
( pbmnoise ${args1} 320 200 | pgmhist
20+
pbmnoise -ratio=1/2 ${args1} 160 400 | pgmhist
21+
pbmnoise -ratio=2/4 ${args1} 64000 1 | pgmhist
22+
pbmnoise -pack ${args1} 10 6400 | pgmhist ) | \
23+
awk 'BEGIN { pixels=64000; Pb=Pw=0.5;
24+
average=pixels*Pb;
25+
sd=sqrt(pixels*Pb*Pw); # standard deviation
26+
sl=1.96 # significance level
27+
limit1 = average - sd * sl;
28+
limit2 = average + sd * sl
29+
count=-1 # initial value
30+
}
31+
$1!=0 { next }
32+
{ v=1 } # initial value
33+
limit1 < $2 && $2 < limit2 { v=0 }
34+
v==0 {print "OK", (count==prev)+1}
35+
v==1 {print "NG" $0}
36+
{prev=count}'
37+
38+
39+
40+
echo "Test 2. Should print OK 1, then OK 2 three times"
41+
42+
args2="-endian=big -randomseed=2"
43+
44+
( pbmnoise -ratio=11/32 ${args1} 32 119 | pgmhist
45+
pbmnoise -ratio=11/32 ${args1} 224 17 | pgmhist
46+
pbmnoise -ratio=22/64 ${args1} 3808 1 | pgmhist
47+
pbmnoise -ratio=44/128 -pack ${args1} 1904 2 | pgmhist ) | \
48+
awk 'BEGIN {pixels=32*119; Pb=11/32; Pw=1-Pb;
49+
average=pixels*Pb;
50+
sd=sqrt(pixels*Pb*Pw); # standard deviation
51+
sl=1.96 # significance level
52+
limit1 = average - sd * sl;
53+
limit2 = average + sd * sl
54+
count=-1 # initial value
55+
}
56+
$1!=0 { next }
57+
{ v=1 } # initial value
58+
limit1 < $2 && $2 < limit2 { v=0 }
59+
v==0 {print "OK", (count==prev)+1}
60+
v==1 {print "NG" $0}
61+
{prev=count}'
62+
63+
64+
65+
66+
echo "Test 3-black. Should print 255 384 100% 100% four times"
67+
68+
pbmnoise -ratio=0/1 -randomseed=1 128 3 | pgmhist | \
69+
awk '$1==0 || $1==255'
70+
pbmnoise -ratio=0/1024 -randomseed=1 64 6 | pgmhist | \
71+
awk '$1==0 || $1==255'
72+
pbmnoise -ratio=0/8192 -randomseed=1 32 12 | pgmhist | \
73+
awk '$1==0 || $1==255'
74+
pbmnoise -ratio=0/65536 -randomseed=1 -pack 1 384 | pgmhist | \
75+
awk '$1==0 || $1==255'
76+
77+
echo "Test 3-white. Should print 0 320 100% 100% three times"
78+
79+
pbmnoise -ratio=1/1 -randomseed=1 64 5 | pgmhist | \
80+
awk '$1==0 || $1==255'
81+
pbmnoise -ratio=8/8 -randomseed=1 32 10 | pgmhist | \
82+
awk '$1==0 || $1==255'
83+
pbmnoise -ratio=65536/65536 -randomseed=1 -pack 2 160 | pgmhist | \
84+
awk '$1==0 || $1==255'
85+

0 commit comments

Comments
 (0)