3 # This program tests the RECODE command
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
9 # ensure that top_builddir are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
18 STAT_CONFIG_PATH=$top_srcdir/config
19 export STAT_CONFIG_PATH
58 activity="create program"
60 DATA LIST LIST NOTABLE/x (f1) s (a4) t (a10).
61 MISSING VALUES x(9)/s('xxx').
76 * Numeric to numeric, without INTO.
77 NUMERIC x0 TO x8 (F3).
78 MISSING VALUES x0 to x8 (9).
82 RECODE x1 (1=9)(3=8)(5=7).
84 RECODE x2 (1=8)(2,3,4,5,6,8=9)(9=1).
86 RECODE x3 (1 THRU 9=10)(MISSING=11).
88 RECODE x4 (MISSING=11)(1 THRU 9=10).
90 RECODE x5 (LOWEST THRU 5=1).
92 RECODE x6 (4 THRU HIGHEST=2).
94 RECODE x7 (LO THRU HI=3).
99 * Numeric to numeric, with INTO, without COPY.
100 NUMERIC ix0 TO ix8 (F3).
101 RECODE x (1=9) INTO ix0.
102 RECODE x (1=9)(3=8)(5=7) INTO ix1.
103 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1) INTO ix2.
104 RECODE x (1 THRU 9=10)(MISSING=11) INTO ix3.
105 RECODE x (MISSING=11)(1 THRU 9=10) INTO ix4.
106 RECODE x (LOWEST THRU 5=1) INTO ix5.
107 RECODE x (4 THRU HIGHEST=2) INTO ix6.
108 RECODE x (LO THRU HI=3) INTO ix7.
109 RECODE x (SYSMIS=4) INTO ix8.
112 * Numeric to numeric, with INTO, with COPY.
113 NUMERIC cx0 TO cx8 (F3).
114 RECODE x (1=9)(ELSE=COPY) INTO cx0.
115 RECODE x (1=9)(3=8)(5=7)(ELSE=COPY) INTO cx1.
116 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1)(ELSE=COPY) INTO cx2.
117 RECODE x (1 THRU 9=10)(MISSING=11)(ELSE=COPY) INTO cx3.
118 RECODE x (MISSING=11)(1 THRU 9=10)(ELSE=COPY) INTO cx4.
119 RECODE x (LOWEST THRU 5=1)(ELSE=COPY) INTO cx5.
120 RECODE x (4 THRU HIGHEST=2)(ELSE=COPY) INTO cx6.
121 RECODE x (LO THRU HI=3)(ELSE=COPY) INTO cx7.
122 RECODE x (SYSMIS=4)(ELSE=COPY) INTO cx8.
125 * String to string, with INTO, without COPY.
126 STRING s0 TO s2 (A4)/t0 TO t3 (A10).
127 RECODE s t ('a'='b')('ab'='bc') INTO s0 t0.
128 RECODE s t ('abcd'='xyzw') INTO s1 t1.
129 RECODE s t ('abc'='def')(ELSE='xyz') INTO s2 t2.
130 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr') INTO t3.
131 LIST s t s0 TO s2 t0 TO t3.
133 * String to string, with INTO, with COPY.
134 STRING cs0 TO cs2 (A4)/ct0 TO ct3 (A10).
135 RECODE s t ('a'='b')('ab'='bc')(ELSE=COPY) INTO cs0 ct0.
136 RECODE s t ('abcd'='xyzw')(ELSE=COPY) INTO cs1 ct1.
137 RECODE s t ('abc'='def')(ELSE='xyz')(ELSE=COPY) INTO cs2 ct2.
138 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr')(ELSE=COPY)
140 LIST s t cs0 TO cs2 ct0 TO ct3.
143 NUMERIC ns0 TO ns2 (F3)/nt0 TO nt2 (F3).
144 RECODE s t (CONVERT)(' '=0)('abcd'=1) INTO ns0 nt0.
145 RECODE s t (' '=0)(CONVERT)('abcd'=1) INTO ns1 nt1.
146 RECODE s t ('1x'=1)('abcd'=2)(ELSE=3) INTO ns2 nt2.
147 LIST s t ns0 TO ns2 nt0 TO nt2.
150 STRING sx0 TO sx2 (a10).
151 RECODE x (1 THRU 9='abcdefghij') INTO sx0.
152 RECODE x (0,1,3,5,7,MISSING='xxx') INTO sx1.
153 RECODE x (2 THRU 6,SYSMIS='xyz')(ELSE='foobar') INTO sx2.
156 if [ $? -ne 0 ] ; then no_result ; fi
158 activity="run program"
159 $SUPERVISOR $PSPP --testing-mode $TESTFILE
160 if [ $? -ne 0 ] ; then no_result ; fi
162 activity="test output"
163 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
164 diff -bu $TEMPDIR/pspp.list - <<EOF
165 x x0 x1 x2 x3 x4 x5 x6 x7 x8
166 - --- --- --- --- --- --- --- --- ---
168 1 9 9 8 10 10 1 1 3 1
169 2 2 2 9 10 10 1 2 3 2
170 3 3 8 9 10 10 1 3 3 3
171 4 4 4 9 10 10 1 2 3 4
172 5 5 7 9 10 10 1 2 3 5
173 6 6 6 9 10 10 6 2 3 6
174 7 7 7 7 10 10 7 2 3 7
175 8 8 8 9 10 10 8 2 3 8
176 9 9 9 1 10 11 9 2 3 9
177 . . . . 11 11 . . . 4
178 x ix0 ix1 ix2 ix3 ix4 ix5 ix6 ix7 ix8
179 - --- --- --- --- --- --- --- --- ---
181 1 9 9 8 10 10 1 . 3 .
182 2 . . 9 10 10 1 . 3 .
183 3 . 8 9 10 10 1 . 3 .
184 4 . . 9 10 10 1 2 3 .
185 5 . 7 9 10 10 1 2 3 .
186 6 . . 9 10 10 . 2 3 .
187 7 . . . 10 10 . 2 3 .
188 8 . . 9 10 10 . 2 3 .
189 9 . . 1 10 11 . 2 3 .
190 . . . . 11 11 . . . 4
191 x cx0 cx1 cx2 cx3 cx4 cx5 cx6 cx7 cx8
192 - --- --- --- --- --- --- --- --- ---
194 1 9 9 8 10 10 1 1 3 1
195 2 2 2 9 10 10 1 2 3 2
196 3 3 8 9 10 10 1 3 3 3
197 4 4 4 9 10 10 1 2 3 4
198 5 5 7 9 10 10 1 2 3 5
199 6 6 6 9 10 10 6 2 3 6
200 7 7 7 7 10 10 7 2 3 7
201 8 8 8 9 10 10 8 2 3 8
202 9 9 9 1 10 11 9 2 3 9
203 . . . . 11 11 . . . 4
204 s t s0 s1 s2 t0 t1 t2 t3
205 ---- ---------- ---- ---- ---- ---------- ---------- ---------- ----------
210 abcd abcd xyzw xyz xyzw xyz
215 abcd abcdefghi xyzw xyz xyz xyz
216 xxx abcdefghij xyz xyz jklmnopqr
217 s t cs0 cs1 cs2 ct0 ct1 ct2 ct3
218 ---- ---------- ---- ---- ---- ---------- ---------- ---------- ----------
220 a a b a xyz b a xyz b
221 ab ab bc ab xyz bc ab xyz ab
222 abc abc abc abc def abc abc def abc
223 abcd abcd abcd xyzw xyz abcd xyzw xyz abcd
224 123 123 123 123 xyz 123 123 xyz 123
225 123 123 123 123 xyz 123 123 xyz 123
226 +1 +1 +1 +1 xyz +1 +1 xyz +1
227 1x 1x 1x 1x xyz 1x 1x xyz 1x
228 abcd abcdefghi abcd xyzw xyz abcdefghi abcdefghi xyz xyz
229 xxx abcdefghij xxx xxx xyz abcdefghij abcdefghij xyz jklmnopqr
230 s t ns0 ns1 ns2 nt0 nt1 nt2
231 ---- ---------- --- --- --- --- --- ---
236 abcd abcd 1 1 2 1 1 2
237 123 123 123 123 3 123 123 3
238 123 123 123 123 3 123 123 3
241 abcd abcdefghi 1 1 2 . . 3
242 xxx abcdefghij . . 3 . . 3
244 - ---------- ---------- ----------
246 1 abcdefghij xxx foobar
252 7 abcdefghij xxx foobar
254 9 abcdefghij xxx foobar
258 if [ $? -ne 0 ] ; then fail ; fi