5fc6f82cc4118bac91b8050944e3917cb871157c
[pspp] / tests / language / stats / 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_DATA([scatterlong.sps],[
45 NEW FILE.
46 INPUT PROGRAM.
47 LOOP #i = 1 to 10000.
48 COMPUTE Age = RV.NORMAL(40,10).
49 COMPUTE CityNum = TRUNC(UNIFORM(2.95)).
50 END CASE.
51 END LOOP.
52 END FILE.
53 END INPUT PROGRAM.
54
55 COMPUTE Size = Age * 3 + 50 + 50*CityNum.
56
57 STRING City (a20).
58
59 Recode CityNum 
60        (0 = "Madrid")
61        (1 = "Paris")
62        (ELSE = "Stockholm")
63        into City.
64
65  GRAPH
66     /SCATTERPLOT(BIVARIATE) = Age WITH Size 
67
68  GRAPH
69     /SCATTERPLOT(BIVARIATE) = Age WITH CityNum
70  
71  GRAPH
72     /SCATTERPLOT = CityNum WITH Age
73
74  GRAPH
75     /SCATTERPLOT = CityNum WITH Size
76
77  GRAPH
78     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY City
79
80  GRAPH
81     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY CityNum
82
83  ADD VALUE LABELS 
84     /CityNum 1 'Rio' 2 'Tokyo' 0 'Mumbai'.
85
86  GRAPH
87     /SCATTERPLOT(BIVARIATE) = Age WITH Size BY CityNum
88
89  GRAPH
90     /HISTOGRAM = Age.
91
92 ])
93
94 AT_CHECK([pspp -O format=pdf scatterlong.sps], [0], [ignore])
95 AT_CLEANUP
96
97 AT_SETUP([GRAPH missing values don't crash])
98 AT_DATA([scatter.sps], [dnl
99 data list list /x * y *.
100 begin data.
101 1 0
102 2 0
103 . 0
104 3 1
105 4 1
106 5 .
107 6 1
108 end data.
109 graph 
110       /scatterplot = x with y.
111 graph
112       /histogram = x. 
113 ])
114 AT_CHECK([pspp -o pspp.pdf scatter.sps])
115 dnl Ignore output -- this is just a no-crash check.
116 AT_CLEANUP
117
118 AT_SETUP([GRAPH missing=VARIABLE no crash])
119 AT_DATA([scatter.sps], [dnl
120 data list list /x * y *.
121 begin data.
122 1 0
123 2 0
124 . 0
125 3 1
126 4 1
127 5 .
128 6 1
129 end data.
130 graph 
131       /scatterplot = x with y
132       /missing = VARIABLE.
133 graph
134       /histogram = x
135       /missing = VARIABLE.
136 ])
137 AT_CHECK([pspp -o pspp.pdf scatter.sps])
138 dnl Ignore output -- this is just a no-crash check.
139 AT_CLEANUP
140
141 AT_SETUP([GRAPH missing value in by variable])
142 AT_DATA([scatter.sps], [dnl
143 data list list /x * y * z *.
144 begin data.
145 1 0 9
146 2 0 9
147 . 0 9
148 3 1 .
149 4 1 8
150 5 . 8
151 6 1 8
152 end data.
153 graph 
154       /scatterplot = x with y by z
155       /missing = VARIABLE.
156
157 graph 
158       /scatterplot = x with y by z.
159
160 ])
161 AT_CHECK([pspp -o pspp.pdf scatter.sps])
162 dnl Ignore output -- this is just a no-crash check.
163 AT_CLEANUP
164
165
166 AT_SETUP([GRAPH histogram with null data])
167 AT_DATA([null-hist.sps], [dnl
168 data list list /x *.
169 begin data.
170 1109 
171
172 end data.
173
174 graph 
175       /histogram = x.
176
177 ])
178
179 AT_CHECK([pspp -o pspp.pdf null-hist.sps], [0], [ignore])
180 dnl Ignore output -- this is just a no-crash check.
181 AT_CLEANUP
182
183
184 AT_SETUP([GRAPH histogram all missing])
185 AT_DATA([null-hist.sps], [dnl
186 data list list /x *.
187 begin data.
188
189 end data.
190
191 graph 
192       /histogram = x.
193
194 ])
195
196 AT_CHECK([pspp null-hist.sps], [0], [ignore])
197 dnl Ignore output -- this is just a no-crash check.
198 AT_CLEANUP
199
200
201
202
203 AT_SETUP([GRAPH barcharts])
204 AT_CHECK([ln -s $top_srcdir/examples/physiology.sav .], [0])
205 AT_CHECK([ln -s $top_srcdir/examples/repairs.sav .], [0])
206
207 AT_DATA([barchart.sps], [dnl
208 GET FILE="physiology.sav".
209
210 GRAPH /BAR = COUNT BY SEX.
211
212 GRAPH /BAR = MEAN(height) BY SEX.
213
214 NEW FILE.
215
216 GET FILE="repairs.sav".
217
218 GRAPH /BAR = MEAN (mtbf) BY factory.
219
220 COMPUTE  R = TRUNC(RV.UNIFORM(1,5)).
221
222 GRAPH /BAR = MEAN (mtbf) BY factory BY R.
223 ])
224
225 AT_CHECK([pspp -o pspp.pdf barchart.sps], [0], [ignore])
226 dnl Ignore output -- this is just a no-crash check.
227
228 AT_CLEANUP
229
230
231
232 AT_SETUP([GRAPH barchart arity])
233
234 AT_DATA([barchart.sps], [dnl
235 data list notable list /x y z*.
236 begin data
237 1  1  3
238 2  1  4
239 3  1  3
240 4  1  4
241 5  .  3
242 6  2  4
243 7  2  3
244 8  2  4
245 9  2  3
246 10  2  4
247 end data.
248
249 * This line is invalid
250 GRAPH /BAR = COUNT(x) BY y.
251 ])
252
253 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
254 dnl Ignore output -- this is just a no-crash check.
255
256 AT_CLEANUP
257
258
259
260
261 AT_SETUP([GRAPH barchart bad syntax])
262
263 AT_DATA([barchart.sps], [dnl
264 data list notable list /x y z*.
265 begin data
266 1  1  3
267 2  1  4
268 3  1  3
269 4  1  4
270 5  .  3
271 6  2  4
272 7  2  3
273 8  2  4
274 9  2  3
275 10  2  4
276 end data.
277
278 * This line is invalid
279 GRAPH /BAR = SCROD BY y.
280 ])
281
282 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
283 dnl Ignore output -- this is just a no-crash check.
284
285 AT_CLEANUP
286
287
288
289 AT_SETUP([GRAPH barchart full])
290
291 AT_DATA([barchart.sps], [dnl
292 data list notable list /x y z*.
293 begin data
294 1  1  3
295 2  1  4
296 3  1  3
297 4  1  4
298 5  .  3
299 6  2  4
300 7  2  3
301 8  2  4
302 9  2  3
303 10  2  4
304 end data.
305
306 * This line is invalid
307 GRAPH /BAR = COUNT by z.
308 GRAPH /BAR = CUFREQ by z.
309 GRAPH /BAR = PCT by z.
310 GRAPH /BAR = CUPCT by z.
311
312 GRAPH /BAR = MEAN(y) BY z.
313 GRAPH /BAR = SUM(y) BY z.
314 GRAPH /BAR = MAXIMUM(y) BY z.
315 GRAPH /BAR = MINIMUM(y) BY z.
316
317 GRAPH /BAR = MEAN(y) BY z BY y.
318 GRAPH /BAR = SUM(y) BY z BY y.
319 GRAPH /BAR = MAXIMUM(y) BY z BY y.
320 GRAPH /BAR = MINIMUM(y) BY z BY y.
321 ])
322
323 AT_CHECK([pspp -o pspp.pdf barchart.sps], [0], [ignore])
324 dnl Ignore output -- this is just a no-crash check.
325
326 AT_CLEANUP
327
328
329
330
331
332 AT_SETUP([GRAPH buggy syntax])
333
334 AT_DATA([barchart.sps], [dnl
335 data list notable list /x y z*.
336 begin data
337 1  1  3
338 2  1  4
339 10  2  4
340 end data.
341
342 GRAPH /BAR = MINIMUM({) BY z BY y.
343 ])
344
345 AT_CHECK([pspp -o pspp.pdf barchart.sps], [1], [ignore])
346 dnl Ignore output -- this is just a no-crash check.
347
348 AT_CLEANUP