AUTORECODE: Use minimum width output format for new variables.
[pspp] / tests / language / stats / autorecode.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([AUTORECODE procedure])
18
19 AT_SETUP([AUTORECODE multiple missing values])
20 AT_DATA([autorecode.sps],
21   [DATA LIST LIST NOTABLE /u v w x y z (F2.0).
22 BEGIN DATA.
23 11 11 11 11 11 11
24 12 12 12 12 12 12
25 13 13 13 13 13 13
26 14 14 14 14 14 14
27 15 15 15 15 15 15
28 16 16 16 16 16 16
29 END DATA.
30
31 MISSING VALUES u (11)
32                v (11, 12)
33                w (11, 12, 13)
34                x (11 THRU 14)
35                y (11 THRU 15)
36                z (11 THRU 16).
37
38 AUTORECODE u v w x y z INTO a b c d e f.
39 LIST.
40 DISPLAY VARIABLES/VARIABLES=a TO f.
41 ])
42 AT_CHECK([pspp -O format=csv autorecode.sps], [0], [dnl
43 Table: Data List
44 u,v,w,x,y,z,a,b,c,d,e,f
45 11,11,11,11,11,11,6,5,4,3,2,1
46 12,12,12,12,12,12,1,6,5,4,3,2
47 13,13,13,13,13,13,2,1,6,5,4,3
48 14,14,14,14,14,14,3,2,1,6,5,4
49 15,15,15,15,15,15,4,3,2,1,6,5
50 16,16,16,16,16,16,5,4,3,2,1,6
51
52 Table: Variables
53 Name,Position,Print Format,Write Format,Missing Values
54 a,7,F1.0,F1.0,6
55 b,8,F1.0,F1.0,5; 6
56 c,9,F1.0,F1.0,4; 5; 6
57 d,10,F1.0,F1.0,3 THRU 6
58 e,11,F1.0,F1.0,2 THRU 6
59 f,12,F1.0,F1.0,1 THRU 6
60 ])
61 AT_CLEANUP
62
63 AT_SETUP([AUTORECODE numbers and short strings])
64 AT_DATA([autorecode.sps],
65   [data list /X 1-5(a) Y 7.
66 begin data.
67 lasdj 1
68 asdfk 0
69 asdfj 2
70 asdfj 1
71 asdfk 2
72 asdfj 9
73 lajks 9
74 asdfk 0
75 asdfk 1
76 end data.
77
78 missing values x('asdfk') y(9).
79
80 autorecode x y into A B/descend.
81
82 list.
83 compute Z=trunc(y/2).
84 formats z(F1.0).
85 autorecode z into W.
86 list.
87 ])
88 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
89   [Table: Reading 1 record from INLINE.
90 Variable,Record,Columns,Format
91 X,1,1-  5,A5
92 Y,1,7-  7,F1.0
93
94 Table: Data List
95 X,Y,A,B
96 lasdj,1,1,2
97 asdfk,0,4,3
98 asdfj,2,3,1
99 asdfj,1,3,2
100 asdfk,2,4,1
101 asdfj,9,3,4
102 lajks,9,2,4
103 asdfk,0,4,3
104 asdfk,1,4,2
105
106 Table: Data List
107 X,Y,A,B,Z,W
108 lasdj,1,1,2,0,1
109 asdfk,0,4,3,0,1
110 asdfj,2,3,1,1,2
111 asdfj,1,3,2,0,1
112 asdfk,2,4,1,1,2
113 asdfj,9,3,4,.,.
114 lajks,9,2,4,.,.
115 asdfk,0,4,3,0,1
116 asdfk,1,4,2,0,1
117 ])
118 AT_CLEANUP
119
120
121
122 AT_SETUP([AUTORECODE long strings and check the value labels])
123 AT_DATA([ar.sps],
124   [data list notable list /s (a16) x (f1.0).
125 begin data.
126 widgets      1
127 thingummies  2
128 oojars       3
129 widgets      4
130 oojars       5
131 thingummies  6
132 oojimiflips  7
133 end data.
134
135 variable labels s 'tracking my stuff'.
136 value labels /s 'thingummies' 'Funny sticky things'.
137
138 autorecode s into new.
139
140 list.
141
142 display dictionary/variables=new.
143 ])
144
145 AT_CHECK([pspp -O format=csv ar.sps], [0],
146   [Table: Data List
147 s,x,new
148 widgets,1,4
149 thingummies,2,3
150 oojars,3,1
151 widgets,4,4
152 oojars,5,1
153 thingummies,6,3
154 oojimiflips,7,2
155
156 Table: Variables
157 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
158 new,3,tracking my stuff,Scale,Input,8,Right,F1.0,F1.0,
159
160 Table: Value Labels
161 Variable Value,,Label
162 tracking my stuff,1,oojars
163 ,2,oojimiflips
164 ,3,Funny sticky things
165 ,4,widgets
166 ])
167
168 AT_CLEANUP
169
170
171 AT_SETUP([AUTORECODE group subcommand])
172 AT_DATA([ar-group.sps],
173 [data list notable list /x y (f8.0).
174 begin data.
175 11 10
176 12 12 
177 13 15
178 14 11
179 15 12
180 16 18
181 end data.
182
183 missing values y (12).
184
185 autorecode 
186         x y into a b
187         /group.
188
189 list.
190 display variables /variables=a b.
191 ])
192
193 AT_CHECK([pspp -O format=csv ar-group.sps], [0],
194 [Table: Data List
195 x,y,a,b
196 11,10,2,1
197 12,12,8,8
198 13,15,3,5
199 14,11,4,2
200 15,12,5,8
201 16,18,6,7
202
203 Table: Variables
204 Name,Position,Print Format,Write Format,Missing Values
205 a,3,F1.0,F1.0,8
206 b,4,F1.0,F1.0,8
207 ])
208
209 AT_CLEANUP
210
211
212
213 AT_SETUP([AUTORECODE group - string variables])
214 AT_DATA([strings.sps],
215 [data list notable list /x (a8) y (a16).
216 begin data.
217 fred bert
218 charlie "         "
219 delta echo
220 "      " windows
221 " "  nothing
222 end data.
223
224
225 autorecode x y into a b
226         /group.
227
228 delete variables x y.
229
230 list.
231
232 ])
233
234 AT_CHECK([pspp -O format=csv strings.sps], [0],
235 [Table: Data List
236 a,b
237 6,2
238 3,1
239 4,5
240 1,8
241 1,7
242 ])
243
244 AT_CLEANUP
245
246
247 dnl Tests for a crash which happened when the /GROUP subcommand
248 dnl appeared with string variables of different widths.
249 AT_SETUP([AUTORECODE group vs. strings])
250 AT_DATA([ar-strings.sps],
251   [data list notable list /a (a12) b (a6).
252 begin data.
253 one    nine
254 two    ten
255 three  eleven 
256 four   nought
257 end data.
258
259 autorecode a b into x y 
260         /group.
261
262 list.
263 ])
264
265 AT_CHECK([pspp -O format=csv ar-strings.sps], [0],
266 [dnl
267 Table: Data List
268 a,b,x,y
269 one,nine,5,3
270 two,ten,8,6
271 three,eleven,7,1
272 four,nought,2,4
273 ])
274
275 AT_CLEANUP
276
277
278
279 AT_SETUP([AUTORECODE /blank])
280
281 AT_DATA([auto-blank.sps],  [dnl
282 data list notable list /x (a8) y (f8.0) z (a16).
283 begin data.
284 one   2  fred
285 two   4  ""
286 ""    4  fred
287 ""    2  charliebrown
288 three 2  charliebrown
289 end data.
290
291 autorecode variables x y z into a b c  /blank=missing.
292
293 list a b c y.
294 ])
295
296 AT_CHECK([pspp -O format=csv auto-blank.sps], [0], [dnl
297 Table: Data List
298 a,b,c,y
299 1,1,2,2
300 3,2,.,4
301 .,2,2,4
302 .,1,1,2
303 2,1,1,2
304 ])
305
306 AT_CLEANUP
307
308 dnl AUTORECODE had a use-after-free error when TEMPORARY was in use.
309 dnl Bug #32757.
310 AT_SETUP([AUTORECODE with TEMPORARY])
311 AT_DATA([autorecode.sps],
312   [data list /X 1-5(a) Y 7.
313 begin data.
314 lasdj 1
315 asdfk 0
316 asdfj 2
317 asdfj 1
318 asdfk 2
319 asdfj 9
320 lajks 9
321 asdfk 0
322 asdfk 1
323 end data.
324
325 temporary.
326 select if y > 1.
327 autorecode x y into A B/descend.
328 list.
329 ])
330 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
331   [Table: Reading 1 record from INLINE.
332 Variable,Record,Columns,Format
333 X,1,1-  5,A5
334 Y,1,7-  7,F1.0
335
336 Table: Data List
337 X,Y,A,B
338 lasdj,1,.,.
339 asdfk,0,2,.
340 asdfj,2,3,2
341 asdfj,1,3,.
342 asdfk,2,2,2
343 asdfj,9,3,1
344 lajks,9,1,1
345 asdfk,0,2,.
346 asdfk,1,2,.
347 ])
348 AT_CLEANUP
349
350
351 dnl For compatibility, make sure that /INTO (with leading slash) is accepted
352 dnl (bug #48762)
353 AT_SETUP([AUTORECODE with /INTO])
354 AT_DATA([autorecode.sps],
355   [data list list notable /x (f8.0).
356 begin data.
357 1
358 8
359 -901
360 4
361 1
362 99
363 8
364 end data.
365
366 autorecode x  /into y.
367
368 list.
369 ])
370 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
371 [Table: Data List
372 x,y
373 1,2
374 8,4
375 -901,1
376 4,3
377 1,2
378 99,5
379 8,4
380 ])
381 AT_CLEANUP