about summary refs log tree commit diff
path: root/test/cut-cat-roundtrip.test
blob: 970c3e17b46204d7a4070f57d09002fa421aca59 (plain) (blame)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /bin/bash
# This script tests: pamcut
# Also requires: pamfile pnmcat pnmpad pnmcrop

tmpdir=${tmpdir:-/tmp}

left_ppm=${tmpdir}/left.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=`cat testimg.ppm | cksum`
echo ${testimg_ppm_sum}

 imgsize=$(pamfile -size testimg.ppm)
 iw=$(echo ${imgsize} | cut -d" " -f1)
 ih=$(echo ${imgsize} | cut -d" " -f2)

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=${iw} | cksum
  rm ${left_ppm} ${right_ppm}
  done

echo "Test 2.  Should print 3891261972 202953 1926073387 101484 six times"
# Padding added to right.

pnmpad -right=${iw} -black testimg.ppm | cksum | tr '\n' ' '
echo ${testimg_ppm_sum}

for border in 0 1 128 224 225
  do
  pamcut -left=$((${border}+1)) -width=${iw} -pad testimg.ppm > ${right_ppm}
  pamcut -right=${border} -width=${iw} -pad testimg.ppm > ${left_ppm}
  pnmcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \
    pamcut -left=$((${iw}-${border}-1))  -width=$((${iw}*2)) | \
    tee ${padded_ppm} | cksum | tr '\n' ' '
  pnmcrop -black -right ${padded_ppm} | cksum
  rm ${left_ppm} ${right_ppm} ${padded_ppm}
  done


echo "Test 3.  Should print 1926073387 101484 five times"

echo ${testimg_ppm_sum}
for border in 0 1 70 147
  do
  pamcut -top=$((${border}+1)) testimg.ppm > ${bottom_ppm}
  pamcut -bottom=${border}     testimg.ppm > ${top_ppm}
  pnmcat -tb ${top_ppm} ${bottom_ppm} | \
    pamcut -top=0 -height=${ih} | cksum
  rm ${top_ppm} ${bottom_ppm}
  done

echo "Test 4.  Should print 26789469 202953 1926073387 101484 five times"
# Padding added to bottom.

pnmpad -bottom=${ih} -black testimg.ppm | cksum | tr '\n' ' '
echo ${testimg_ppm_sum}
for border in 0 1 70 147
  do
  pamcut -top=$((${border}+1)) -height=${ih} -pad testimg.ppm > ${bottom_ppm}
  pamcut -bottom=${border}     -height=${ih} -pad testimg.ppm > ${top_ppm}
  pnmcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \
    pamcut -top=$((${ih}-${border}-1))  -height=$((${ih}*2)) | \
    tee ${padded_ppm} | cksum | tr '\n' ' 'cksum
  pnmcrop -black -bottom ${padded_ppm} | cksum
  rm ${top_ppm} ${bottom_ppm} ${padded_ppm}
  done

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=`cat maze.pbm | cksum`
echo ${maze_pbm_sum}

imgsize=$(pamfile -size maze.pbm)
iw=$(echo ${imgsize} | cut -d" " -f1)
ih=$(echo ${imgsize} | cut -d" " -f2)

for i in 0 1 10 30 50
  do
  pamcut -left=$((i+1)) maze.pbm > ${right_ppm}
  pamcut -right=$i      maze.pbm > ${left_ppm}
  pnmcat -lr ${left_ppm} ${right_ppm} | \
    pamcut -left=0 -width=${iw} | cksum
  rm ${left_ppm} ${right_ppm}
  done


echo "Test 6.  Should print 1748767123 895 281226646 481 six times"
# Padding added to right.

pnmpad -right=${iw} -black maze.pbm | cksum | tr '\n' ' '
echo ${maze_pbm_sum}

for border in 0 1 10 30 50
  do
  pamcut -left=$((${border}+1)) -width=${iw} -pad maze.pbm > ${right_ppm}
  pamcut -right=${border} -width=${iw} -pad maze.pbm > ${left_ppm}
  pnmcat -lr ${left_ppm} ${right_ppm} ${left_ppm} | \
    pamcut -left=$((${iw}-${border}-1))  -width=$((${iw}*2)) | \
    tee ${padded_ppm} | cksum | tr '\n' ' '
  pnmcrop -black -right ${padded_ppm} | cksum
  rm ${left_ppm} ${right_ppm} ${padded_ppm}
  done


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=$((${border}+1)) maze.pbm > ${bottom_ppm}
  pamcut -bottom=${border}     maze.pbm > ${top_ppm}
  pnmcat -tb ${top_ppm} ${bottom_ppm} | \
    pamcut -top=0 -height=${ih} | cksum
  rm ${top_ppm} ${bottom_ppm}
  done

echo "Test 8.  Should print 1346655680 954 281226646 481 five times"
# Padding added to bottom.

pnmpad -bottom=${ih} -black maze.pbm | cksum | tr '\n' ' '
echo ${maze_pbm_sum}
for border in 0 1 10 50
  do
  pamcut -top=$((${border}+1)) -height=${ih} -pad maze.pbm > ${bottom_ppm}
  pamcut -bottom=${border}     -height=${ih} -pad maze.pbm > ${top_ppm}
  pnmcat -tb ${top_ppm} ${bottom_ppm} ${top_ppm} | \
    pamcut -top=$((${ih}-${border}-1))  -height=$((${ih}*2)) | \
    tee ${padded_ppm} | cksum | tr '\n' ' 'cksum
  pnmcrop -black -bottom ${padded_ppm} | cksum
  rm ${top_ppm} ${bottom_ppm} ${padded_ppm}
  done