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