it works!!
[pspp] / tests / language / commands / 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/print.
39 LIST.
40 DISPLAY VARIABLES/VARIABLES=a TO f.
41 ])
42 AT_CHECK([pspp -O format=csv autorecode.sps], [0], [dnl
43 Table: Recoding u into a.
44 Old Value,New Value,Value Label
45 12,1,12
46 13,2,13
47 14,3,14
48 15,4,15
49 16,5,16
50 11,6,11
51
52 Table: Recoding v into b.
53 Old Value,New Value,Value Label
54 13,1,13
55 14,2,14
56 15,3,15
57 16,4,16
58 11,5,11
59 12,6,12
60
61 Table: Recoding w into c.
62 Old Value,New Value,Value Label
63 14,1,14
64 15,2,15
65 16,3,16
66 11,4,11
67 12,5,12
68 13,6,13
69
70 Table: Recoding x into d.
71 Old Value,New Value,Value Label
72 15,1,15
73 16,2,16
74 11,3,11
75 12,4,12
76 13,5,13
77 14,6,14
78
79 Table: Recoding y into e.
80 Old Value,New Value,Value Label
81 16,1,16
82 11,2,11
83 12,3,12
84 13,4,13
85 14,5,14
86 15,6,15
87
88 Table: Recoding z into f.
89 Old Value,New Value,Value Label
90 11,1,11
91 12,2,12
92 13,3,13
93 14,4,14
94 15,5,15
95 16,6,16
96
97 Table: Data List
98 u,v,w,x,y,z,a,b,c,d,e,f
99 11,11,11,11,11,11,6,5,4,3,2,1
100 12,12,12,12,12,12,1,6,5,4,3,2
101 13,13,13,13,13,13,2,1,6,5,4,3
102 14,14,14,14,14,14,3,2,1,6,5,4
103 15,15,15,15,15,15,4,3,2,1,6,5
104 16,16,16,16,16,16,5,4,3,2,1,6
105
106 Table: Variables
107 Name,Position,Print Format,Write Format,Missing Values
108 a,7,F1.0,F1.0,6
109 b,8,F1.0,F1.0,5; 6
110 c,9,F1.0,F1.0,4; 5; 6
111 d,10,F1.0,F1.0,3 THRU 6
112 e,11,F1.0,F1.0,2 THRU 6
113 f,12,F1.0,F1.0,1 THRU 6
114 ])
115 AT_CLEANUP
116
117 AT_SETUP([AUTORECODE numbers and short strings])
118 AT_DATA([autorecode.sps],
119   [data list /X 1-5(a) Y 7.
120 begin data.
121 lasdj 1
122 asdfk 0
123 asdfj 2
124 asdfj 1
125 asdfk 2
126 asdfj 9
127 lajks 9
128 asdfk 0
129 asdfk 1
130 end data.
131
132 missing values x('asdfk') y(9).
133
134 autorecode x y into A B/descend/print.
135
136 list.
137 compute Z=trunc(y/2).
138 formats z(F1.0).
139 autorecode z into W.
140 list.
141 ])
142 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
143   [Table: Reading 1 record from INLINE.
144 Variable,Record,Columns,Format
145 X,1,1-5,A5
146 Y,1,7-7,F1.0
147
148 Table: Recoding X into A.
149 Old Value,New Value,Value Label
150 lasdj,1,lasdj
151 lajks,2,lajks
152 asdfj,3,asdfj
153 asdfk,4,asdfk
154
155 Table: Recoding Y into B.
156 Old Value,New Value,Value Label
157 2,1,2
158 1,2,1
159 0,3,0
160 9,4,9
161
162 Table: Data List
163 X,Y,A,B
164 lasdj,1,1,2
165 asdfk,0,4,3
166 asdfj,2,3,1
167 asdfj,1,3,2
168 asdfk,2,4,1
169 asdfj,9,3,4
170 lajks,9,2,4
171 asdfk,0,4,3
172 asdfk,1,4,2
173
174 Table: Data List
175 X,Y,A,B,Z,W
176 lasdj,1,1,2,0,1
177 asdfk,0,4,3,0,1
178 asdfj,2,3,1,1,2
179 asdfj,1,3,2,0,1
180 asdfk,2,4,1,1,2
181 asdfj,9,3,4,.,.
182 lajks,9,2,4,.,.
183 asdfk,0,4,3,0,1
184 asdfk,1,4,2,0,1
185 ])
186 AT_CLEANUP
187
188 AT_SETUP([AUTORECODE long strings and check the value labels])
189 AT_DATA([ar.sps],
190   [data list notable list /s (a16) x (f1.0).
191 begin data.
192 widgets      1
193 thingummies  2
194 oojars       3
195 widgets      4
196 oojars       5
197 thingummies  6
198 oojimiflips  7
199 end data.
200
201 variable labels s 'tracking my stuff'.
202 value labels /s 'thingummies' 'Funny sticky things'.
203
204 autorecode s into new/print.
205
206 list.
207
208 display dictionary/variables=new.
209 ])
210
211 AT_CHECK([pspp -O format=csv ar.sps], [0],
212   [Table: Recoding s into new (tracking my stuff).
213 Old Value,New Value,Value Label
214 oojars,1,oojars
215 oojimiflips,2,oojimiflips
216 thingummies,3,Funny sticky things
217 widgets,4,widgets
218
219 Table: Data List
220 s,x,new
221 widgets,1,4
222 thingummies,2,3
223 oojars,3,1
224 widgets,4,4
225 oojars,5,1
226 thingummies,6,3
227 oojimiflips,7,2
228
229 Table: Variables
230 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format
231 new,3,tracking my stuff,Nominal,Input,8,Right,F1.0,F1.0
232
233 Table: Value Labels
234 Variable Value,,Label
235 tracking my stuff,1,oojars
236 ,2,oojimiflips
237 ,3,Funny sticky things
238 ,4,widgets
239 ])
240
241 AT_CLEANUP
242
243
244 AT_SETUP([AUTORECODE group subcommand])
245 AT_DATA([ar-group.sps],
246 [data list notable list /x y (f8.0).
247 begin data.
248 11 10
249 12 12
250 13 15
251 14 11
252 15 12
253 16 18
254 end data.
255
256 missing values y (12).
257
258 autorecode
259         x y into a b
260         /group
261         /print.
262
263 list.
264 display variables /variables=a b.
265 ])
266
267 AT_CHECK([pspp -O format=csv ar-group.sps], [0],
268 [Table: Recoding grouped variables.
269 Old Value,New Value,Value Label
270 10,1,10
271 11,2,11
272 13,3,13
273 14,4,14
274 15,5,15
275 16,6,16
276 18,7,18
277 12,8,12
278
279 Table: Data List
280 x,y,a,b
281 11,10,2,1
282 12,12,8,8
283 13,15,3,5
284 14,11,4,2
285 15,12,5,8
286 16,18,6,7
287
288 Table: Variables
289 Name,Position,Print Format,Write Format,Missing Values
290 a,3,F1.0,F1.0,8
291 b,4,F1.0,F1.0,8
292 ])
293
294 AT_CLEANUP
295
296
297
298 AT_SETUP([AUTORECODE group - string variables])
299 AT_DATA([strings.sps],
300 [data list notable list /x (a8) y (a16).
301 begin data.
302 fred bert
303 charlie "         "
304 delta echo
305 "      " windows
306 " "  nothing
307 end data.
308
309
310 autorecode x y into a b
311         /group
312         /print.
313
314 delete variables x y.
315
316 list.
317 ])
318
319 AT_CHECK([pspp -O format=csv strings.sps], [0],
320 [Table: Recoding grouped variables.
321 Old Value,New Value,Value Label
322 ,1,
323 bert,2,bert
324 charlie,3,charlie
325 delta,4,delta
326 echo,5,echo
327 fred,6,fred
328 nothing,7,nothing
329 windows,8,windows
330
331 Table: Data List
332 a,b
333 6,2
334 3,1
335 4,5
336 1,8
337 1,7
338 ])
339
340 AT_CLEANUP
341
342
343 dnl Tests for a crash which happened when the /GROUP subcommand
344 dnl appeared with string variables of different widths.
345 AT_SETUP([AUTORECODE group vs. strings])
346 AT_DATA([ar-strings.sps],
347   [data list notable list /a (a12) b (a6).
348 begin data.
349 one    nine
350 two    ten
351 three  eleven
352 four   nought
353 end data.
354
355 autorecode a b into x y
356         /group
357         /print.
358
359 list.
360 ])
361
362 AT_CHECK([pspp -O format=csv ar-strings.sps], [0], [dnl
363 Table: Recoding grouped variables.
364 Old Value,New Value,Value Label
365 eleven,1,eleven
366 four,2,four
367 nine,3,nine
368 nought,4,nought
369 one,5,one
370 ten,6,ten
371 three,7,three
372 two,8,two
373
374 Table: Data List
375 a,b,x,y
376 one,nine,5,3
377 two,ten,8,6
378 three,eleven,7,1
379 four,nought,2,4
380 ])
381
382 AT_CLEANUP
383
384
385
386 AT_SETUP([AUTORECODE /blank])
387
388 AT_DATA([auto-blank.sps],  [dnl
389 data list notable list /x (a8) y (f8.0) z (a16).
390 begin data.
391 one   2  fred
392 two   4  ""
393 ""    4  fred
394 ""    2  charliebrown
395 three 2  charliebrown
396 end data.
397
398 autorecode variables x y z into a b c  /blank=missing /print.
399
400 list a b c y.
401 ])
402
403 AT_CHECK([pspp -O format=csv auto-blank.sps], [0], [dnl
404 Table: Recoding x into a.
405 Old Value,New Value,Value Label
406 one,1,one
407 three,2,three
408 two,3,two
409
410 Table: Recoding y into b.
411 Old Value,New Value,Value Label
412 2,1,2
413 4,2,4
414
415 Table: Recoding z into c.
416 Old Value,New Value,Value Label
417 charliebrown,1,charliebrown
418 fred,2,fred
419
420 Table: Data List
421 a,b,c,y
422 1,1,2,2
423 3,2,.,4
424 .,2,2,4
425 .,1,1,2
426 2,1,1,2
427 ])
428
429 AT_CLEANUP
430
431 dnl AUTORECODE had a use-after-free error when TEMPORARY was in use.
432 dnl Bug #32757.
433 AT_SETUP([AUTORECODE with TEMPORARY])
434 AT_DATA([autorecode.sps],
435   [data list /X 1-5(a) Y 7.
436 begin data.
437 lasdj 1
438 asdfk 0
439 asdfj 2
440 asdfj 1
441 asdfk 2
442 asdfj 9
443 lajks 9
444 asdfk 0
445 asdfk 1
446 end data.
447
448 temporary.
449 select if y > 1.
450 autorecode x y into A B/descend/print.
451 list.
452 ])
453 AT_CHECK([pspp -O format=csv autorecode.sps], [0], [dnl
454 Table: Reading 1 record from INLINE.
455 Variable,Record,Columns,Format
456 X,1,1-5,A5
457 Y,1,7-7,F1.0
458
459 Table: Recoding X into A.
460 Old Value,New Value,Value Label
461 lajks,1,lajks
462 asdfk,2,asdfk
463 asdfj,3,asdfj
464
465 Table: Recoding Y into B.
466 Old Value,New Value,Value Label
467 9,1,9
468 2,2,2
469
470 Table: Data List
471 X,Y,A,B
472 lasdj,1,.,.
473 asdfk,0,2,.
474 asdfj,2,3,2
475 asdfj,1,3,.
476 asdfk,2,2,2
477 asdfj,9,3,1
478 lajks,9,1,1
479 asdfk,0,2,.
480 asdfk,1,2,.
481 ])
482 AT_CLEANUP
483
484
485 dnl For compatibility, make sure that /INTO (with leading slash) is accepted
486 dnl (bug #48762)
487 AT_SETUP([AUTORECODE with /INTO])
488 AT_DATA([autorecode.sps],
489   [data list list notable /x (f8.0).
490 begin data.
491 1
492 8
493 -901
494 4
495 1
496 99
497 8
498 end data.
499
500 autorecode x  /into y /print.
501
502 list.
503 ])
504 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
505 [Table: Recoding x into y.
506 Old Value,New Value,Value Label
507 -901,1,-901
508 1,2,1
509 4,3,4
510 8,4,8
511 99,5,99
512
513 Table: Data List
514 x,y
515 1,2
516 8,4
517 -901,1
518 4,3
519 1,2
520 99,5
521 8,4
522 ])
523 AT_CLEANUP
524
525
526 AT_SETUP([AUTORECODE with /BLANK without specifier])
527
528 AT_DATA([autorecode.sps], [data list notable list /x (a18).
529 begin data
530 one
531 two
532 three
533 end data.
534
535 * /BLANK should be either =MISSING or =VALID
536 autorecode x /into y
537  /blank
538
539 execute.
540 ])
541
542 AT_CHECK([pspp -O format=csv autorecode.sps], [1], [ignore])
543
544 AT_CLEANUP