From 0edecba31c963f14b9b0a3361891fd8a46ae7942 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 18 Dec 2021 22:48:59 +0000 Subject: Add tests for 'pbmnoise' git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4207 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- test/Test-Order | 3 + test/pbmnoise-parameters.ok | 26 ++++++++ test/pbmnoise-parameters.test | 143 ++++++++++++++++++++++++++++++++++++++++++ test/pbmnoise1.ok | 50 +++++++++++++++ test/pbmnoise1.test | 36 +++++++++++ test/pbmnoise2.ok | 19 ++++++ test/pbmnoise2.test | 85 +++++++++++++++++++++++++ 7 files changed, 362 insertions(+) create mode 100644 test/pbmnoise-parameters.ok create mode 100755 test/pbmnoise-parameters.test create mode 100644 test/pbmnoise1.ok create mode 100755 test/pbmnoise1.test create mode 100644 test/pbmnoise2.ok create mode 100755 test/pbmnoise2.test diff --git a/test/Test-Order b/test/Test-Order index 67ce0831..c21f892d 100644 --- a/test/Test-Order +++ b/test/Test-Order @@ -27,6 +27,9 @@ ppmforge-parameters.test # Generators with random components +pbmnoise1.test +pbmnoise2.test +pbmnoise-parameters.test pgmnoise.test pgmnoise-parameters.test ppmpat-random.test diff --git a/test/pbmnoise-parameters.ok b/test/pbmnoise-parameters.ok new file mode 100644 index 00000000..c2a61c37 --- /dev/null +++ b/test/pbmnoise-parameters.ok @@ -0,0 +1,26 @@ +Test Invalid +Expected failure 1 1 +Expected failure 2 1 +Expected failure 3 1 +Expected failure 4 1 +Expected failure 5 1 +Expected failure 6 1 +Expected failure 7 1 +Expected failure 8 1 +Expected failure 9 1 +Expected failure 10 1 +Expected failure 11 1 +Expected failure 12 1 +Expected failure 13 1 +Expected failure 14 1 +Expected failure 15 1 +Expected failure 16 1 +Expected failure 17 1 +Expected failure 17 1 +Expected failure 18 1 +Expected failure 19 1 +Expected failure 20 1 +Expected failure 21 1 +Expected failure 22 1 +Expected failure 23 1 +Expected failure 24 1 diff --git a/test/pbmnoise-parameters.test b/test/pbmnoise-parameters.test new file mode 100755 index 00000000..f3348ae8 --- /dev/null +++ b/test/pbmnoise-parameters.test @@ -0,0 +1,143 @@ +#! /bin/bash +# This script tests: pbmnoise +# Also requires: + +echo "Invalid command-line argument combinations." 1>&2 +echo "Error messages should appear below the line." 1>&2 +echo "-----------------------------------------------------------" 1>&2 + +echo "Test Invalid" + +test_out=${tmpdir}/test_out + +# Invalid -ratio arguments + +pbmnoise -ratio 100 100 > ${test_out} || \ + echo -n "Expected failure 1" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio 0 1 100 > ${test_out} || \ + echo -n "Expected failure 2" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=1.1 100 100 > ${test_out} || \ + echo -n "Expected failure 3" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=-1 100 100 > ${test_out} || \ + echo -n "Expected failure 4" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=half 100 100 > ${test_out} || \ + echo -n "Expected failure 5" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=0/1/1 100 100 > ${test_out} || \ + echo -n "Expected failure 6" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=-1/2 100 100 > ${test_out} || \ + echo -n "Expected failure 7" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=1/0 100 100 > ${test_out} || \ + echo -n "Expected failure 8" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=/2 100 100 > ${test_out} || \ + echo -n "Expected failure 9" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=4/2 100 100 > ${test_out} || \ + echo -n "Expected failure 10" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=6/ 100 100 > ${test_out} || \ + echo -n "Expected failure 11" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=1.0/2.0 100 100 > ${test_out} || \ + echo -n "Expected failure 12" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +# denominator must be power of 2 +pbmnoise -ratio=3/9 100 100 > ${test_out} || \ + echo -n "Expected failure 13" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=a/2 100 100 > ${test_out} || \ + echo -n "Expected failure 14" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + + +pbmnoise -ratio=2/a 100 100 > ${test_out} || \ + echo -n "Expected failure 15" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=1/-2 100 100 > ${test_out} || \ + echo -n "Expected failure 16" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +# Denominator must be 65536 or less +pbmnoise -ratio=1/65537 100 100 > ${test_out} || \ + echo -n "Expected failure 17" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -ratio=1/131072 100 100 > ${test_out} || \ + echo -n "Expected failure 17" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -endian=large 100 100 > ${test_out} || \ + echo -n "Expected failure 18" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -randomseed 100 100 > ${test_out} || \ + echo -n "Expected failure 19" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -randomseed=-1 100 100 > ${test_out} || \ + echo -n "Expected failure 20" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise -randomseed=0.1 100 100 > ${test_out} || \ + echo -n "Expected failure 21" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise > ${test_out} || \ + echo -n "Expected failure 22" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise 100 > ${test_out} || \ + echo -n "Expected failure 23" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + +pbmnoise 100 200 300 > ${test_out} || \ + echo -n "Expected failure 24" + test -s ${test_out}; echo " "$? + rm -f ${test_out} + + diff --git a/test/pbmnoise1.ok b/test/pbmnoise1.ok new file mode 100644 index 00000000..84f1f04e --- /dev/null +++ b/test/pbmnoise1.ok @@ -0,0 +1,50 @@ +Test 1. Should print 242292858 962 five times +242292858 962 +242292858 962 +242292858 962 +242292858 962 +242292858 962 +Test 2. +P1 32 1 00000000000000000000000000000000 +P1 32 1 00010000000001000000000000000000 +P1 32 1 00010000000001000010000000000000 +P1 32 1 00010000000001000000000000000000 +P1 32 1 00010000000001000010010000000000 +P1 32 1 01010001000101000000000000000000 +P1 32 1 00010000000001000010100000000000 +P1 32 1 01010001000111000000000000100010 +P1 32 1 10011001000001100010010000000000 +P1 32 1 01010001000111000000010100100010 +P1 32 1 01011001000101000010100000000000 +P1 32 1 01010001000111000001010100100110 +P1 32 1 00010000000001000111110000000100 +P1 32 1 01010001010111001001010100100110 +P1 32 1 01011011000111000010101000101010 +P1 32 1 01010001011111011001010100110110 +P1 32 1 10011001001001110010011000101110 +P1 32 1 01010001011111011011010101110110 +P1 32 1 01011011000111000010111110101010 +P1 32 1 01010001011111011011110101110110 +P1 32 1 11011001010101101111110000000100 +P1 32 1 01011001011111011011110101110110 +P1 32 1 01011011000111000111111110101110 +P1 32 1 01011011011111011011111101111110 +P1 32 1 10111111101011110111111000111111 +P1 32 1 01011011011111011011111111111110 +P1 32 1 11011011010111101111111110101110 +P1 32 1 01011011011111011111111111111110 +P1 32 1 11111111111111111111111000111111 +P1 32 1 11011011011111111111111111111110 +P1 32 1 11111111111111111111111110111111 +P1 32 1 11111111111111111111111111111111 +P1 32 1 11111111111111111111111111111111 +Test 3. Should print 126142586 1218 four times +126142586 1218 +126142586 1218 +126142586 1218 +126142586 1218 +Test 4. +P1 64 1 1000010001101101101000100101001110101011010010011111001011100110 +P1 64 1 1000010001101101101000100101001110101011010010011111001011100110 +P1 64 1 0101001110100010011011011000010011100110111100100100100110101011 +P1 64 1 0101001110100010011011011000010011100110111100100100100110101011 diff --git a/test/pbmnoise1.test b/test/pbmnoise1.test new file mode 100755 index 00000000..1b8fc241 --- /dev/null +++ b/test/pbmnoise1.test @@ -0,0 +1,36 @@ +#! /bin/bash +# This script tests: pbmnoise +# + +# Assumes that the random number generator is Mersenne Twister + +echo "Test 1. Should print 242292858 962 five times" + +for arg in "" "-ratio=1/2" "-ratio=256/512" "-ratio=32768/65536" "-pack" + do + pbmnoise -endian=big -randomseed=1 1088 7 ${arg} | cksum +done + +echo "Test 2." + +for ((i=0 ; i<=32; i++)) + do + pbmnoise -endian=little -randomseed=11 -ratio=$i/32 -plain 32 1 | \ + tr '\n' ' '; echo +done + +echo "Test 3. Should print 126142586 1218 four times" + +pbmnoise -endian=big -pack -randomseed=12 -plain 19 64 | sed 2d | tr -d '\n' | cksum +pbmnoise -endian=big -pack -randomseed=12 -plain 152 8 | sed 2d | tr -d '\n' | cksum +pbmnoise -endian=big -pack -randomseed=12 -plain 64 19 | sed 2d | tr -d '\n' | cksum +pbmnoise -endian=big -randomseed=12 -plain 64 19 | sed 2d | tr -d '\n' | cksum + +echo "Test 4." + + pbmnoise -endian=big -randomseed=23 64 1 -plain | tr '\n' ' '; echo +( pbmnoise -endian=native -randomseed=23 64 1 -plain | tr '\n' ' '; echo + pbmnoise -endian=swap -randomseed=23 64 1 -plain | tr '\n' ' '; echo +) | sort -nr + pbmnoise -endian=little -randomseed=23 64 1 -plain | tr '\n' ' '; echo + diff --git a/test/pbmnoise2.ok b/test/pbmnoise2.ok new file mode 100644 index 00000000..5c3959e0 --- /dev/null +++ b/test/pbmnoise2.ok @@ -0,0 +1,19 @@ +Test 1. Should print OK 1, then OK 2 three times +OK 1 +OK 2 +OK 2 +OK 2 +Test 2. Should print OK 1, then OK 2 three times +OK 1 +OK 2 +OK 2 +OK 2 +Test 3-black. Should print 255 384 100% 100% four times + 255 384 100% 100% + 255 384 100% 100% + 255 384 100% 100% + 255 384 100% 100% +Test 3-white. Should print 0 320 100% 100% three times + 0 320 100% 100% + 0 320 100% 100% + 0 320 100% 100% diff --git a/test/pbmnoise2.test b/test/pbmnoise2.test new file mode 100755 index 00000000..7476d03c --- /dev/null +++ b/test/pbmnoise2.test @@ -0,0 +1,85 @@ +#! /bin/bash +# This script tests: pbmnoise +# Also requires: pgmhist + +# Expected value and variance of binominal distribution: +# Pb: probability of getting a black pixel (=ratio) +# Pw: probability of getting a white pixel (= 1 - Pb = 1 - ratio) +# +# E(width, height, Pb, Pw) = width * height * Pb +# V(width, height, Pb, Pw) = width * height * Pb * Pw +# +# When width * height is large and Pb is not too near edges +# approximate with normal distribution + +echo "Test 1. Should print OK 1, then OK 2 three times" + +args1="-endian=big -randomseed=1" + +( pbmnoise ${args1} 320 200 | pgmhist + pbmnoise -ratio=1/2 ${args1} 160 400 | pgmhist + pbmnoise -ratio=2/4 ${args1} 64000 1 | pgmhist + pbmnoise -pack ${args1} 10 6400 | pgmhist ) | \ + awk 'BEGIN { pixels=64000; Pb=Pw=0.5; + average=pixels*Pb; + sd=sqrt(pixels*Pb*Pw); # standard deviation + sl=1.96 # significance level + limit1 = average - sd * sl; + limit2 = average + sd * sl + count=-1 # initial value + } + $1!=0 { next } + { v=1 } # initial value + limit1 < $2 && $2 < limit2 { v=0 } + v==0 {print "OK", (count==prev)+1} + v==1 {print "NG" $0} + {prev=count}' + + + +echo "Test 2. Should print OK 1, then OK 2 three times" + +args2="-endian=big -randomseed=2" + +( pbmnoise -ratio=11/32 ${args1} 32 119 | pgmhist + pbmnoise -ratio=11/32 ${args1} 224 17 | pgmhist + pbmnoise -ratio=22/64 ${args1} 3808 1 | pgmhist + pbmnoise -ratio=44/128 -pack ${args1} 1904 2 | pgmhist ) | \ + awk 'BEGIN {pixels=32*119; Pb=11/32; Pw=1-Pb; + average=pixels*Pb; + sd=sqrt(pixels*Pb*Pw); # standard deviation + sl=1.96 # significance level + limit1 = average - sd * sl; + limit2 = average + sd * sl + count=-1 # initial value + } + $1!=0 { next } + { v=1 } # initial value + limit1 < $2 && $2 < limit2 { v=0 } + v==0 {print "OK", (count==prev)+1} + v==1 {print "NG" $0} + {prev=count}' + + + + +echo "Test 3-black. Should print 255 384 100% 100% four times" + +pbmnoise -ratio=0/1 -randomseed=1 128 3 | pgmhist | \ + awk '$1==0 || $1==255' +pbmnoise -ratio=0/1024 -randomseed=1 64 6 | pgmhist | \ + awk '$1==0 || $1==255' +pbmnoise -ratio=0/8192 -randomseed=1 32 12 | pgmhist | \ + awk '$1==0 || $1==255' +pbmnoise -ratio=0/65536 -randomseed=1 -pack 1 384 | pgmhist | \ + awk '$1==0 || $1==255' + +echo "Test 3-white. Should print 0 320 100% 100% three times" + +pbmnoise -ratio=1/1 -randomseed=1 64 5 | pgmhist | \ + awk '$1==0 || $1==255' +pbmnoise -ratio=8/8 -randomseed=1 32 10 | pgmhist | \ + awk '$1==0 || $1==255' +pbmnoise -ratio=65536/65536 -randomseed=1 -pack 2 160 | pgmhist | \ + awk '$1==0 || $1==255' + -- cgit 1.4.1