diff options
Diffstat (limited to 'test/cut-cat-roundtrip.test')
-rwxr-xr-x | test/cut-cat-roundtrip.test | 181 |
1 files changed, 100 insertions, 81 deletions
diff --git a/test/cut-cat-roundtrip.test b/test/cut-cat-roundtrip.test index 95ee5279..274cb865 100755 --- a/test/cut-cat-roundtrip.test +++ b/test/cut-cat-roundtrip.test @@ -1,128 +1,147 @@ -#! /bin/bash +#! /bin/sh # This script tests: pamcut -# Also requires: pnmcat pnmpad +# Also requires: pamfile pamcat pnmpad pnmcrop 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 +right_ppm=${tmpdir}/right.ppm top_ppm=${tmpdir}/top.ppm +bottom_ppm=${tmpdir}/bottom.ppm +padded_ppm=${tmpdir}/padded.ppm + +echo "Test 1. Should print 1926073387 101484 six times" +testimg_ppm_sum=`cksum < testimg.ppm` +echo ${testimg_ppm_sum} -# Test 1. Should print 1926073387 101484 six times -echo Test 1. +imgsize=$(pamfile -size testimg.ppm) +width=$(echo ${imgsize} | cut -d " " -f 1) +height=$(echo ${imgsize} | cut -d " " -f 2) -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 + pamcat -lr ${left_ppm} ${right_ppm} | \ + pamcut -left=0 -width=${width} | cksum rm ${left_ppm} ${right_ppm} done +echo "Test 2. Should print 3891261972 202953 1926073387 101484 six times" +# Padding added to right. -# Test 2. Should print 3891261972 202953 six times -# Not roundtrip. Padding added to right. -echo Test 2. +pnmpad -right=${width} -black testimg.ppm | cksum | tr '\n' ' ' +echo ${testimg_ppm_sum} -pnmpad -right=227 -black testimg.ppm | cksum -for i in 0 1 128 224 225 +for border 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} + pamcut -left=$((${border}+1)) -width=${width} -pad testimg.ppm > ${right_ppm} + pamcut -right=${border} -width=${width} -pad testimg.ppm > ${left_ppm} + pamcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \ + pamcut -left=$((${width}-${border}-1)) -width=$((${width}*2)) | \ + tee ${padded_ppm} | cksum | tr '\n' ' ' + pnmcrop -black -right ${padded_ppm} | cksum + rm ${left_ppm} ${right_ppm} ${padded_ppm} done -# Test 3. Should print 1926073387 101484 five times -echo Test 3. +echo "Test 3. Should print 1926073387 101484 five times" -cat testimg.ppm | cksum -for i in 0 1 70 147 +echo ${testimg_ppm_sum} +for border 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 + pamcut -top=$((${border}+1)) testimg.ppm > ${bottom_ppm} + pamcut -bottom=${border} testimg.ppm > ${top_ppm} + pamcat -tb ${top_ppm} ${bottom_ppm} | \ + pamcut -top=0 -height=${height} | cksum rm ${top_ppm} ${bottom_ppm} done -# Test 4. Should print 26789469 202953 five times -# Not roundtrip. Padding added to bottom. -echo Test 4. +echo "Test 4. Should print 26789469 202953 1926073387 101484 five times" +# Padding added to bottom. -pnmpad -bottom=149 -black testimg.ppm | cksum -for i in 0 1 70 147 +pnmpad -bottom=${height} -black testimg.ppm | cksum | tr '\n' ' ' +echo ${testimg_ppm_sum} +for border 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} + pamcut -top=$((${border}+1)) -height=${height} -pad testimg.ppm \ + > ${bottom_ppm} + pamcut -bottom=${border} -height=${height} -pad testimg.ppm > ${top_ppm} + pamcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \ + pamcut -top=$((${height}-${border}-1)) -height=$((${height}*2)) | \ + tee ${padded_ppm} | cksum | tr '\n' ' 'cksum + pnmcrop -black -bottom ${padded_ppm} | cksum + rm ${top_ppm} ${bottom_ppm} ${padded_ppm} done -# Test 5. Should print 2425386270 41 fourteen times -echo Test 5. +left_pbm=${tmpdir}/left.pbm +right_pbm=${tmpdir}/right.pbm +top_pbm=${tmpdir}/top.pbm +bottom_pbm=${tmpdir}/bottom.pbm +padded_pbm=${tmpdir}/padded.pbm + +echo "Test 5. Should print 281226646 481 six times" + +maze_pbm_sum=`cksum < maze.pbm` +echo ${maze_pbm_sum} + +imgsize=$(pamfile -size maze.pbm) +width=$(echo ${imgsize} | cut -d " " -f 1) +height=$(echo ${imgsize} | cut -d " " -f 2) -cat testgrid.pbm | cksum -for i in `seq 0 12` +for i in 0 1 10 30 50 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} + pamcut -left=$((i+1)) maze.pbm > ${right_ppm} + pamcut -right=$i maze.pbm > ${left_ppm} + pamcat -lr ${left_ppm} ${right_ppm} | \ + pamcut -left=0 -width=${width} | cksum + rm ${left_ppm} ${right_ppm} done -# Test 6. Should print 1887700557 73 fifteen times -# Not roundtrip. Padding added to right. -echo Test 6. +echo "Test 6. Should print 1748767123 895 281226646 481 six times" +# Padding added to right. + +pnmpad -right=${width} -black maze.pbm | cksum | tr '\n' ' ' +echo ${maze_pbm_sum} -pnmpad -right=14 -black testgrid.pbm | cksum -for i in `seq 0 13` +for border in 0 1 10 30 50 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} + pamcut -left=$((${border}+1)) -width=${width} -pad maze.pbm > ${right_ppm} + pamcut -right=${border} -width=${width} -pad maze.pbm > ${left_ppm} + pamcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \ + pamcut -left=$((${width}-${border}-1)) -width=$((${width}*2)) | \ + tee ${padded_ppm} | cksum | tr '\n' ' ' + pnmcrop -black -right ${padded_ppm} | cksum + rm ${left_ppm} ${right_ppm} ${padded_ppm} done -# Test 7. Should print 2425386270 41 sixteen times -echo Test 7. -cat testgrid.pbm | cksum -for i in `seq 0 14` +echo "Test 7. Should print 281226646 481 seven times" + +echo ${maze_pbm_sum} +for border in 0 1 12 21 31 44 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} + pamcut -top=$((${border}+1)) maze.pbm > ${bottom_ppm} + pamcut -bottom=${border} maze.pbm > ${top_ppm} + pamcat -tb ${top_ppm} ${bottom_ppm} | \ + pamcut -top=0 -height=${height} | cksum + rm ${top_ppm} ${bottom_ppm} done -# Test 8. Should print 3221289196 73 seventeen times -# Not roundtrip. Padding added to bottom. -echo Test 8. +echo "Test 8. Should print 1346655680 954 281226646 481 five times" +# Padding added to bottom. -pnmpad -bottom=16 -black testgrid.pbm | cksum -for i in `seq 0 15` +pnmpad -bottom=${height} -black maze.pbm | cksum | tr '\n' ' ' +echo ${maze_pbm_sum} +for border in 0 1 10 50 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} + pamcut -top=$((${border}+1)) -height=${height} -pad maze.pbm > ${bottom_ppm} + pamcut -bottom=${border} -height=${height} -pad maze.pbm > ${top_ppm} + pamcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \ + pamcut -top=$((${height}-${border}-1)) -height=$((${height}*2)) | \ + tee ${padded_ppm} | cksum | tr '\n' ' 'cksum + pnmcrop -black -bottom ${padded_ppm} | cksum + rm ${top_ppm} ${bottom_ppm} ${padded_ppm} done - |