FREQUENCIES: Fix crash when median and histogram both requested.
[pspp-builds.git] / tests / language / stats / frequencies.at
1 AT_BANNER([FREQUENCIES procedure])
2
3 AT_SETUP([FREQUENCIES string variable crash])
4 AT_DATA([frequencies.sps],
5   [DATA LIST FREE/
6    name  (A8) value * quantity .
7 BEGIN DATA.
8 Cables 829 3 
9 END DATA.
10 EXECUTE.
11
12 FREQUENCIES /VAR = name.
13 ])
14 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
15   [Table: name
16 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
17 ,Cables  ,1,100.00,100.00,100.00
18 Total,,1,100.0,100.0,
19 ])
20 AT_CLEANUP
21
22 # Tests for a bug where pspp would crash if two FREQUENCIES commands
23 # existed in a input file.
24 AT_SETUP([FREQUENCIES two runs crash])
25 AT_DATA([frequencies.sps],
26   [data list free /v1 v2.
27 begin data.
28 0 1
29 2 3 
30 4 5
31 3 4
32 end data.
33
34 frequencies v1 v2/statistics=none.
35 frequencies v1 v2/statistics=none.
36 ])
37 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
38   [Table: v1
39 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
40 ,.00,1,25.00,25.00,25.00
41 ,2.00,1,25.00,25.00,50.00
42 ,3.00,1,25.00,25.00,75.00
43 ,4.00,1,25.00,25.00,100.00
44 Total,,4,100.0,100.0,
45
46 Table: v2
47 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
48 ,1.00,1,25.00,25.00,25.00
49 ,3.00,1,25.00,25.00,50.00
50 ,4.00,1,25.00,25.00,75.00
51 ,5.00,1,25.00,25.00,100.00
52 Total,,4,100.0,100.0,
53
54 Table: v1
55 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
56 ,.00,1,25.00,25.00,25.00
57 ,2.00,1,25.00,25.00,50.00
58 ,3.00,1,25.00,25.00,75.00
59 ,4.00,1,25.00,25.00,100.00
60 Total,,4,100.0,100.0,
61
62 Table: v2
63 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
64 ,1.00,1,25.00,25.00,25.00
65 ,3.00,1,25.00,25.00,50.00
66 ,4.00,1,25.00,25.00,75.00
67 ,5.00,1,25.00,25.00,100.00
68 Total,,4,100.0,100.0,
69 ])
70 AT_CLEANUP
71
72 # Tests for a bug where PSPP would crash when a FREQUENCIES command
73 # was used with the HTML output driver.
74 AT_SETUP([FREQUENCIES HTML output crash])
75 AT_DATA([frequencies.sps],
76   [data list free /v1 v2.
77 begin data.
78 0 1
79 2 3 
80 4 5
81 3 4
82 end data.
83
84 list.
85
86 frequencies v1/statistics=none.
87 ])
88 AT_CHECK([pspp -o - -O format=csv -o pspp.html frequencies.sps], [0],
89   [Table: Data List
90 v1,v2
91 .00,1.00
92 2.00,3.00
93 4.00,5.00
94 3.00,4.00
95
96 Table: v1
97 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
98 ,.00,1,25.00,25.00,25.00
99 ,2.00,1,25.00,25.00,50.00
100 ,3.00,1,25.00,25.00,75.00
101 ,4.00,1,25.00,25.00,100.00
102 Total,,4,100.0,100.0,
103 ])
104 AT_CHECK([test -s pspp.html])
105 AT_CLEANUP
106
107 # Tests for a bug which crashed PSPP when a piechart with too many
108 # segments was requested.
109 AT_SETUP([FREQUENCIES pie chart crash])
110 AT_DATA([frequencies.sps],
111   [data list list /x * w *.
112 begin data.
113 1  4
114 34 10
115 -9 15
116 232 6
117 11  4
118 134 1
119 9  5
120 32 16
121 -2 6
122 2  16
123 20  6
124 end data.
125
126 weight by w.
127
128 frequencies /x /format=notable /statistics=none
129         /piechart.
130 ])
131 # Cannot use the CSV driver for this because it does not output charts
132 # at all.
133 AT_CHECK([pspp frequencies.sps], [0],
134   [DATA LIST
135
136 Reading free-form data from INLINE.
137 +--------+------+
138 |Variable|Format|
139 #========#======#
140 |x       |F8.0  |
141 |w       |F8.0  |
142 +--------+------+
143
144 BEGIN DATA
145
146 WEIGHT
147
148 FREQUENCIES
149 ])
150 AT_CLEANUP
151
152 # Tests for a bug which crashed PSPP when the median and a histogram
153 # were both requested.
154 AT_SETUP([FREQUENCIES median with histogram crash])
155 AT_DATA([frequencies.sps], [dnl
156 data list list notable /x.
157 begin data.
158 1
159 end data.
160
161 frequencies /x /histogram /STATISTICS=median.
162 ])
163 AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
164 Table: x
165 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
166 ,1.00,1,100.00,100.00,100.00
167 Total,,1,100.0,100.0,
168
169 Table: x
170 N,Valid,1
171 ,Missing,0
172 S.E. Kurt,,.00
173 ,50 (Median),1.00
174 ])
175 AT_CLEANUP
176
177 # Tests for a bug which caused FREQUENCIES following TEMPORARY to
178 # crash (bug #11492).
179 AT_SETUP([FREQUENCIES crash after TEMPORARY])
180 AT_DATA([frequencies.sps],
181   [DATA LIST LIST /SEX (A1) X *.
182 BEGIN DATA.
183 M 31
184 F 21
185 M 41
186 F 31
187 M 13
188 F 12
189 M 14
190 F 13
191 END DATA.
192
193
194 TEMPORARY
195 SELECT IF SEX EQ 'F'
196 FREQUENCIES /X .
197
198 FINISH
199 ])
200 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
201   [Table: Reading free-form data from INLINE.
202 Variable,Format
203 SEX,A1
204 X,F8.0
205
206 Table: X
207 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
208 ,12.00,1,25.00,25.00,25.00
209 ,13.00,1,25.00,25.00,50.00
210 ,21.00,1,25.00,25.00,75.00
211 ,31.00,1,25.00,25.00,100.00
212 Total,,4,100.0,100.0,
213
214 Table: X
215 N,Valid,4
216 ,Missing,0
217 Mean,,19.25
218 Std Dev,,8.81
219 Minimum,,12.00
220 Maximum,,31.00
221 ])
222 AT_CLEANUP
223
224 m4_define([FREQUENCIES_NTILES_OUTPUT],
225   [Table: x
226 N,Valid,5
227 ,Missing,0
228 Mean,,3.00
229 Std Dev,,1.58
230 Minimum,,1.00
231 Maximum,,5.00
232 Percentiles,0,1.00
233 ,25,2.00
234 ,33,2.33
235 ,50 (Median),3.00
236 ,67,3.67
237 ,75,4.00
238 ,100,5.00
239 ])
240 AT_SETUP([FREQUENCIES basic percentiles])
241 AT_DATA([frequencies.sps],
242   [DATA LIST LIST notable /x * .
243 BEGIN DATA.
244
245
246
247
248 5
249 END DATA.
250
251 FREQUENCIES 
252         VAR=x
253         /FORMAT=NOTABLE
254         /PERCENTILES = 0 25 33.333 50 66.666 75 100.
255 ])
256 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
257   [FREQUENCIES_NTILES_OUTPUT])
258 AT_CLEANUP
259
260 AT_SETUP([FREQUENCIES basic n-tiles])
261 AT_DATA([frequencies.sps],
262   [DATA LIST LIST notable /x * .
263 BEGIN DATA.
264
265
266
267
268 5
269 END DATA.
270
271 FREQUENCIES 
272         VAR=x
273         /FORMAT=NOTABLE
274         /NTILES = 3
275         /NTILES = 4.
276 ])
277 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
278   [FREQUENCIES_NTILES_OUTPUT])
279 AT_CLEANUP
280
281 AT_SETUP([FREQUENCIES compatibility percentiles])
282 AT_DATA([frequencies.sps],
283   [DATA LIST LIST notable /X * .
284 BEGIN DATA.
285
286
287
288
289 5
290 END DATA.
291
292 FREQUENCIES 
293         VAR=x
294         /ALGORITHM=COMPATIBLE
295         /PERCENTILES = 0 25 50 75 100.
296 ])
297 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
298   [Table: X
299 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
300 ,1.00,1,20.00,20.00,20.00
301 ,2.00,1,20.00,20.00,40.00
302 ,3.00,1,20.00,20.00,60.00
303 ,4.00,1,20.00,20.00,80.00
304 ,5.00,1,20.00,20.00,100.00
305 Total,,5,100.0,100.0,
306
307 Table: X
308 N,Valid,5
309 ,Missing,0
310 Mean,,3.00
311 Std Dev,,1.58
312 Minimum,,1.00
313 Maximum,,5.00
314 Percentiles,0,1.00
315 ,25,1.50
316 ,50 (Median),3.00
317 ,75,4.50
318 ,100,5.00
319 ])
320 AT_CLEANUP
321
322 AT_SETUP([FREQUENCIES enhanced percentiles])
323 AT_DATA([frequencies.sps],
324   [DATA LIST LIST notable /X * .
325 BEGIN DATA.
326
327
328
329
330 5
331 END DATA.
332
333 FREQUENCIES 
334         VAR=x
335         /PERCENTILES = 0 25 50 75 100.
336 ])
337 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
338   [Table: X
339 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
340 ,1.00,1,20.00,20.00,20.00
341 ,2.00,1,20.00,20.00,40.00
342 ,3.00,1,20.00,20.00,60.00
343 ,4.00,1,20.00,20.00,80.00
344 ,5.00,1,20.00,20.00,100.00
345 Total,,5,100.0,100.0,
346
347 Table: X
348 N,Valid,5
349 ,Missing,0
350 Mean,,3.00
351 Std Dev,,1.58
352 Minimum,,1.00
353 Maximum,,5.00
354 Percentiles,0,1.00
355 ,25,2.00
356 ,50 (Median),3.00
357 ,75,4.00
358 ,100,5.00
359 ])
360 AT_CLEANUP
361
362 AT_SETUP([FREQUENCIES enhanced percentiles, weighted])
363 AT_DATA([frequencies.sps],
364   [DATA LIST LIST notable /X * F *.
365 BEGIN DATA.
366 1 2
367 2 2
368 3 2
369 4 1
370 4 1
371 5 1
372 5 1
373 END DATA.
374
375 WEIGHT BY f.
376
377 FREQUENCIES 
378         VAR=x
379         /PERCENTILES = 0 25 50 75 100.
380 ])
381 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
382   [Table: X
383 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
384 ,1.00,2.00,20.00,20.00,20.00
385 ,2.00,2.00,20.00,20.00,40.00
386 ,3.00,2.00,20.00,20.00,60.00
387 ,4.00,2.00,20.00,20.00,80.00
388 ,5.00,2.00,20.00,20.00,100.00
389 Total,,10.00,100.0,100.0,
390
391 Table: X
392 N,Valid,10.00
393 ,Missing,.00
394 Mean,,3.00
395 Std Dev,,1.49
396 Minimum,,1.00
397 Maximum,,5.00
398 Percentiles,0,1.00
399 ,25,2.00
400 ,50 (Median),3.00
401 ,75,4.00
402 ,100,5.00
403 ])
404 AT_CLEANUP
405
406 AT_SETUP([FREQUENCIES enhanced percentiles, weighted (2)])
407 AT_DATA([frequencies.sps],
408   [DATA LIST LIST notable /X * F *.
409 BEGIN DATA.
410 1 1
411 3 2
412 4 1
413 5 1
414 5 1
415 END DATA.
416
417 WEIGHT BY f.
418
419 FREQUENCIES 
420         VAR=x
421         /PERCENTILES = 0 25 50 75 100.
422 ])
423 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
424   [Table: X
425 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
426 ,1.00,1.00,16.67,16.67,16.67
427 ,3.00,2.00,33.33,33.33,50.00
428 ,4.00,1.00,16.67,16.67,66.67
429 ,5.00,2.00,33.33,33.33,100.00
430 Total,,6.00,100.0,100.0,
431
432 Table: X
433 N,Valid,6.00
434 ,Missing,.00
435 Mean,,3.50
436 Std Dev,,1.52
437 Minimum,,1.00
438 Maximum,,5.00
439 Percentiles,0,1.00
440 ,25,3.00
441 ,50 (Median),3.50
442 ,75,4.75
443 ,100,5.00
444 ])
445 AT_CLEANUP
446
447 dnl Data for this test case from Fabio Bordignon <bordignon@demos.it>.
448 AT_SETUP([FREQUENCIES enhanced percentiles, weighted (3)])
449 AT_DATA([frequencies.sps],
450   [DATA LIST LIST notable /X * F *.
451 BEGIN DATA.
452 1 7
453 2 16
454 3 12
455 4 5
456 END DATA.
457
458 WEIGHT BY f.
459
460 FREQUENCIES 
461         VAR=x
462         /PERCENTILES = 0 25 50 75 100.
463 ])
464 AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
465 Table: X
466 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
467 ,1.00,7.00,17.50,17.50,17.50
468 ,2.00,16.00,40.00,40.00,57.50
469 ,3.00,12.00,30.00,30.00,87.50
470 ,4.00,5.00,12.50,12.50,100.00
471 Total,,40.00,100.0,100.0,
472
473 Table: X
474 N,Valid,40.00
475 ,Missing,.00
476 Mean,,2.38
477 Std Dev,,.93
478 Minimum,,1.00
479 Maximum,,4.00
480 Percentiles,0,1.00
481 ,25,2.00
482 ,50 (Median),2.00
483 ,75,3.00
484 ,100,4.00
485 ])
486 AT_CLEANUP
487
488 AT_SETUP([FREQUENCIES enhanced percentiles, weighted, missing values])
489 AT_DATA([frequencies.sps],
490   [DATA LIST LIST notable /X * F *.
491 BEGIN DATA.
492 1 1
493 3 2
494 4 1
495 5 1
496 5 1
497 99 4
498 END DATA.
499
500 MISSING VALUE x (99.0) .
501 WEIGHT BY f.
502
503 FREQUENCIES 
504         VAR=x
505         /PERCENTILES = 0 25 50 75 100.
506 ])
507 AT_CHECK([pspp -O format=csv frequencies.sps], [0],
508   [Table: X
509 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
510 ,1.00,1.00,10.00,16.67,16.67
511 ,3.00,2.00,20.00,33.33,50.00
512 ,4.00,1.00,10.00,16.67,66.67
513 ,5.00,2.00,20.00,33.33,100.00
514 ,99.00,4.00,40.00,Missing,
515 Total,,10.00,100.0,100.0,
516
517 Table: X
518 N,Valid,6.00
519 ,Missing,4.00
520 Mean,,3.50
521 Std Dev,,1.52
522 Minimum,,1.00
523 Maximum,,5.00
524 Percentiles,0,1.00
525 ,25,3.00
526 ,50 (Median),3.50
527 ,75,4.75
528 ,100,5.00
529 ])
530 AT_CLEANUP