fdd7c33e6bfe6c8de63d87bff76237a2455ebc88
[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 numbers and short strings])
20 AT_DATA([autorecode.sps],
21   [data list /X 1-5(a) Y 7.
22 begin data.
23 lasdj 1
24 asdfk 0
25 asdfj 2
26 asdfj 1
27 asdfk 2
28 asdfj 9
29 lajks 9
30 asdfk 0
31 asdfk 1
32 end data.
33
34 autorecode x y into A B/descend.
35
36 list.
37 compute Z=trunc(y/2).
38 autorecode z into W.
39 list.
40 ])
41 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
42   [Table: Reading 1 record from INLINE.
43 Variable,Record,Columns,Format
44 X,1,1-  5,A5
45 Y,1,7-  7,F1.0
46
47 Table: Data List
48 X,Y,A,B
49 lasdj,1,1.00,3.00
50 asdfk,0,3.00,4.00
51 asdfj,2,4.00,2.00
52 asdfj,1,4.00,3.00
53 asdfk,2,3.00,2.00
54 asdfj,9,4.00,1.00
55 lajks,9,2.00,1.00
56 asdfk,0,3.00,4.00
57 asdfk,1,3.00,3.00
58
59 Table: Data List
60 X,Y,A,B,Z,W
61 lasdj,1,1.00,3.00,.00,1.00
62 asdfk,0,3.00,4.00,.00,1.00
63 asdfj,2,4.00,2.00,1.00,2.00
64 asdfj,1,4.00,3.00,.00,1.00
65 asdfk,2,3.00,2.00,1.00,2.00
66 asdfj,9,4.00,1.00,4.00,3.00
67 lajks,9,2.00,1.00,4.00,3.00
68 asdfk,0,3.00,4.00,.00,1.00
69 asdfk,1,3.00,3.00,.00,1.00
70 ])
71 AT_CLEANUP
72
73
74
75 AT_SETUP([AUTORECODE long strings and check the value labels])
76 AT_DATA([ar.sps],
77   [data list notable list /s (a16) x *.
78 begin data.
79 widgets      1
80 thingummies  2
81 oojars       3
82 widgets      4
83 oojars       5
84 thingummies  6
85 oojimiflips  7
86 end data.
87
88 autorecode s into new.
89
90 list.
91
92 display dictionary.
93 ])
94
95 AT_CHECK([pspp -O format=csv ar.sps], [0],
96   [Table: Data List
97 s,x,new
98 widgets         ,1.00,4.00
99 thingummies     ,2.00,3.00
100 oojars          ,3.00,1.00
101 widgets         ,4.00,4.00
102 oojars          ,5.00,1.00
103 thingummies     ,6.00,3.00
104 oojimiflips     ,7.00,2.00
105
106 Table: Variables
107 Name,Position,Label,Measurement Level,Role,Width,Alignment,Print Format,Write Format,Missing Values
108 s,1,,Nominal,Input,16,Left,A16,A16,
109 x,2,,Scale,Input,8,Right,F8.2,F8.2,
110 new,3,,Scale,Input,8,Right,F8.2,F8.2,
111
112 Table: Value Labels
113 Variable,Value,Label
114 new,1.00,oojars
115 ,2.00,oojimiflips
116 ,3.00,thingummies
117 ,4.00,widgets
118 ])
119
120 AT_CLEANUP
121
122
123 AT_SETUP([AUTORECODE group subcommand])
124 AT_DATA([ar-group.sps],
125 [data list notable list /x * y *.
126 begin data.
127 11 10
128 12 12 
129 13 15
130 14 11
131 15 12
132 16 18
133 end data.
134
135 autorecode 
136         x y into a b
137         /group.
138
139 list.
140 ])
141
142 AT_CHECK([pspp -O format=csv ar-group.sps], [0],
143 [Table: Data List
144 x,y,a,b
145 11.00,10.00,2.00,1.00
146 12.00,12.00,3.00,3.00
147 13.00,15.00,4.00,6.00
148 14.00,11.00,5.00,2.00
149 15.00,12.00,6.00,3.00
150 16.00,18.00,7.00,8.00
151 ])
152
153 AT_CLEANUP
154
155
156
157 AT_SETUP([AUTORECODE group - string variables])
158 AT_DATA([strings.sps],
159 [data list notable list /x (a8) y (a16).
160 begin data.
161 fred bert
162 charlie "         "
163 delta echo
164 "      " windows
165 " "  nothing
166 end data.
167
168
169 autorecode x y into a b
170         /group.
171
172 delete variables x y.
173
174 list.
175
176 ])
177
178 AT_CHECK([pspp -O format=csv strings.sps], [0],
179 [Table: Data List
180 a,b
181 7.00,3.00
182 4.00,1.00
183 5.00,6.00
184 2.00,9.00
185 2.00,8.00
186 ])
187
188 AT_CLEANUP
189
190
191 dnl Tests for a crash which happened when the /GROUP subcommand
192 dnl appeared with string variables of different widths.
193 AT_SETUP([AUTORECODE group vs. strings])
194 AT_DATA([ar-strings.sps],
195   [data list notable list /a (a12) b (a6).
196 begin data.
197 one    nine
198 two    ten
199 three  eleven 
200 four   nought
201 end data.
202
203 autorecode a b into x y 
204         /group.
205
206 list.
207 ])
208
209 AT_CHECK([pspp -O format=csv ar-strings.sps], [0],
210 [dnl
211 Table: Data List
212 a,b,x,y
213 one         ,nine  ,5.00,3.00
214 two         ,ten   ,8.00,6.00
215 three       ,eleven,7.00,1.00
216 four        ,nought,2.00,4.00
217 ])
218
219 AT_CLEANUP
220
221
222
223 AT_SETUP([AUTORECODE /blank])
224
225 AT_DATA([auto-blank.sps],  [dnl
226 data list notable list /x (a8) y * z (a16).
227 begin data.
228 one   2  fred
229 two   4  ""
230 ""    4  fred
231 ""    2  charliebrown
232 three 2  charliebrown
233 end data.
234
235 autorecode variables x y z into a b c  /blank=missing.
236
237 list a b c y.
238 ])
239
240 AT_CHECK([pspp -O format=csv auto-blank.sps], [0], [dnl
241 Table: Data List
242 a,b,c,y
243 1.00,1.00,2.00,2.00
244 3.00,2.00,.  ,4.00
245 .  ,2.00,2.00,4.00
246 .  ,1.00,1.00,2.00
247 2.00,1.00,1.00,2.00
248 ])
249
250 AT_CLEANUP
251
252 dnl AUTORECODE had a use-after-free error when TEMPORARY was in use.
253 dnl Bug #32757.
254 AT_SETUP([AUTORECODE with TEMPORARY])
255 AT_DATA([autorecode.sps],
256   [data list /X 1-5(a) Y 7.
257 begin data.
258 lasdj 1
259 asdfk 0
260 asdfj 2
261 asdfj 1
262 asdfk 2
263 asdfj 9
264 lajks 9
265 asdfk 0
266 asdfk 1
267 end data.
268
269 temporary.
270 select if y > 1.
271 autorecode x y into A B/descend.
272 list.
273 ])
274 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
275   [Table: Reading 1 record from INLINE.
276 Variable,Record,Columns,Format
277 X,1,1-  5,A5
278 Y,1,7-  7,F1.0
279
280 Table: Data List
281 X,Y,A,B
282 lasdj,1,.  ,.  @&t@
283 asdfk,0,2.00,.  @&t@
284 asdfj,2,3.00,2.00
285 asdfj,1,3.00,.  @&t@
286 asdfk,2,2.00,2.00
287 asdfj,9,3.00,1.00
288 lajks,9,1.00,1.00
289 asdfk,0,2.00,.  @&t@
290 asdfk,1,2.00,.  @&t@
291 ])
292 AT_CLEANUP
293
294
295 dnl For compatibility, make sure that /INTO (with leading slash) is accepted
296 dnl (bug #48762)
297 AT_SETUP([AUTORECODE with /INTO])
298 AT_DATA([autorecode.sps],
299   [data list list notable /x .
300 begin data.
301 1
302 8
303 -901
304 4
305 1
306 99
307 8
308 end data.
309
310 autorecode x  /into y.
311
312 list.
313 ])
314 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
315 [Table: Data List
316 x,y
317 1.00,2.00
318 8.00,4.00
319 -901.00,1.00
320 4.00,3.00
321 1.00,2.00
322 99.00,5.00
323 8.00,4.00
324 ])
325 AT_CLEANUP