Implement DATASET commands.
[pspp-builds.git] / tests / language / stats / aggregate.at
1 AT_BANNER([AGGREGATE procedure])
2
3 dnl CHECK_AGGREGATE(OUTFILE, SORT, MISSING)
4 dnl
5 dnl Checks the AGGREGATE procedure with the specified combination of:
6 dnl
7 dnl - OUTFILE: One of "dataset", "active", or "external" according to
8 dnl   where AGGREGATE's output should be directed.
9 dnl 
10 dnl - SORT: Either "presorted" or "unsorted" according to whether
11 dnl   AGGREGATE should received presorted input.
12 dnl
13 dnl - MISSING: Either "itemwise" or "columnwise" according to the basis
14 dnl   on which missing values should be eliminated.
15 dnl
16 m4_define([CHECK_AGGREGATE], [
17   AT_SETUP([AGGREGATE $2 data to $1 file, $3 missing])
18   AT_DATA([aggregate.data],
19   [2 42
20 1001
21 4 41
22 3112
23 1112
24 2661
25 1221
26 2771
27 1331
28 1441
29 2881
30 1551
31 ])
32   AT_DATA([aggregate.sps],
33     [DATA LIST NOTABLE FILE='aggregate.data' /G N 1-2 S 3(a) W 4.
34 WEIGHT BY w.
35 MISSING VALUES n(4) s('4').
36 m4_if([$1], [dataset], [DATASET DECLARE aggregate.])
37 m4_if([$2], [presorted], [SORT CASES BY g.])
38 AGGREGATE dnl
39 m4_if([$1], [active], [OUTFILE=*],
40       [$1], [external], [OUTFILE='aggregate.sys'],
41       [outfile=aggregate]) dnl
42 m4_if([$2], [presorted], [/PRESORTED]) dnl
43 m4_if([$3], [columnwise], [/MISSING=COLUMNWISE])
44         /DOCUMENT
45         /BREAK=g
46         /N = n
47         /NI = n./
48         NU = nu
49         /NUI = nu./
50         NFGT2 = fgt(n, 2)
51         /NFGT2I = fgt.(n, 2)
52         /SFGT2 = fgt(s, '2')
53         /SFGT2I = fgt.(s, '2')
54         /NFIN23 = fin(n, 2, 3)
55         /NFIN23I = fin.(n, 2, 3)
56         /SFIN23 = fin(s, '2', '3')
57         /SFIN23I = fin.(s, '2', '3')
58         /NFLT2 = flt(n, 2)
59         /NFLT2I = flt.(n, 2)
60         /SFLT2 = flt(s, '2')
61         /SFLT2I = flt.(s, '2')
62         /NFIRST = first(n)
63         /NFIRSTI = first.(n)
64         /SFIRST = first(s)
65         /SFIRSTI = first.(s)
66         /NFOUT23 = fout(n, 3, 2)
67         /NFOUT23I = fout.(n, 3, 2)
68         /SFOUT23 = fout(s, '3', '2')
69         /SFOUT23I = fout.(s, '3', '2')
70         /NLAST = last(n)
71         /NLASTI = last.(n)
72         /SLAST = last(s)
73         /SLASTI = last.(s)
74         /NMAX = max(n)
75         /NMAXI = max.(n)
76         /SMAX = max(s)
77         /SMAXI = max.(s)
78         /NMEAN = mean(n)
79         /NMEANI = mean.(n)
80         /NMIN = min(n)
81         /NMINI = min.(n)
82         /SMIN = min(s)
83         /SMINI = min.(s)
84         /NN = n(n)
85         /NNI = n.(n)
86         /SN = n(s)
87         /SNI = n.(s)
88         /NNMISS = nmiss(n)
89         /NNMISSI = nmiss.(n)
90         /SNMISS = nmiss(s)
91         /SNMISSI = nmiss.(s)
92         /NNU = nu(n)
93         /NNUI = nu.(n)
94         /SNU = nu(s)
95         /SNUI = nu.(s)
96         /NNUMISS = numiss(n)
97         /NNUMISSI = numiss.(n)
98         /SNUMISS = numiss(s)
99         /SNUMISSI = numiss.(s)
100         /NPGT2 = pgt(n, 2)
101         /NPGT2I = pgt.(n, 2)
102         /SPGT2 = pgt(s, '2')
103         /SPGT2I = pgt.(s, '2')
104         /NPIN23 = pin(n, 2, 3)
105         /NPIN23I = pin.(n, 2, 3)
106         /SPIN23 = pin(s, '2', '3')
107         /SPIN23I = pin.(s, '2', '3')
108         /NPLT2 = plt(n, 2)
109         /NPLT2I = plt.(n, 2)
110         /SPLT2 = plt(s, '2')
111         /SPLT2I = plt.(s, '2')
112         /NPOUT23 = pout(n, 2, 3)
113         /NPOUT23I = pout.(n, 2, 3)
114         /SPOUT23 = pout(s, '2', '3')
115         /SPOUT23I = pout.(s, '2', '3')
116         /NMEDIAN = median(n)
117         /NMEDIANI = median.(n)
118         /NSD = sd(n)
119         /NSDI = sd.(n)
120         /NSUM = sum(n)
121         /NSUMI = sum.(n).
122 m4_if([$1], [external], [GET FILE='aggregate.sys'.],
123       [$1], [dataset], [DATASET ACTIVATE aggregate.])
124 LIST.
125 ])
126   AT_CHECK([pspp -O format=csv aggregate.sps], [0], [stdout])
127   AT_CHECK([[sed 's/^[^:]*:[0-9]*: //' < stdout]], [0],
128     [m4_if([$3], [itemwise],
129       [warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
130
131 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
132
133 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
134
135 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
136
137 Table: Data List
138 G,N,NI,NU,NUI,NFGT2,NFGT2I,SFGT2,SFGT2I,NFIN23,NFIN23I,SFIN23,SFIN23I,NFLT2,NFLT2I,SFLT2,SFLT2I,NFIRST,NFIRSTI,SFIRST,SFIRSTI,NFOUT23,NFOUT23I,SFOUT23,SFOUT23I,NLAST,NLASTI,SLAST,SLASTI,NMAX,NMAXI,SMAX,SMAXI,NMEAN,NMEANI,NMIN,NMINI,SMIN,SMINI,NN,NNI,SN,SNI,NNMISS,NNMISSI,SNMISS,SNMISSI,NNU,NNUI,SNU,SNUI,NNUMISS,NNUMISSI,SNUMISS,SNUMISSI,NPGT2,NPGT2I,SPGT2,SPGT2I,NPIN23,NPIN23I,SPIN23,SPIN23I,NPLT2,NPLT2I,SPLT2,SPLT2I,NPOUT23,NPOUT23I,SPOUT23,SPOUT23I,NMEDIAN,NMEDIANI,NSD,NSDI,NSUM,NSUMI
139 1,7.00,7.00,6,6,.333,.429,.333,.429,.333,.286,.333,.286,.500,.429,.500,.429,0,0,0,0,.667,.714,.667,.714,5,5,5,5,5,5,5,5,2.00,2.29,0,0,0,0,6.00,7.00,6.00,7.00,1.00,.00,1.00,.00,5,6,5,6,1,0,1,0,33.3,42.9,33.3,42.9,33.3,28.6,33.3,28.6,50.0,42.9,50.0,42.9,66.7,71.4,66.7,71.4,1.50,2.00,1.79,1.80,12.00,16.00
140 2,5.00,5.00,4,4,1.000,1.000,1.000,1.000,.000,.000,.000,.000,.000,.000,.000,.000,6,6,6,4,1.000,1.000,1.000,1.000,8,8,8,8,8,8,8,8,7.00,7.00,6,6,6,4,3.00,3.00,3.00,5.00,2.00,2.00,2.00,.00,3,3,3,4,1,1,1,0,100.0,100.0,100.0,100.0,.0,.0,.0,.0,.0,.0,.0,.0,100.0,100.0,100.0,100.0,7.00,7.00,1.00,1.00,21.00,21.00
141 3,2.00,2.00,1,1,.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000,1.000,1.000,1,1,1,1,1.000,1.000,1.000,1.000,1,1,1,1,1,1,1,1,1.00,1.00,1,1,1,1,2.00,2.00,2.00,2.00,.00,.00,.00,.00,1,1,1,1,0,0,0,0,.0,.0,.0,.0,.0,.0,.0,.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,1.00,1.00,.00,.00,2.00,2.00
142 4,1.00,1.00,1,1,.   ,.   ,.   ,1.000,.   ,.   ,.   ,.000,.   ,.   ,.   ,.000,.,.,,4,.   ,.   ,.   ,1.000,.,.,,4,.,.,,4,.  ,.  ,.,.,,4,.00,.00,.00,1.00,1.00,1.00,1.00,.00,0,0,0,1,1,1,1,0,. ,. ,. ,100.0,. ,. ,. ,.0,. ,. ,. ,.0,. ,. ,. ,100.0,NaN,NaN,.  ,.  ,.  ,.  @&t@
143 ],
144       [warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
145
146 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
147
148 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
149
150 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
151
152 Table: Data List
153 G,N,NI,NU,NUI,NFGT2,NFGT2I,SFGT2,SFGT2I,NFIN23,NFIN23I,SFIN23,SFIN23I,NFLT2,NFLT2I,SFLT2,SFLT2I,NFIRST,NFIRSTI,SFIRST,SFIRSTI,NFOUT23,NFOUT23I,SFOUT23,SFOUT23I,NLAST,NLASTI,SLAST,SLASTI,NMAX,NMAXI,SMAX,SMAXI,NMEAN,NMEANI,NMIN,NMINI,SMIN,SMINI,NN,NNI,SN,SNI,NNMISS,NNMISSI,SNMISS,SNMISSI,NNU,NNUI,SNU,SNUI,NNUMISS,NNUMISSI,SNUMISS,SNUMISSI,NPGT2,NPGT2I,SPGT2,SPGT2I,NPIN23,NPIN23I,SPIN23,SPIN23I,NPLT2,NPLT2I,SPLT2,SPLT2I,NPOUT23,NPOUT23I,SPOUT23,SPOUT23I,NMEDIAN,NMEDIANI,NSD,NSDI,NSUM,NSUMI
154 1,7.00,7.00,6,6,.   ,.429,.   ,.429,.   ,.286,.   ,.286,.   ,.429,.   ,.429,.,0,,0,.   ,.714,.   ,.714,.,5,,5,.,5,,5,.  ,2.29,.,0,,0,6.00,7.00,6.00,7.00,1.00,.00,1.00,.00,5,6,5,6,1,0,1,0,. ,42.9,. ,42.9,. ,28.6,. ,28.6,. ,42.9,. ,42.9,. ,71.4,. ,71.4,.  ,2.00,.  ,1.80,.  ,16.00
155 2,5.00,5.00,4,4,.   ,.   ,.   ,1.000,.   ,.   ,.   ,.000,.   ,.   ,.   ,.000,.,.,,4,.   ,.   ,.   ,1.000,.,.,,8,.,.,,8,.  ,.  ,.,.,,4,3.00,3.00,3.00,5.00,2.00,2.00,2.00,.00,3,3,3,4,1,1,1,0,. ,. ,. ,100.0,. ,. ,. ,.0,. ,. ,. ,.0,. ,. ,. ,100.0,.  ,.  ,.  ,.  ,.  ,.  @&t@
156 3,2.00,2.00,1,1,.000,.000,.000,.000,.000,.000,.000,.000,1.000,1.000,1.000,1.000,1,1,1,1,1.000,1.000,1.000,1.000,1,1,1,1,1,1,1,1,1.00,1.00,1,1,1,1,2.00,2.00,2.00,2.00,.00,.00,.00,.00,1,1,1,1,0,0,0,0,.0,.0,.0,.0,.0,.0,.0,.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,100.0,1.00,1.00,.00,.00,2.00,2.00
157 4,1.00,1.00,1,1,.   ,.   ,.   ,1.000,.   ,.   ,.   ,.000,.   ,.   ,.   ,.000,.,.,,4,.   ,.   ,.   ,1.000,.,.,,4,.,.,,4,.  ,.  ,.,.,,4,.00,.00,.00,1.00,1.00,1.00,1.00,.00,0,0,0,1,1,1,1,0,. ,. ,. ,100.0,. ,. ,. ,.0,. ,. ,. ,.0,. ,. ,. ,100.0,.  ,.  ,.  ,.  ,.  ,.  @&t@
158 ])])
159   AT_CLEANUP])
160
161 CHECK_AGGREGATE([dataset], [presorted], [itemwise])
162 CHECK_AGGREGATE([dataset], [presorted], [columnwise])
163 CHECK_AGGREGATE([dataset], [unsorted], [itemwise])
164 CHECK_AGGREGATE([dataset], [unsorted], [columnwise])
165 CHECK_AGGREGATE([active], [presorted], [itemwise])
166 CHECK_AGGREGATE([active], [presorted], [columnwise])
167 CHECK_AGGREGATE([active], [unsorted], [itemwise])
168 CHECK_AGGREGATE([active], [unsorted], [columnwise])
169 CHECK_AGGREGATE([external], [presorted], [itemwise])
170 CHECK_AGGREGATE([external], [presorted], [columnwise])
171 CHECK_AGGREGATE([external], [unsorted], [itemwise])
172 CHECK_AGGREGATE([external], [unsorted], [columnwise])
173
174 AT_SETUP([AGGREGATE crash with MAX function])
175 AT_DATA([aggregate.sps], 
176   [DATA LIST LIST /X (F8.2) Y (a25).
177
178 BEGIN DATA.
179 87.50 foo
180 87.34 bar
181 1 bar
182 END DATA.
183
184 AGGREGATE OUTFILE=* /BREAK=y /X=MAX(x).
185 LIST /x y.
186 ])
187 AT_CHECK([pspp -O format=csv aggregate.sps], [0],
188   [Table: Reading free-form data from INLINE.
189 Variable,Format
190 X,F8.2
191 Y,A25
192
193 Table: Data List
194 X,Y
195 87.34,bar                      @&t@
196 87.50,foo                      @&t@
197 ])
198 AT_CLEANUP
199
200 AT_SETUP([AGGREGATE crash with invalid syntax])
201 AT_DATA([aggregate.sps],
202   [INPUT PROGRAM.
203 LOOP c=1 TO 20.
204   COMPUTE x=UNIFORM(10)
205   END CASE.
206 END LOOP.
207 END FILE.
208 END INPUT PROGRAM.
209
210 AGGREGATE /BREAK=x .
211 ])
212 AT_CHECK([pspp -O format=csv aggregate.sps], [1], [ignore], [])
213 AT_CLEANUP
214
215
216 AT_SETUP([AGGREGATE mode=addvariables])
217 AT_DATA([addvariables.sps],
218   [data list notable list /x * cn * y *.
219 begin data.
220 1 1 2
221 3 2 3
222 3 3 4
223 5 4 6
224 7 5 8
225 7 6 9
226 7 7 20
227 9 8 11
228 end data.
229
230 aggregate outfile=* mode=addvariables
231         /break = x
232         /sum = sum(y)
233         /mean = mean (y)
234         /median = median (y).
235
236 list.
237 ])
238
239 AT_CHECK([pspp -O format=csv addvariables.sps], [0],
240   [Table: Data List
241 x,cn,y,sum,mean,median
242 1.00,1.00,2.00,2.00,2.00,2.00
243 3.00,2.00,3.00,7.00,3.50,3.50
244 3.00,3.00,4.00,7.00,3.50,3.50
245 5.00,4.00,6.00,6.00,6.00,6.00
246 7.00,5.00,8.00,37.00,12.33,9.00
247 7.00,6.00,9.00,37.00,12.33,9.00
248 7.00,7.00,20.00,37.00,12.33,9.00
249 9.00,8.00,11.00,11.00,11.00,11.00
250 ])
251
252 AT_CLEANUP
253
254
255 AT_SETUP([AGGREGATE buggy duplicate variables])
256 dnl Test for a bug which crashed when duplicated
257 dnl variables were attempted.
258 AT_DATA([dup-variables.sps],
259   [DATA LIST NOTABLE LIST /x * .
260 begin data
261 1
262 1
263 1
264 1
265 2
266 2
267 2
268 3
269 3
270 3
271 3
272 3
273 3
274 end data.
275
276 AGGREGATE OUTFILE=* MODE=ADDVARIABLES
277         /BREAK= x
278         /N_BREAK = N.
279
280 AGGREGATE OUTFILE=* MODE=ADDVARIABLES
281         /BREAK= x
282         /N_BREAK = N.
283 ])
284
285 AT_CHECK([pspp -O format=csv dup-variables.sps], [1],
286 ["dup-variables.sps:24: error: AGGREGATE: Variable name N_BREAK is not unique within the aggregate file dictionary, which contains the aggregate variables and the break variables."
287 ])
288
289 AT_CLEANUP