Fix erroneous subsitute by previous commit.
[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 Variable,Description,Position
107 s,Format: A16,1
108 x,Format: F8.2,2
109 new,"Format: F8.2
110
111 Value,Label
112 1.00,oojars
113 2.00,oojimiflips
114 3.00,thingummies
115 4.00,widgets",3
116 ])
117
118 AT_CLEANUP
119
120
121 AT_SETUP([AUTORECODE group subcommand])
122 AT_DATA([ar-group.sps],
123 [data list notable list /x * y *.
124 begin data.
125 11 10
126 12 12 
127 13 15
128 14 11
129 15 12
130 16 18
131 end data.
132
133 autorecode 
134         x y into a b
135         /group.
136
137 list.
138 ])
139
140 AT_CHECK([pspp -O format=csv ar-group.sps], [0],
141 [Table: Data List
142 x,y,a,b
143 11.00,10.00,2.00,1.00
144 12.00,12.00,3.00,3.00
145 13.00,15.00,4.00,6.00
146 14.00,11.00,5.00,2.00
147 15.00,12.00,6.00,3.00
148 16.00,18.00,7.00,8.00
149 ])
150
151 AT_CLEANUP
152
153
154
155 AT_SETUP([AUTORECODE group - string variables])
156 AT_DATA([strings.sps],
157 [data list notable list /x (a8) y (a16).
158 begin data.
159 fred bert
160 charlie "         "
161 delta echo
162 "      " windows
163 " "  nothing
164 end data.
165
166
167 autorecode x y into a b
168         /group.
169
170 delete variables x y.
171
172 list.
173
174 ])
175
176 AT_CHECK([pspp -O format=csv strings.sps], [0],
177 [Table: Data List
178 a,b
179 7.00,3.00
180 4.00,1.00
181 5.00,6.00
182 2.00,9.00
183 2.00,8.00
184 ])
185
186 AT_CLEANUP
187
188
189 dnl Tests for a crash which happened when the /GROUP subcommand
190 dnl appeared with string variables of different widths.
191 AT_SETUP([AUTORECODE group vs. strings])
192 AT_DATA([ar-strings.sps],
193   [data list notable list /a (a12) b (a6).
194 begin data.
195 one    nine
196 two    ten
197 three  eleven 
198 four   nought
199 end data.
200
201 autorecode a b into x y 
202         /group.
203
204 list.
205 ])
206
207 AT_CHECK([pspp -O format=csv ar-strings.sps], [0],
208 [dnl
209 Table: Data List
210 a,b,x,y
211 one         ,nine  ,5.00,3.00
212 two         ,ten   ,8.00,6.00
213 three       ,eleven,7.00,1.00
214 four        ,nought,2.00,4.00
215 ])
216
217 AT_CLEANUP
218
219
220
221 AT_SETUP([AUTORECODE /blank])
222
223 AT_DATA([auto-blank.sps],  [dnl
224 data list notable list /x (a8) y * z (a16).
225 begin data.
226 one   2  fred
227 two   4  ""
228 ""    4  fred
229 ""    2  charliebrown
230 three 2  charliebrown
231 end data.
232
233 autorecode variables x y z into a b c  /blank=missing.
234
235 list a b c y.
236 ])
237
238 AT_CHECK([pspp -O format=csv auto-blank.sps], [0], [dnl
239 Table: Data List
240 a,b,c,y
241 1.00,1.00,2.00,2.00
242 3.00,2.00,.  ,4.00
243 .  ,2.00,2.00,4.00
244 .  ,1.00,1.00,2.00
245 2.00,1.00,1.00,2.00
246 ])
247
248 AT_CLEANUP
249
250 dnl AUTORECODE had a use-after-free error when TEMPORARY was in use.
251 dnl Bug #32757.
252 AT_SETUP([AUTORECODE with TEMPORARY])
253 AT_DATA([autorecode.sps],
254   [data list /X 1-5(a) Y 7.
255 begin data.
256 lasdj 1
257 asdfk 0
258 asdfj 2
259 asdfj 1
260 asdfk 2
261 asdfj 9
262 lajks 9
263 asdfk 0
264 asdfk 1
265 end data.
266
267 temporary.
268 select if y > 1.
269 autorecode x y into A B/descend.
270 list.
271 ])
272 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
273   [Table: Reading 1 record from INLINE.
274 Variable,Record,Columns,Format
275 X,1,1-  5,A5
276 Y,1,7-  7,F1.0
277
278 Table: Data List
279 X,Y,A,B
280 lasdj,1,.  ,.  @&t@
281 asdfk,0,2.00,.  @&t@
282 asdfj,2,3.00,2.00
283 asdfj,1,3.00,.  @&t@
284 asdfk,2,2.00,2.00
285 asdfj,9,3.00,1.00
286 lajks,9,1.00,1.00
287 asdfk,0,2.00,.  @&t@
288 asdfk,1,2.00,.  @&t@
289 ])
290 AT_CLEANUP
291
292
293 dnl For compatibility, make sure that /INTO (with leading slash) is accepted
294 dnl (bug #48762)
295 AT_SETUP([AUTORECODE with /INTO])
296 AT_DATA([autorecode.sps],
297   [data list list notable /x .
298 begin data.
299 1
300 8
301 -901
302 4
303 1
304 99
305 8
306 end data.
307
308 autorecode x  /into y.
309
310 list.
311 ])
312 AT_CHECK([pspp -O format=csv autorecode.sps], [0],
313 [Table: Data List
314 x,y
315 1.00,2.00
316 8.00,4.00
317 -901.00,1.00
318 4.00,3.00
319 1.00,2.00
320 99.00,5.00
321 8.00,4.00
322 ])
323 AT_CLEANUP