Move all command implementations into a single 'commands' directory.
[pspp] / tests / language / commands / graph.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([GRAPH])
18
19 AT_SETUP([GRAPH simple scatterplot])
20 AT_DATA([scatterplot.sps],[
21 * Simple Scatterplot test
22 NEW FILE.
23 INPUT PROGRAM.
24 LOOP #i = 1 to 100.
25 COMPUTE Age = RV.NORMAL(40,10).
26 END CASE.
27 END LOOP.
28 END FILE.
29 END INPUT PROGRAM.
30
31 COMPUTE Size = Age * 3 + 50.
32
33 GRAPH
34     /SCATTERPLOT(BIVARIATE) = Age WITH Size.
35
36 ])
37
38 AT_CHECK([pspp -O format=csv scatterplot.sps], [0], [ignore])
39
40 AT_CLEANUP
41
42
43 AT_SETUP([GRAPH Scatter and Histogram])
44 AT_KEYWORDS([slow])
45 AT_DATA([scatterlong.sps],[
46 NEW FILE.
47 INPUT PROGRAM.
48 LOOP #i = 1 to 10000.
49 COMPUTE Age = RV.NORMAL(40,10).
50 COMPUTE CityNum = TRUNC(UNIFORM(2.95)).
51 END CASE.
52 END LOOP.
53 END FILE.
54 END INPUT PROGRAM.
55
56 COMPUTE Size = Age * 3 + 50 + 50*CityNum.
57
58 STRING City (a20).
59
60 Recode CityNum
61        (0 = "Madrid")
62        (1 = "Paris")
63        (ELSE = "Stockholm")
64        into City.
65
66  GRAPH
67     /SCATTERPLOT(BIVARIATE) = Age WITH Size
68
69  GRAPH
70     /SCATTERPLOT(BIVARIATE) = Age WITH CityNum
71
72  GRAPH
73     /SCATTERPLOT = CityNum WITH Age
74
75  GRAPH
76     /SCATTERPLOT = CityNum WITH Size
77
78  GRAPH
79     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY City
80
81  GRAPH
82     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY CityNum
83
84  ADD VALUE LABELS
85     /CityNum 1 'Rio' 2 'Tokyo' 0 'Mumbai'.
86
87  GRAPH
88     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY CityNum
89
90  GRAPH
91     /HISTOGRAM = Age.
92
93 ])
94
95 AT_CHECK([pspp -O format=pdf scatterlong.sps], [0], [ignore], [ignore])
96 AT_CLEANUP
97
98 AT_SETUP([GRAPH missing values don't crash])
99 AT_DATA([scatter.sps], [dnl
100 data list list /x * y *.
101 begin data.
102 1 0
103 2 0
104 . 0
105 3 1
106 4 1
107 5 .
108 6 1
109 end data.
110 graph
111       /scatterplot = x with y.
112 graph
113       /histogram = x.
114 ])
115 AT_CHECK([pspp -o pspp.pdf scatter.sps], [], [ignore])
116 dnl Ignore output -- this is just a no-crash check.
117 AT_CLEANUP
118
119 AT_SETUP([GRAPH missing=VARIABLE no crash])
120 AT_DATA([scatter.sps], [dnl
121 data list list /x * y *.
122 begin data.
123 1 0
124 2 0
125 . 0
126 3 1
127 4 1
128 5 .
129 6 1
130 end data.
131 graph
132       /scatterplot = x with y
133       /missing = VARIABLE.
134 graph
135       /histogram = x
136       /missing = VARIABLE.
137 ])
138 AT_CHECK([pspp -o pspp.pdf scatter.sps], [], [ignore])
139 dnl Ignore output -- this is just a no-crash check.
140 AT_CLEANUP
141
142 AT_SETUP([GRAPH missing value in by variable])
143 AT_DATA([scatter.sps], [dnl
144 data list list /x * y * z *.
145 begin data.
146 1 0 9
147 2 0 9
148 . 0 9
149 3 1 .
150 4 1 8
151 5 . 8
152 6 1 8
153 end data.
154 graph
155       /scatterplot = x with y by z
156       /missing = VARIABLE.
157
158 graph
159       /scatterplot = x with y by z.
160
161 ])
162 AT_CHECK([pspp -o pspp.pdf scatter.sps], [0], [ignore])
163 dnl Ignore output -- this is just a no-crash check.
164 AT_CLEANUP
165
166
167 AT_SETUP([GRAPH histogram with null data])
168 AT_DATA([null-hist.sps], [dnl
169 data list list /x *.
170 begin data.
171 1109
172 .
173 end data.
174
175 graph
176       /histogram = x.
177
178 ])
179
180 AT_CHECK([pspp -o pspp.pdf null-hist.sps], [0], [ignore])
181 dnl Ignore output -- this is just a no-crash check.
182 AT_CLEANUP
183
184
185 AT_SETUP([GRAPH histogram all missing])
186 AT_DATA([null-hist.sps], [dnl
187 data list list /x *.
188 begin data.
189 .
190 end data.
191
192 graph
193       /histogram = x.
194
195 ])
196
197 AT_CHECK([pspp null-hist.sps], [0], [ignore])
198 dnl Ignore output -- this is just a no-crash check.
199 AT_CLEANUP
200
201
202
203
204 AT_SETUP([GRAPH barcharts])
205 AT_CHECK([ln -s $top_srcdir/examples/physiology.sav .], [0])
206 AT_CHECK([ln -s $top_srcdir/examples/repairs.sav .], [0])
207
208 AT_DATA([barchart.sps], [dnl
209 GET FILE="physiology.sav".
210
211 GRAPH /BAR = COUNT BY SEX.
212
213 GRAPH /BAR = MEAN(height) BY SEX.
214
215 NEW FILE.
216
217 GET FILE="repairs.sav".
218
219 GRAPH /BAR = MEAN (mtbf) BY factory.
220
221 COMPUTE  R = TRUNC(RV.UNIFORM(1,5)).
222
223 GRAPH /BAR = MEAN (mtbf) BY factory BY R.
224 ])
225
226 AT_CHECK([pspp -o pspp.pdf barchart.sps], [0], [ignore])
227 dnl Ignore output -- this is just a no-crash check.
228
229 AT_CLEANUP
230
231
232
233 AT_SETUP([GRAPH barchart arity])
234
235 AT_DATA([barchart.sps], [dnl
236 data list notable list /x y z*.
237 begin data
238 1  1  3
239 2  1  4
240 3  1  3
241 4  1  4
242 5  .  3
243 6  2  4
244 7  2  3
245 8  2  4
246 9  2  3
247 10  2  4
248 end data.
249
250 * This line is invalid
251 GRAPH /BAR = COUNT(x) BY y.
252 ])
253
254 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
255 dnl Ignore output -- this is just a no-crash check.
256
257 AT_CLEANUP
258
259
260
261
262 AT_SETUP([GRAPH barchart bad syntax])
263
264 AT_DATA([barchart.sps], [dnl
265 data list notable list /x y z*.
266 begin data
267 1  1  3
268 2  1  4
269 3  1  3
270 4  1  4
271 5  .  3
272 6  2  4
273 7  2  3
274 8  2  4
275 9  2  3
276 10  2  4
277 end data.
278
279 * This line is invalid
280 GRAPH /BAR = SCROD BY y.
281 ])
282
283 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
284 dnl Ignore output -- this is just a no-crash check.
285
286 AT_CLEANUP
287
288
289
290 AT_SETUP([GRAPH barchart full])
291
292 AT_DATA([barchart.sps], [dnl
293 data list notable list /x y z*.
294 begin data
295 1  1  3
296 2  1  4
297 3  1  3
298 4  1  4
299 5  .  3
300 6  2  4
301 7  2  3
302 8  2  4
303 9  2  3
304 10  2  4
305 end data.
306
307 * This line is invalid
308 GRAPH /BAR = COUNT by z.
309 GRAPH /BAR = CUFREQ by z.
310 GRAPH /BAR = PCT by z.
311 GRAPH /BAR = CUPCT by z.
312
313 GRAPH /BAR = MEAN(y) BY z.
314 GRAPH /BAR = SUM(y) BY z.
315 GRAPH /BAR = MAXIMUM(y) BY z.
316 GRAPH /BAR = MINIMUM(y) BY z.
317
318 GRAPH /BAR = MEAN(y) BY z BY y.
319 GRAPH /BAR = SUM(y) BY z BY y.
320 GRAPH /BAR = MAXIMUM(y) BY z BY y.
321 GRAPH /BAR = MINIMUM(y) BY z BY y.
322 ])
323
324 AT_CHECK([pspp -o pspp.pdf barchart.sps], [0], [ignore])
325 dnl Ignore output -- this is just a no-crash check.
326
327 AT_CLEANUP
328
329
330
331
332
333 AT_SETUP([GRAPH buggy syntax])
334
335 AT_DATA([barchart.sps], [dnl
336 data list notable list /x y z*.
337 begin data
338 1  1  3
339 2  1  4
340 10  2  4
341 end data.
342
343 GRAPH /BAR = MINIMUM({) BY z BY y.
344 ])
345
346 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
347 dnl Ignore output -- this is just a no-crash check.
348
349 AT_CLEANUP
350
351
352 dnl Check that percentages are calculated with respect to the
353 dnl proper total.  See bug #56247
354 AT_SETUP([GRAPH barchart percentage sub-categorical])
355 AT_DATA([barchart.sps], [dnl
356 data list list notable /penalty_favopp_x * XYdem_racethW8 * w *.
357 begin data.
358 1 0 1960
359 1 1 376
360 2 0 678
361 2 1 147
362 4 0 368
363 4 1 164
364 5 0 427
365 5 1 274
366 . . 1522
367 end data.
368
369 weight by w.
370
371 * crosstabs
372 *   /tables=penalty_favopp_x by XYdem_racethW8
373 *   /format=AVALUE TABLES PIVOT
374 *   /statistics=CHISQ
375 *   /cells COUNT COLUMN TOTAL.
376
377 graph
378   /bar=pct by penalty_favopp_x
379   .
380
381 graph
382   /bar=pct by penalty_favopp_x by XYdem_racethW8
383   .
384 ])
385
386 AT_CHECK([pspp --testing barchart.sps], [0], [dnl
387 Graphic: Barchart
388 Percentage: 0
389 Total Categories: 4
390 Primary Categories: 4
391 Largest Category: 53.1634
392 Total Count: 100
393 Y Label: "Percentage"
394 Categorical Variables:
395   Var: "penalty_favopp_x"
396 Categories:
397   0 "    1.00"
398   1 "    2.00"
399   2 "    4.00"
400   3 "    5.00"
401 All Categories:
402 Count: 53.1634; Cat: "    1.00"
403 Count: 18.7756; Cat: "    2.00"
404 Count: 12.1074; Cat: "    4.00"
405 Count: 15.9536; Cat: "    5.00"
406
407 Graphic: Barchart
408 Percentage: 0
409 Total Categories: 8
410 Primary Categories: 4
411 Largest Category: 57.0929
412 Total Count: 200
413 Y Label: "Percentage"
414 Categorical Variables:
415   Var: "penalty_favopp_x"
416   Var: "XYdem_racethW8"
417 Categories:
418   0 "    1.00"
419   1 "    2.00"
420   2 "    4.00"
421   3 "    5.00"
422 Sub-categories:
423   0 "     .00"
424   1 "    1.00"
425 All Categories:
426 Count: 57.0929; Cat: "    1.00", "     .00"
427 Count: 39.1259; Cat: "    1.00", "    1.00"
428 Count: 19.7495; Cat: "    2.00", "     .00"
429 Count: 15.2966; Cat: "    2.00", "    1.00"
430 Count: 10.7195; Cat: "    4.00", "     .00"
431 Count: 17.0656; Cat: "    4.00", "    1.00"
432 Count: 12.4381; Cat: "    5.00", "     .00"
433 Count: 28.512; Cat: "    5.00", "    1.00"
434
435 ])
436
437 AT_CLEANUP
438
439 AT_SETUP([GRAPH syntax errors])
440 AT_DATA([graph.sps], [dnl
441 DATA LIST LIST NOTABLE/x y z.
442 GRAPH/HISTOGRAM=x/HISTOGRAM=y.
443 GRAPH/HISTOGRAM(**).
444 GRAPH/HISTOGRAM(NORMAL **).
445 GRAPH/HISTOGRAM=**.
446 GRAPH/HISTOGRAM=x y z.
447 GRAPH/HISTOGRAM=x/BAR=y.
448 GRAPH/BAR(GROUPED).
449 GRAPH/BAR(STACKED).
450 GRAPH/BAR(RANGE).
451 GRAPH/BAR(**).
452 GRAPH/BAR **.
453 GRAPH/BAR=**.
454 GRAPH/BAR=MEAN **.
455 GRAPH/BAR=MEAN(**).
456 GRAPH/BAR=MEAN(x**).
457 GRAPH/BAR=MEAN(x) **.
458 GRAPH/BAR=MEAN(x) BY **.
459 GRAPH/BAR=MEAN(x) BY y BY **.
460 GRAPH/HISTOGRAM=x/SCATTERPLOT=y.
461 GRAPH/SCATTERPLOT(OVERLAY).
462 GRAPH/SCATTERPLOT(MATRIX).
463 GRAPH/SCATTERPLOT(XYZ).
464 GRAPH/SCATTERPLOT(**).
465 GRAPH/SCATTERPLOT(BIVARIATE **).
466 GRAPH/SCATTERPLOT **.
467 GRAPH/SCATTERPLOT=**.
468 GRAPH/SCATTERPLOT=x y z.
469 GRAPH/SCATTERPLOT=x **.
470 GRAPH/SCATTERPLOT=x WITH **.
471 GRAPH/SCATTERPLOT=x WITH y z.
472 GRAPH/SCATTERPLOT=x WITH y BY **.
473 GRAPH/LINE.
474 GRAPH/PIE.
475 GRAPH/ERRORBAR.
476 GRAPH/PARETO.
477 GRAPH/TITLE.
478 GRAPH/SUBTITLE.
479 GRAPH/FOOTNOTE.
480 GRAPH/MISSING=**.
481 GRAPH/ **.
482 ])
483 AT_CHECK([pspp -O format=csv graph.sps], [1], [dnl
484 "graph.sps:2.19-2.27: error: GRAPH: Only one chart type is allowed.
485     2 | GRAPH/HISTOGRAM=x/HISTOGRAM=y.
486       |                   ^~~~~~~~~"
487
488 "graph.sps:3.17-3.18: error: GRAPH: Syntax error expecting `NORMAL)'.
489     3 | GRAPH/HISTOGRAM(**).
490       |                 ^~"
491
492 "graph.sps:4.17-4.25: error: GRAPH: Syntax error expecting `NORMAL)'.
493     4 | GRAPH/HISTOGRAM(NORMAL **).
494       |                 ^~~~~~~~~"
495
496 "graph.sps:5.17-5.18: error: GRAPH: Syntax error expecting variable name.
497     5 | GRAPH/HISTOGRAM=**.
498       |                 ^~"
499
500 "graph.sps:6.17-6.21: error: GRAPH: Only one variable is allowed.
501     6 | GRAPH/HISTOGRAM=x y z.
502       |                 ^~~~~"
503
504 "graph.sps:7.19-7.21: error: GRAPH: Only one chart type is allowed.
505     7 | GRAPH/HISTOGRAM=x/BAR=y.
506       |                   ^~~"
507
508 "graph.sps:8.11-8.17: error: GRAPH: GROUPED is not yet implemented.
509     8 | GRAPH/BAR(GROUPED).
510       |           ^~~~~~~"
511
512 "graph.sps:9.11-9.17: error: GRAPH: STACKED is not yet implemented.
513     9 | GRAPH/BAR(STACKED).
514       |           ^~~~~~~"
515
516 "graph.sps:10.11-10.15: error: GRAPH: RANGE is not yet implemented.
517    10 | GRAPH/BAR(RANGE).
518       |           ^~~~~"
519
520 "graph.sps:11.11-11.12: error: GRAPH: Syntax error expecting SIMPLE, GROUPED, STACKED, or RANGE.
521    11 | GRAPH/BAR(**).
522       |           ^~"
523
524 "graph.sps:12.11-12.12: error: GRAPH: Syntax error expecting `='.
525    12 | GRAPH/BAR **.
526       |           ^~"
527
528 "graph.sps:13.11-13.12: error: GRAPH: Syntax error expecting COUNT, PCT, CUFREQ, CUPCT, MEAN, SUM, MAXIMUM, or MINIMUM.
529    13 | GRAPH/BAR=**.
530       |           ^~"
531
532 "graph.sps:14.16-14.17: error: GRAPH: Syntax error expecting `('.
533    14 | GRAPH/BAR=MEAN **.
534       |                ^~"
535
536 "graph.sps:15.16-15.17: error: GRAPH: Syntax error expecting variable name.
537    15 | GRAPH/BAR=MEAN(**).
538       |                ^~"
539
540 "graph.sps:16.17-16.18: error: GRAPH: Syntax error expecting `)'.
541    16 | GRAPH/BAR=MEAN(x**).
542       |                 ^~"
543
544 "graph.sps:17.19-17.20: error: GRAPH: Syntax error expecting `BY'.
545    17 | GRAPH/BAR=MEAN(x) **.
546       |                   ^~"
547
548 "graph.sps:18.22-18.23: error: GRAPH: Syntax error expecting variable name.
549    18 | GRAPH/BAR=MEAN(x) BY **.
550       |                      ^~"
551
552 "graph.sps:19.27-19.28: error: GRAPH: Syntax error expecting variable name.
553    19 | GRAPH/BAR=MEAN(x) BY y BY **.
554       |                           ^~"
555
556 "graph.sps:20.19-20.29: error: GRAPH: Only one chart type is allowed.
557    20 | GRAPH/HISTOGRAM=x/SCATTERPLOT=y.
558       |                   ^~~~~~~~~~~"
559
560 "graph.sps:21.19-21.25: error: GRAPH: OVERLAY is not yet implemented.
561    21 | GRAPH/SCATTERPLOT(OVERLAY).
562       |                   ^~~~~~~"
563
564 "graph.sps:22.19-22.24: error: GRAPH: MATRIX is not yet implemented.
565    22 | GRAPH/SCATTERPLOT(MATRIX).
566       |                   ^~~~~~"
567
568 "graph.sps:23.19-23.21: error: GRAPH: XYZ is not yet implemented.
569    23 | GRAPH/SCATTERPLOT(XYZ).
570       |                   ^~~"
571
572 "graph.sps:24.19-24.20: error: GRAPH: Syntax error expecting BIVARIATE, OVERLAY, MATRIX, or XYZ.
573    24 | GRAPH/SCATTERPLOT(**).
574       |                   ^~"
575
576 "graph.sps:25.29-25.30: error: GRAPH: Syntax error expecting `)'.
577    25 | GRAPH/SCATTERPLOT(BIVARIATE **).
578       |                             ^~"
579
580 "graph.sps:26.19-26.20: error: GRAPH: Syntax error expecting `='.
581    26 | GRAPH/SCATTERPLOT **.
582       |                   ^~"
583
584 "graph.sps:27.19-27.20: error: GRAPH: Syntax error expecting variable name.
585    27 | GRAPH/SCATTERPLOT=**.
586       |                   ^~"
587
588 "graph.sps:28.19-28.23: error: GRAPH: Only one variable is allowed.
589    28 | GRAPH/SCATTERPLOT=x y z.
590       |                   ^~~~~"
591
592 "graph.sps:29.21-29.22: error: GRAPH: Syntax error expecting `WITH'.
593    29 | GRAPH/SCATTERPLOT=x **.
594       |                     ^~"
595
596 "graph.sps:30.26-30.27: error: GRAPH: Syntax error expecting variable name.
597    30 | GRAPH/SCATTERPLOT=x WITH **.
598       |                          ^~"
599
600 "graph.sps:31.26-31.28: error: GRAPH: Only one variable is allowed.
601    31 | GRAPH/SCATTERPLOT=x WITH y z.
602       |                          ^~~"
603
604 "graph.sps:32.31-32.32: error: GRAPH: Syntax error expecting variable name.
605    32 | GRAPH/SCATTERPLOT=x WITH y BY **.
606       |                               ^~"
607
608 "graph.sps:33.7-33.10: error: GRAPH: LINE is not yet implemented.
609    33 | GRAPH/LINE.
610       |       ^~~~"
611
612 "graph.sps:34.7-34.9: error: GRAPH: PIE is not yet implemented.
613    34 | GRAPH/PIE.
614       |       ^~~"
615
616 "graph.sps:35.7-35.14: error: GRAPH: ERRORBAR is not yet implemented.
617    35 | GRAPH/ERRORBAR.
618       |       ^~~~~~~~"
619
620 "graph.sps:36.7-36.12: error: GRAPH: PARETO is not yet implemented.
621    36 | GRAPH/PARETO.
622       |       ^~~~~~"
623
624 "graph.sps:37.7-37.11: error: GRAPH: TITLE is not yet implemented.
625    37 | GRAPH/TITLE.
626       |       ^~~~~"
627
628 "graph.sps:38.7-38.14: error: GRAPH: SUBTITLE is not yet implemented.
629    38 | GRAPH/SUBTITLE.
630       |       ^~~~~~~~"
631
632 "graph.sps:39.7-39.14: error: GRAPH: FOOTNOTE is not yet implemented.
633    39 | GRAPH/FOOTNOTE.
634       |       ^~~~~~~~"
635
636 "graph.sps:40.15-40.16: error: GRAPH: Syntax error expecting LISTWISE, VARIABLE, EXCLUDE, INCLUDE, REPORT, or NOREPORT.
637    40 | GRAPH/MISSING=**.
638       |               ^~"
639
640 "graph.sps:41.8-41.9: error: GRAPH: Syntax error expecting one of the following: HISTOGRAM, BAR, SCATTERPLOT, LINE, PIE, ERRORBAR, PARETO, TITLE, SUBTITLE, FOOTNOTE, MISSING.
641    41 | GRAPH/ **.
642       |        ^~"
643 ])
644 AT_CLEANUP