about summary refs log tree commit diff
path: root/test/symmetry.test
blob: 5fdb39180c7c9084c38826f31c1c8a7ff830a69d (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
#! /bin/bash
# This script tests: pgmramp pamgauss pgmkernel pbmpscale
# Also requires: pamflip

  alias pgmramp="${PBM_TESTPREFIX}pgmramp"
  alias pamgauss="${PBM_TESTPREFIX}pamgauss"
  alias pgmkernel="${PBM_TESTPREFIX}pgmkernel"
  alias pbmpscale="${PBM_TESTPREFIX}pbmpscale"
  alias pamflip="${PBM_BINPREFIX}pamflip"
  shopt -s expand_aliases

# All tests print "ok" upon success, cksum results otherwise.
# The "$3>0" is a kludge for preventing false positives with empty files.

# All test images are square and have the symmetries of the square (Dih4).
# The sole exception is ell.pgm which is a rectangle (Dih2, also called
# "Klein four-group".)

# Example symmetric square PGM image:
# P2
# 5 5
# 6
# 1 2 3 2 1
# 2 4 5 4 2
# 3 5 6 5 3
# 2 4 5 4 2
# 1 2 3 2 1

## Failure with this test indicates that a generator or editor which
## should produce symmetric output images isn't doing so.

# Test 1.
pgmramp -rect 31 31 > ${tmpdir}/rect.pgm

( for op in -null -tb -lr -r90
    do pamflip $op ${tmpdir}/rect.pgm | cksum
    done ) | uniq -c | \
  awk '$1==4 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/rect.pgm

# Test 2.
pgmramp -ell 63 63 > ${tmpdir}/circle.pgm

( for op in -null -tb -lr -r90
    do pamflip $op ${tmpdir}/circle.pgm | cksum
    done ) | uniq -c | \
  awk '$1==4 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/circle.pgm

# Test 3.
pamgauss -sigma=0.1 -tupletype=GRAYSCALE 25 25 > ${tmpdir}/gauss.pam

( for op in -null -tb -lr -r90
    do pamflip $op ${tmpdir}/gauss.pam | cksum
    done ) | uniq -c | \
  awk '$1==4 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/gauss.pam

# Test 4.
pgmkernel 15 15 > ${tmpdir}/kernel.pgm

( for op in -null -tb -lr -r90
    do pamflip $op ${tmpdir}/kernel.pgm | cksum
    done ) | uniq -c | \
  awk '$1==4 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/kernel.pgm

# Test 5.
# Should print "ok" 7 times.
for size in `seq 1 7`
do
pbmmake -g 5 5 | pbmpscale $size > ${tmpdir}/pscale.pbm

( for op in -null -tb -lr -r90
    do pamflip $op ${tmpdir}/pscale.pbm | cksum
    done ) | uniq -c | \
  awk '$1==4 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/pscale.pbm
done

# Test 6.
pgmramp -ell 101 33 > ${tmpdir}/ell.pgm

( for op in -null -tb -lr
  do pamflip $op ${tmpdir}/ell.pgm | cksum
  done ) | uniq -c | \
  awk '$1==3 && $3>0 { print "ok"; exit }; { print }'

rm ${tmpdir}/ell.pgm