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 diff -c $TEMPDIR/pspp.csv - <<EOF
171 x,x0,x1,x2,x3,x4,x5,x6,x7,x8
173 1,9,9,8,10,10,1,1,3,1
174 2,2,2,9,10,10,1,2,3,2
175 3,3,8,9,10,10,1,3,3,3
176 4,4,4,9,10,10,1,2,3,4
177 5,5,7,9,10,10,1,2,3,5
178 6,6,6,9,10,10,6,2,3,6
179 7,7,7,7,10,10,7,2,3,7
180 8,8,8,9,10,10,8,2,3,8
181 9,9,9,1,10,11,9,2,3,9
182 .,.,.,.,11,11,.,.,.,4
185 x,ix0,ix1,ix2,ix3,ix4,ix5,ix6,ix7,ix8
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
199 x,cx0,cx1,cx2,cx3,cx4,cx5,cx6,cx7,cx8,cx9
200 0,0,0,0,0,0,1,0,3,0,22.00
201 1,9,9,8,10,10,1,1,3,1,22.00
202 2,2,2,9,10,10,1,2,3,2,22.00
203 3,3,8,9,10,10,1,3,3,3,22.00
204 4,4,4,9,10,10,1,2,3,4,22.00
205 5,5,7,9,10,10,1,2,3,5,5.00
206 6,6,6,9,10,10,6,2,3,6,22.00
207 7,7,7,7,10,10,7,2,3,7,22.00
208 8,8,8,9,10,10,8,2,3,8,22.00
209 9,9,9,1,10,11,9,2,3,9,22.00
210 .,.,.,.,11,11,.,.,.,4,22.00
213 s,t,s0,s1,s2,s3,t0,t1,t2,t3
215 a ,a ,b ,,xyz ,,b ,,xyz ,b
216 ab ,ab ,bc ,,xyz ,,bc ,,xyz ,
217 abc ,abc ,,,def ,,,,def ,
218 abcd,abcd ,,xyzw,xyz ,,,xyzw ,xyz ,
219 123 ,123 ,,,xyz ,,,,xyz ,
220 123,123 ,,,xyz ,,,,xyz ,
221 +1 ,+1 ,,,xyz ,,,,xyz ,
222 1x ,1x ,,,xyz ,,,,xyz ,
223 abcd,abcdefghi ,,xyzw,xyz ,,,,xyz ,xyz
224 xxx ,abcdefghij,,,xyz ,gone,,,xyz ,jklmnopqr
227 s,t,cs0,cs1,cs2,ct0,ct1,ct2,ct3
229 a ,a ,b ,a ,xyz ,b ,a ,xyz ,b
230 ab ,ab ,bc ,ab ,xyz ,bc ,ab ,xyz ,ab
231 abc ,abc ,abc ,abc ,def ,abc ,abc ,def ,abc
232 abcd,abcd ,abcd,xyzw,xyz ,abcd ,xyzw ,xyz ,abcd
233 123 ,123 ,123 ,123 ,xyz ,123 ,123 ,xyz ,123
234 123,123 ,123,123,xyz ,123 ,123 ,xyz ,123
235 +1 ,+1 ,+1 ,+1 ,xyz ,+1 ,+1 ,xyz ,+1
236 1x ,1x ,1x ,1x ,xyz ,1x ,1x ,xyz ,1x
237 abcd,abcdefghi ,abcd,xyzw,xyz ,abcdefghi ,abcdefghi ,xyz ,xyz
238 xxx ,abcdefghij,xxx ,xxx ,xyz ,abcdefghij,abcdefghij,xyz ,jklmnopqr
241 s,t,ns0,ns1,ns2,nt0,nt1,nt2
245 abc ,abc ,.,.,3,.,.,3
246 abcd,abcd ,1,1,2,1,1,2
247 123 ,123 ,123,123,3,123,123,3
248 123,123 ,123,123,3,123,123,3
251 abcd,abcdefghi ,1,1,2,.,.,3
252 xxx ,abcdefghij,.,.,3,.,.,3
257 1,abcdefghij,xxx ,foobar
259 3,abcdefghij,xxx ,xyz
261 5,abcdefghij,xxx ,xyz
263 7,abcdefghij,xxx ,foobar
265 9,abcdefghij,xxx ,foobar
268 if [ $? -ne 0 ] ; then fail ; fi