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
26 if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then
27 echo "NOT cleaning $TEMPDIR"
62 activity="create program"
64 DATA LIST LIST NOTABLE/x (f1) s (a4) t (a10).
65 MISSING VALUES x(9)/s('xxx').
80 * Numeric to numeric, without INTO.
81 NUMERIC x0 TO x8 (F3).
82 MISSING VALUES x0 to x8 (9).
86 RECODE x1 (1=9)(3=8)(5=7).
88 RECODE x2 (1=8)(2,3,4,5,6,8=9)(9=1).
90 RECODE x3 (1 THRU 9=10)(MISSING=11).
92 RECODE x4 (MISSING=11)(1 THRU 9=10).
94 RECODE x5 (LOWEST THRU 5=1).
96 RECODE x6 (4 THRU HIGHEST=2).
98 RECODE x7 (LO THRU HI=3).
100 RECODE x8 (SYSMIS=4).
103 * Numeric to numeric, with INTO, without COPY.
104 NUMERIC ix0 TO ix8 (F3).
105 RECODE x (1=9) INTO ix0.
106 RECODE x (1=9)(3=8)(5=7) INTO ix1.
107 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1) INTO ix2.
108 RECODE x (1 THRU 9=10)(MISSING=11) INTO ix3.
109 RECODE x (MISSING=11)(1 THRU 9=10) INTO ix4.
110 RECODE x (LOWEST THRU 5=1) INTO ix5.
111 RECODE x (4 THRU HIGHEST=2) INTO ix6.
112 RECODE x (LO THRU HI=3) INTO ix7.
113 RECODE x (SYSMIS=4) INTO ix8.
116 * Numeric to numeric, with INTO, with COPY.
117 NUMERIC cx0 TO cx8 (F3).
118 RECODE x (1=9)(ELSE=COPY) INTO cx0.
119 RECODE x (1=9)(3=8)(5=7)(ELSE=COPY) INTO cx1.
120 RECODE x (1=8)(2,3,4,5,6,8=9)(9=1)(ELSE=COPY) INTO cx2.
121 RECODE x (1 THRU 9=10)(MISSING=11)(ELSE=COPY) INTO cx3.
122 RECODE x (MISSING=11)(1 THRU 9=10)(ELSE=COPY) INTO cx4.
123 RECODE x (LOWEST THRU 5=1)(ELSE=COPY) INTO cx5.
124 RECODE x (4 THRU HIGHEST=2)(ELSE=COPY) INTO cx6.
125 RECODE x (LO THRU HI=3)(ELSE=COPY) INTO cx7.
126 RECODE x (SYSMIS=4)(ELSE=COPY) INTO cx8.
127 RECODE x (5=COPY)(ELSE=22) INTO cx9.
130 * String to string, with INTO, without COPY.
131 STRING s0 TO s3 (A4)/t0 TO t3 (A10).
132 RECODE s t ('a'='b')('ab'='bc') INTO s0 t0.
133 RECODE s t ('abcd'='xyzw') INTO s1 t1.
134 RECODE s t ('abc'='def')(ELSE='xyz') INTO s2 t2.
135 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr') INTO t3.
136 RECODE s (MISSING='gone') INTO s3.
137 LIST s t s0 TO s3 t0 TO t3.
139 * String to string, with INTO, with COPY.
140 STRING cs0 TO cs2 (A4)/ct0 TO ct3 (A10).
141 RECODE s t ('a'='b')('ab'='bc')(ELSE=COPY) INTO cs0 ct0.
142 RECODE s t ('abcd'='xyzw')(ELSE=COPY) INTO cs1 ct1.
143 RECODE s t ('abc'='def')(ELSE='xyz')(ELSE=COPY) INTO cs2 ct2.
144 RECODE t ('a'='b')('abcdefghi'='xyz')('abcdefghij'='jklmnopqr')(ELSE=COPY)
146 LIST s t cs0 TO cs2 ct0 TO ct3.
149 NUMERIC ns0 TO ns2 (F3)/nt0 TO nt2 (F3).
150 RECODE s t (CONVERT)(' '=0)('abcd'=1) INTO ns0 nt0.
151 RECODE s t (' '=0)(CONVERT)('abcd'=1) INTO ns1 nt1.
152 RECODE s t ('1x'=1)('abcd'=2)(ELSE=3) INTO ns2 nt2.
153 LIST s t ns0 TO ns2 nt0 TO nt2.
156 STRING sx0 TO sx2 (a10).
157 RECODE x (1 THRU 9='abcdefghij') INTO sx0.
158 RECODE x (0,1,3,5,7,MISSING='xxx') INTO sx1.
159 RECODE x (2 THRU 6,SYSMIS='xyz')(ELSE='foobar') INTO sx2.
162 if [ $? -ne 0 ] ; then no_result ; fi
164 activity="run program"
165 $SUPERVISOR $PSPP --testing-mode $TESTFILE
166 if [ $? -ne 0 ] ; then no_result ; fi
168 activity="test output"
169 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
170 diff -bu $TEMPDIR/pspp.list - <<EOF
171 x x0 x1 x2 x3 x4 x5 x6 x7 x8
172 - --- --- --- --- --- --- --- --- ---
174 1 9 9 8 10 10 1 1 3 1
175 2 2 2 9 10 10 1 2 3 2
176 3 3 8 9 10 10 1 3 3 3
177 4 4 4 9 10 10 1 2 3 4
178 5 5 7 9 10 10 1 2 3 5
179 6 6 6 9 10 10 6 2 3 6
180 7 7 7 7 10 10 7 2 3 7
181 8 8 8 9 10 10 8 2 3 8
182 9 9 9 1 10 11 9 2 3 9
183 . . . . 11 11 . . . 4
184 x ix0 ix1 ix2 ix3 ix4 ix5 ix6 ix7 ix8
185 - --- --- --- --- --- --- --- --- ---
187 1 9 9 8 10 10 1 . 3 .
188 2 . . 9 10 10 1 . 3 .
189 3 . 8 9 10 10 1 . 3 .
190 4 . . 9 10 10 1 2 3 .
191 5 . 7 9 10 10 1 2 3 .
192 6 . . 9 10 10 . 2 3 .
193 7 . . . 10 10 . 2 3 .
194 8 . . 9 10 10 . 2 3 .
195 9 . . 1 10 11 . 2 3 .
196 . . . . 11 11 . . . 4
197 x cx0 cx1 cx2 cx3 cx4 cx5 cx6 cx7 cx8 cx9
198 - --- --- --- --- --- --- --- --- --- --------
199 0 0 0 0 0 0 1 0 3 0 22.00
200 1 9 9 8 10 10 1 1 3 1 22.00
201 2 2 2 9 10 10 1 2 3 2 22.00
202 3 3 8 9 10 10 1 3 3 3 22.00
203 4 4 4 9 10 10 1 2 3 4 22.00
204 5 5 7 9 10 10 1 2 3 5 5.00
205 6 6 6 9 10 10 6 2 3 6 22.00
206 7 7 7 7 10 10 7 2 3 7 22.00
207 8 8 8 9 10 10 8 2 3 8 22.00
208 9 9 9 1 10 11 9 2 3 9 22.00
209 . . . . 11 11 . . . 4 22.00
210 s t s0 s1 s2 s3 t0 t1 t2 t3
211 ---- ---------- ---- ---- ---- ---- ---------- ---------- ---------- ----------
216 abcd abcd xyzw xyz xyzw xyz
221 abcd abcdefghi xyzw xyz xyz xyz
222 xxx abcdefghij xyz gone xyz jklmnopqr
223 s t cs0 cs1 cs2 ct0 ct1 ct2 ct3
224 ---- ---------- ---- ---- ---- ---------- ---------- ---------- ----------
226 a a b a xyz b a xyz b
227 ab ab bc ab xyz bc ab xyz ab
228 abc abc abc abc def abc abc def abc
229 abcd abcd abcd xyzw xyz abcd xyzw xyz abcd
230 123 123 123 123 xyz 123 123 xyz 123
231 123 123 123 123 xyz 123 123 xyz 123
232 +1 +1 +1 +1 xyz +1 +1 xyz +1
233 1x 1x 1x 1x xyz 1x 1x xyz 1x
234 abcd abcdefghi abcd xyzw xyz abcdefghi abcdefghi xyz xyz
235 xxx abcdefghij xxx xxx xyz abcdefghij abcdefghij xyz jklmnopqr
236 s t ns0 ns1 ns2 nt0 nt1 nt2
237 ---- ---------- --- --- --- --- --- ---
242 abcd abcd 1 1 2 1 1 2
243 123 123 123 123 3 123 123 3
244 123 123 123 123 3 123 123 3
247 abcd abcdefghi 1 1 2 . . 3
248 xxx abcdefghij . . 3 . . 3
250 - ---------- ---------- ----------
252 1 abcdefghij xxx foobar
258 7 abcdefghij xxx foobar
260 9 abcdefghij xxx foobar
263 if [ $? -ne 0 ] ; then fail ; fi