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