From 7b42fdfafb461b568a259870de22c34d4b4e1343 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 22 Dec 2018 17:11:33 +0000 Subject: Add tests git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3462 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- test/Test-Order | 5 +- test/cut-cat-roundtrip.ok | 92 +++++++++++++++++++++++++++++ test/cut-cat-roundtrip.test | 128 +++++++++++++++++++++++++++++++++++++++++ test/pamcut.ok | 15 +++++ test/pamcut.test | 35 ++++++++++- test/pammixmulti-identity.ok | 22 +++++++ test/pammixmulti-identity.test | 77 +++++++++++++++++++++++++ test/pnmpaste-pbm.ok | 22 +++++++ test/pnmpaste-pbm.test | 47 +++++++++++++++ 9 files changed, 439 insertions(+), 4 deletions(-) create mode 100644 test/cut-cat-roundtrip.ok create mode 100755 test/cut-cat-roundtrip.test create mode 100644 test/pammixmulti-identity.ok create mode 100755 test/pammixmulti-identity.test create mode 100644 test/pnmpaste-pbm.ok create mode 100755 test/pnmpaste-pbm.test (limited to 'test') diff --git a/test/Test-Order b/test/Test-Order index fbeaf6a3..8bda73a4 100644 --- a/test/Test-Order +++ b/test/Test-Order @@ -1,4 +1,4 @@ -# General test +# General tests all-in-place.test legacy-names.test @@ -63,6 +63,7 @@ pnminvert.test pamchannel.test ppmchange.test pambackground.test +pnmpaste-pbm.test pbmpscale.test pnmremap1.test @@ -78,6 +79,7 @@ pnmshear.test pgmbentley.test ppmmix.test +pammixmulti-identity.test # Symmetry test @@ -111,6 +113,7 @@ pamdice-roundtrip.test pamslice-roundtrip.test lookup-roundtrip.test enlarge-reduce-roundtrip.test +cut-cat-roundtrip.test # Round-trip tests : lossless converters diff --git a/test/cut-cat-roundtrip.ok b/test/cut-cat-roundtrip.ok new file mode 100644 index 00000000..bc9b8cb4 --- /dev/null +++ b/test/cut-cat-roundtrip.ok @@ -0,0 +1,92 @@ +Test 1. +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +Test 2. +3891261972 202953 +3891261972 202953 +3891261972 202953 +3891261972 202953 +3891261972 202953 +3891261972 202953 +Test 3. +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +Test 4. +26789469 202953 +26789469 202953 +26789469 202953 +26789469 202953 +26789469 202953 +Test 5. +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +Test 6. +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +1887700557 73 +Test 7. +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +Test 8. +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 +3221289196 73 diff --git a/test/cut-cat-roundtrip.test b/test/cut-cat-roundtrip.test new file mode 100755 index 00000000..95ee5279 --- /dev/null +++ b/test/cut-cat-roundtrip.test @@ -0,0 +1,128 @@ +#! /bin/bash +# This script tests: pamcut +# Also requires: pnmcat pnmpad + +tmpdir=${tmpdir:-/tmp} +quant_ppm=${tmpdir}/quant.ppm + +right_pbm=${tmpdir}/right.pbm +left_pbm=${tmpdir}/left.pbm +right_ppm=${tmpdir}/right.ppm +left_ppm=${tmpdir}/left.ppm +bottom_pbm=${tmpdir}/bottom.pbm +top_pbm=${tmpdir}/top.pbm +bottom_ppm=${tmpdir}/bottom.ppm +top_ppm=${tmpdir}/top.ppm + + +# Test 1. Should print 1926073387 101484 six times +echo Test 1. + +cat testimg.ppm | cksum +for i in 0 1 128 224 225 + do + pamcut -left=$((i+1)) testimg.ppm > ${right_ppm} + pamcut -right=$i testimg.ppm > ${left_ppm} + pnmcat -lr ${left_ppm} ${right_ppm} | \ + pamcut -left=0 -width=227| cksum + rm ${left_ppm} ${right_ppm} + done + + +# Test 2. Should print 3891261972 202953 six times +# Not roundtrip. Padding added to right. +echo Test 2. + +pnmpad -right=227 -black testimg.ppm | cksum +for i in 0 1 128 224 225 + do + pamcut -left=$((i+1)) -width=227 -pad testimg.ppm > ${right_ppm} + pamcut -right=$i -width=227 -pad testimg.ppm > ${left_ppm} + pnmcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \ + pamcut -left=$((227-i-1)) -width=$((227*2)) | cksum + rm ${left_ppm} ${right_ppm} + done + + +# Test 3. Should print 1926073387 101484 five times +echo Test 3. + +cat testimg.ppm | cksum +for i in 0 1 70 147 + do + pamcut -top=$((i+1)) testimg.ppm > ${bottom_ppm} + pamcut -bottom=$i testimg.ppm > ${top_ppm} + pnmcat -tb ${top_ppm} ${bottom_ppm} | \ + pamcut -top=0 -height=149 | cksum + rm ${top_ppm} ${bottom_ppm} + done + +# Test 4. Should print 26789469 202953 five times +# Not roundtrip. Padding added to bottom. +echo Test 4. + +pnmpad -bottom=149 -black testimg.ppm | cksum +for i in 0 1 70 147 + do + pamcut -top=$((i+1)) -height=149 -pad testimg.ppm > ${bottom_ppm} + pamcut -bottom=$i -height=149 -pad testimg.ppm > ${top_ppm} + pnmcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \ + pamcut -top=$((149-i-1)) -height=$((149*2)) | cksum + rm ${top_ppm} ${bottom_ppm} + done + +# Test 5. Should print 2425386270 41 fourteen times +echo Test 5. + +cat testgrid.pbm | cksum +for i in `seq 0 12` + do + pamcut -left=$((i+1)) testgrid.pbm > ${right_pbm} + pamcut -right=$i testgrid.pbm > ${left_pbm} + pnmcat -lr ${left_pbm} ${right_pbm} | \ + pamcut -left=0 -width=14 | cksum + rm ${left_pbm} ${right_pbm} + done + + +# Test 6. Should print 1887700557 73 fifteen times +# Not roundtrip. Padding added to right. +echo Test 6. + +pnmpad -right=14 -black testgrid.pbm | cksum +for i in `seq 0 13` + do + pamcut -left=$((i+1)) -width=14 -pad testgrid.pbm > ${right_pbm} + pamcut -right=$i -width=14 -pad testgrid.pbm > ${left_pbm} + pnmcat -lr ${left_pbm} ${right_pbm} ${left_pbm} | \ + pamcut -left=$((14-i-1)) -width=28 | cksum + rm ${left_pbm} ${right_pbm} + done + +# Test 7. Should print 2425386270 41 sixteen times +echo Test 7. + +cat testgrid.pbm | cksum +for i in `seq 0 14` + do + pamcut -top=$((i+1)) testgrid.pbm > ${bottom_pbm} + pamcut -bottom=$i testgrid.pbm > ${top_pbm} + pnmcat -tb ${top_pbm} ${bottom_pbm} | \ + pamcut -top=0 -height=16 | cksum + rm ${top_pbm} ${bottom_pbm} + done + +# Test 8. Should print 3221289196 73 seventeen times +# Not roundtrip. Padding added to bottom. +echo Test 8. + +pnmpad -bottom=16 -black testgrid.pbm | cksum +for i in `seq 0 15` + do + pamcut -top=$((i+1)) -height=16 -pad testgrid.pbm > ${bottom_pbm} + pamcut -bottom=$i -height=16 -pad testgrid.pbm > ${top_pbm} + pnmcat -tb ${top_pbm} ${bottom_pbm} ${top_pbm} | \ + pamcut -top=$((16-i-1)) -height=32 | cksum + rm ${top_pbm} ${bottom_pbm} + done + diff --git a/test/pamcut.ok b/test/pamcut.ok index 61ef99bc..b08bc531 100644 --- a/test/pamcut.ok +++ b/test/pamcut.ok @@ -1,4 +1,19 @@ +Test 1. 2958909756 124815 +Test 2. 1550940962 10933 +Test 3. 708474423 14 +708474423 14 +Test 4. +659346598 80124 +659346598 80124 +659346598 80124 +659346598 80124 +Test 5. +2425386270 41 +2425386270 41 +2425386270 41 +2425386270 41 +Test 6. 3412257956 129 diff --git a/test/pamcut.test b/test/pamcut.test index fd9185a3..9971b1a5 100755 --- a/test/pamcut.test +++ b/test/pamcut.test @@ -2,17 +2,46 @@ # This script tests: pamcut pbmmake # Also requires: - # Test 1. Should print 2958909756 124815 +echo Test 1. + pamcut -top 0 -left 0 -width 260 -height 160 \ -pad testimg.ppm | cksum # Test 2. Should print 1550940962 10933 +echo Test 2. + pamcut -top 200 -left 120 -width 40 -height 40 \ -pad testimg.ppm | cksum -# Test 3. Should print 708474423 14 +# Test 3. Should print 708474423 14 twice +echo Test 3. + pamcut -top 5 -left 5 -bottom 5 -right 5 testimg.ppm | cksum +pamcut -width 1 -height 1 -bottom 5 -right 5 testimg.ppm | cksum + + +# Test 4. Should print 659346598 80124 four times +echo Test 4. + +pamcut -croptop 10 -cropleft 10 -cropbottom 10 -cropright 10 testimg.ppm | \ + cksum +pamcut -top 10 -left 10 -bottom 138 -right 216 testimg.ppm | cksum +pamcut -top 10 -left 10 -bottom -11 -right -11 testimg.ppm | cksum +pamcut -top 10 -left 10 -width 207 -height 129 testimg.ppm | cksum + + +# Test 5. Should print 2425386270 41 four times +echo Test 5. + +pamcut -croptop 0 -cropleft 0 -cropbottom 0 -cropright 0 testgrid.pbm | \ + cksum +pamcut -top 0 -left 0 -bottom 15 -right 13 testgrid.pbm | cksum +pamcut -top 0 -left 0 -bottom -1 -right -1 testgrid.pbm | cksum +pamcut -top 0 -left 0 -width 14 -height 16 testgrid.pbm | cksum + + +# Test 6. Should print 3412257956 129 +echo Test 6. -# Test 4. Should print 3412257956 129 pbmmake -g 50 50 | pamcut 5 5 30 30 | cksum diff --git a/test/pammixmulti-identity.ok b/test/pammixmulti-identity.ok new file mode 100644 index 00000000..9e712f7f --- /dev/null +++ b/test/pammixmulti-identity.ok @@ -0,0 +1,22 @@ +Test 1. +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +1926073387 101484 +Test 2. +1926073387 101484 +1926073387 101484 +1926073387 101484 +Test 3. +1926073387 101484 +1926073387 101484 +1926073387 101484 +Test 4. +127 +127 +127 +127 +127 +127 diff --git a/test/pammixmulti-identity.test b/test/pammixmulti-identity.test new file mode 100755 index 00000000..d205c359 --- /dev/null +++ b/test/pammixmulti-identity.test @@ -0,0 +1,77 @@ +#! /bin/bash +# This script tests: pammixmulti +# Also requires: pgmnoise pnminvert pamsumm + +tmpdir=${tmpdir:-/tmp} + +# Test 1. Should print 1926073387 101484 six times +echo Test 1. + +pammixmulti testimg.ppm | cksum +pammixmulti testimg.ppm testimg.ppm | cksum +pammixmulti testimg.ppm testimg.ppm testimg.ppm | cksum +pammixmulti -blend=average testimg.ppm testimg.ppm | cksum +pammixmulti -blend=average testimg.ppm testimg.ppm testimg.ppm | cksum +pammixmulti -blend=random -randomseed=1 \ + testimg.ppm testimg.ppm testimg.ppm | cksum + + +# Test 2. Should print 1926073387 101484 three times +echo Test 2. + +mask_pgm=${tmpdir}/mask.pgm +pgmnoise -maxval=2 -randomseed=1 227 149 > ${mask_pgm} + +for sd in 0.5 1.2 3.0 + do + pammixmulti -blend=mask -maskfile=${mask_pgm} -stdev=${sd} \ + testimg.ppm testimg.ppm testimg.ppm | cksum + done +rm ${mask_pgm} + +# Test 3. Should print +echo Test 3. + +noise_pgm=${tmpdir}/noise.pgm +pgmnoise --randomseed=1 227 149 > ${noise_pgm} + +pammixmulti -blend=mask -maskfile=${noise_pgm} \ + testimg.ppm testimg.ppm | cksum +pammixmulti -blend=mask -maskfile=${noise_pgm} \ + testimg.ppm testimg.ppm testimg.ppm | cksum +pammixmulti -blend=mask -maskfile=${noise_pgm} \ + testimg.ppm testimg.ppm testimg.ppm testimg.ppm | cksum +rm ${noise_pgm} + + +# Test 4. + +# Mix image with its own inverse. +# Output should be a monotone gray sheet. +# Should print 127 six times +echo Test 4. + +invert_ppm=${tmpdir}/invert.ppm +monotone_ppm=${tmpdir}/monotone.ppm + +pnminvert testimg.ppm > ${invert_ppm} + +pammixmulti -blend=average testimg.ppm ${invert_ppm} | tee ${monotone_ppm} | \ + pamsumm -brief -max && + pamsumm -brief -min ${monotone_ppm} +rm ${monotone_ppm} + +pammixmulti -blend=average \ + testimg.ppm ${invert_ppm} testimg.ppm ${invert_ppm} | \ + tee ${monotone_ppm} | \ + pamsumm -brief -max && + pamsumm -brief -min ${monotone_ppm} +rm ${monotone_ppm} + +pammixmulti -blend=average \ + testimg.ppm testimg.ppm ${invert_ppm} ${invert_ppm} | \ + tee ${monotone_ppm} | \ + pamsumm -brief -max && + pamsumm -brief -min ${monotone_ppm} + +rm ${monotone_ppm} ${invert_ppm} diff --git a/test/pnmpaste-pbm.ok b/test/pnmpaste-pbm.ok new file mode 100644 index 00000000..d3b0a7e8 --- /dev/null +++ b/test/pnmpaste-pbm.ok @@ -0,0 +1,22 @@ +Test 1. +-replace +P1 18 1 001010101010101011 +-and +P1 18 1 001111101111101111 +-or +P1 18 1 000010000010000011 +-xor +P1 18 1 010010010010010011 +-nand +P1 18 1 010000010000010011 +-nor +P1 18 1 011101111101111111 +-nxor +P1 18 1 001101101101101111 +Test 2. +-and -nand +P1 18 1 110000000000000001 +-or -nor +P1 18 1 110000000000000001 +-xor -nxor +P1 18 1 110000000000000001 diff --git a/test/pnmpaste-pbm.test b/test/pnmpaste-pbm.test new file mode 100755 index 00000000..b75797af --- /dev/null +++ b/test/pnmpaste-pbm.test @@ -0,0 +1,47 @@ +#! /bin/bash +# This script tests: pnmpaste +# Also requires: pbmmake + +tmpdir=${tmpdir:-/tmp} +base_pbm=${tmpdir}/font.pbm +insert_pbm=${tmpdir}/insert.pbm + +cat > ${base_pbm} << EOF +P1 +18 1 +000111000111000111 +EOF + +pbmmake -g 15 1 > ${insert_pbm} + +# Test 1. +echo "Test 1." + +for operation in "-replace" "-and" "-or" "-xor" "-nand" "-nor" "-nxor" + do + echo ${operation} + pnmpaste ${operation} -plain ${insert_pbm} 1 0 ${base_pbm} | tr '\n' ' ' + echo + done + + +# Test 2. +# Perform an operation and its negative counterpart, combine the +# resulting images with "-xor". +# The untouched area of the base image should be 1; inserted area 0. + +echo "Test 2." + +positive_pbm=${tmpdir}/positive.pbm +negative_pbm=${tmpdir}/negative.pbm + +for operation in "and" "or" "xor" + do + echo "-"$operation " -n"$operation + pnmpaste "-"${operation} ${insert_pbm} 2 0 ${base_pbm} > ${positive_pbm} + pnmpaste "-n"${operation} ${insert_pbm} 2 0 ${base_pbm} > ${negative_pbm} + pnmpaste -xor -plain ${positive_pbm} 0 0 ${negative_pbm} | tr '\n ' ' ' + echo + done + +rm ${base_pbm} ${insert_pbm} ${positive_pbm} ${negative_pbm} -- cgit 1.4.1