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