lexer: Reimplement for better testability and internationalization.
[pspp-builds.git] / tests / language / stats / rank.at
1 AT_BANNER([RANK])
2
3 AT_SETUP([RANK simple case with defaults])
4 AT_DATA([rank.sps], [dnl
5 DATA LIST LIST NOTABLE /x (f8).
6 BEGIN DATA.
7 -1
8
9
10
11
12
13
14 END DATA.
15
16 RANK x.
17
18 LIST.
19 ])
20 AT_CHECK([pspp -o pspp.csv rank.sps])
21 AT_CHECK([cat pspp.csv], [0], [dnl
22 Variables Created By RANK
23
24
25
26 x into Rx(RANK of x)
27
28 Table: Data List
29 x,Rx
30 -1,1.000
31 0,2.000
32 1,3.000
33 2,4.500
34 2,4.500
35 4,6.000
36 5,7.000
37 ])
38 AT_CLEANUP
39
40 AT_SETUP([RANK with RANK, RFRACTION, N])
41 AT_DATA([rank.sps], [dnl
42 DATA LIST LIST NOTABLE /a * b *.
43 BEGIN DATA.
44 0 24
45 1 32
46 2 31
47 2 32
48 4 30
49 5 29
50 6 1
51 7 43
52 8 .
53 9 45
54 END DATA.
55
56 RANK a b (D)
57    /PRINT=YES 
58    /RANK
59    /TIES=HIGH
60    /RFRACTION
61    /N INTO count
62    .
63
64 DISPLAY DICTIONARY.
65
66 LIST.
67 ])
68 AT_CHECK([pspp -o pspp.csv rank.sps])
69 AT_CHECK([cat pspp.csv], [0], [dnl
70 Variables Created By RANK
71
72
73
74 a into Ra(RANK of a)
75
76 b into Rb(RANK of b)
77
78 a into RFR001(RFRACTION of a)
79
80 b into RFR002(RFRACTION of b)
81
82 a into count(N of a)
83
84 b into Nb(N of b)
85
86 Variable,Description,,Position
87 a,Format: F8.2,,1
88 ,Measure: Scale,,
89 ,Display Alignment: Right,,
90 ,Display Width: 8,,
91 b,Format: F8.2,,2
92 ,Measure: Scale,,
93 ,Display Alignment: Right,,
94 ,Display Width: 8,,
95 count,N of a,,3
96 ,Format: F6.0,,
97 ,Measure: Scale,,
98 ,Display Alignment: Right,,
99 ,Display Width: 8,,
100 Ra,RANK of a,,4
101 ,Format: F9.3,,
102 ,Measure: Scale,,
103 ,Display Alignment: Right,,
104 ,Display Width: 8,,
105 Rb,RANK of b,,5
106 ,Format: F9.3,,
107 ,Measure: Scale,,
108 ,Display Alignment: Right,,
109 ,Display Width: 8,,
110 RFR001,RFRACTION of a,,6
111 ,Format: F6.4,,
112 ,Measure: Scale,,
113 ,Display Alignment: Right,,
114 ,Display Width: 8,,
115 RFR002,RFRACTION of b,,7
116 ,Format: F6.4,,
117 ,Measure: Scale,,
118 ,Display Alignment: Right,,
119 ,Display Width: 8,,
120 Nb,N of b,,8
121 ,Format: F6.0,,
122 ,Measure: Scale,,
123 ,Display Alignment: Right,,
124 ,Display Width: 8,,
125
126 Table: Data List
127 a,b,count,Ra,Rb,RFR001,RFR002,Nb
128 .00,24.00,10,10.000,8.000,1.0000,.8889,9
129 1.00,32.00,10,9.000,4.000,.9000,.4444,9
130 2.00,31.00,10,8.000,5.000,.8000,.5556,9
131 2.00,32.00,10,8.000,4.000,.8000,.4444,9
132 4.00,30.00,10,6.000,6.000,.6000,.6667,9
133 5.00,29.00,10,5.000,7.000,.5000,.7778,9
134 6.00,1.00,10,4.000,9.000,.4000,1.0000,9
135 7.00,43.00,10,3.000,2.000,.3000,.2222,9
136 8.00,.  ,10,2.000,.   ,.2000,.    ,.
137 9.00,45.00,10,1.000,1.000,.1000,.1111,9
138 ])
139 AT_CLEANUP
140
141 AT_SETUP([RANK with SAVAGE, PERCENT, PROPORTION, NTILES])
142 AT_DATA([rank.sps], [dnl
143 DATA LIST LIST NOTABLE /a * b *.
144 BEGIN DATA.
145 0 24
146 1 32
147 2 31
148 2 32
149 4 30
150 5 29
151 6 1
152 7 43
153 8 8 
154 9 45
155 END DATA.
156
157 RANK a
158   /PRINT=YES
159   /TIES=CONDENSE
160   /SAVAGE
161   /PERCENT
162   /PROPORTION
163   /NTILES(4)
164   /NORMAL
165 .
166
167 LIST.
168 ])
169 AT_CHECK([pspp -o pspp.csv rank.sps])
170 AT_CHECK([cat pspp.csv], [0], [dnl
171 Variables Created By RANK
172
173
174
175 a into Sa(SAVAGE of a)
176
177 a into Pa(PERCENT of a)
178
179 a into PRO001(PROPORTION of a using BLOM)
180
181 a into Na(NTILES of a)
182
183 a into NOR001(NORMAL of a using BLOM)
184
185 Table: Data List
186 a,b,Sa,Pa,PRO001,Na,NOR001
187 .00,24.00,-.9000,10.00,.0610,1,-1.547
188 1.00,32.00,-.7889,20.00,.1585,1,-1.000
189 2.00,31.00,-.5925,30.00,.2561,2,-.6554
190 2.00,32.00,-.5925,30.00,.2561,2,-.6554
191 4.00,30.00,-.3544,40.00,.3537,2,-.3755
192 5.00,29.00,-.1544,50.00,.4512,2,-.1226
193 6.00,1.00,.0956,60.00,.5488,3,.1226
194 7.00,43.00,.4290,70.00,.6463,3,.3755
195 8.00,8.00,.9290,80.00,.7439,3,.6554
196 9.00,45.00,1.9290,90.00,.8415,4,1.0005
197 ])
198 AT_CLEANUP
199
200 AT_SETUP([RANK with SPLIT FILE])
201 AT_DATA([rank.sps], [dnl
202 DATA LIST LIST NOTABLE /a * g1 g2 *.
203 BEGIN DATA.
204 2 1 2
205 2 1 2
206 3 1 2
207 4 1 2
208 5 1 2
209 1 0 2
210 2 0 2
211 3 0 2
212 4 0 2
213 5 0 2
214 6 0 2
215 7 0 2
216 8 0 2
217 6 1 2
218 7 1 2
219 7 1 2
220 8 1 2
221 9 1 1
222 END DATA.
223
224 RANK a (D) BY g2 g1
225   /PRINT=YES
226   /TIES=LOW
227   /MISSING=INCLUDE
228   /FRACTION=RANKIT
229   /RANK
230   /NORMAL
231   .
232
233 SPLIT FILE BY g1.
234
235 RANK a (D) BY g2
236   /PRINT=YES
237   /TIES=LOW
238   /MISSING=INCLUDE
239   /FRACTION=RANKIT
240   /RANK
241   /NORMAL
242   .
243
244 SPLIT FILE OFF.
245
246 LIST.
247 ])
248 AT_CHECK([pspp -o pspp.csv rank.sps])
249 AT_CHECK([cat pspp.csv], [0], [dnl
250 Variables Created By RANK
251
252
253
254 a into Ra(RANK of a BY g2 g1)
255
256 a into Na(NORMAL of a using RANKIT BY g2 g1)
257
258 Variables Created By RANK
259
260
261
262 a into RAN001(RANK of a BY g2)
263
264 a into NOR001(NORMAL of a using RANKIT BY g2)
265
266 Table: Data List
267 a,g1,g2,Ra,Na,RAN001,NOR001
268 2.00,1.00,2.00,8.000,.9674,4.000,.5244
269 2.00,1.00,2.00,8.000,.9674,4.000,.5244
270 3.00,1.00,2.00,7.000,.5895,3.000,.0000
271 4.00,1.00,2.00,6.000,.2822,2.000,-.5244
272 5.00,1.00,2.00,5.000,.0000,1.000,-1.282
273 1.00,.00,2.00,8.000,1.5341,8.000,1.5341
274 2.00,.00,2.00,7.000,.8871,7.000,.8871
275 3.00,.00,2.00,6.000,.4888,6.000,.4888
276 4.00,.00,2.00,5.000,.1573,5.000,.1573
277 5.00,.00,2.00,4.000,-.1573,4.000,-.1573
278 6.00,.00,2.00,3.000,-.4888,3.000,-.4888
279 7.00,.00,2.00,2.000,-.8871,2.000,-.8871
280 8.00,.00,2.00,1.000,-1.534,1.000,-1.534
281 6.00,1.00,2.00,4.000,-.2822,4.000,1.1503
282 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
283 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
284 8.00,1.00,2.00,1.000,-1.593,1.000,-1.150
285 9.00,1.00,1.00,1.000,.0000,1.000,.0000
286 ])
287 AT_CLEANUP
288
289 # Also tests small ranks for special case of SAVAGE ranks.
290 AT_SETUP([RANK with fractional ranks]) 
291 AT_DATA([rank.sps], [dnl
292 DATA LIST LIST NOTABLE  /a *  w * .
293 BEGIN DATA.
294 1 1.5
295 2 0.2
296 3 0.1
297 4 1
298 5 1
299 6 1
300 7 1
301 8 1
302 END DATA.
303
304 WEIGHT BY w.
305
306 RANK a 
307   /FRACTION=TUKEY
308   /PROPORTION
309   /SAVAGE
310 .
311
312 LIST.
313 ])
314 AT_CHECK([pspp -o pspp.csv rank.sps])
315 AT_CHECK([cat pspp.csv], [0], [dnl
316 Variables Created By RANK
317
318
319
320 a into Pa(PROPORTION of a using TUKEY)
321
322 a into Sa(SAVAGE of a)
323
324 Table: Data List
325 a,w,Pa,Sa
326 1.00,1.50,.1285,-.8016
327 2.00,.20,.1776,-.6905
328 3.00,.10,.1986,-.6905
329 4.00,1.00,.3458,-.5305
330 5.00,1.00,.4860,-.2905
331 6.00,1.00,.6262,.0262
332 7.00,1.00,.7664,.4929
333 8.00,1.00,.9065,1.3929
334 ])
335 AT_CLEANUP
336
337 AT_SETUP([RANK all-ties due to tiny weights])
338 AT_DATA([rank.sps], [dnl
339 DATA LIST LIST NOTABLE /x * w *.
340 BEGIN DATA.
341 1 0.1
342 2 0.1
343 3 0.1
344 4 0.2
345 5 0.1
346 6 0.1
347 7 0.1
348 8 0.1
349 END DATA.
350
351 WEIGHT BY w.
352
353 RANK x
354  /TIES=low
355  /RANK into xl.
356
357
358 RANK x
359  /TIES=high
360  /RANK into xh.
361
362 RANK x
363  /TIES=condense
364  /RANK into xc.
365
366
367 * Test VW fraction
368
369 RANK x
370  /FRACTION=VW
371  /NORMAL.
372
373 LIST.
374 ])
375 AT_CHECK([pspp -o pspp.csv rank.sps])
376 AT_CHECK([cat pspp.csv], [0], [dnl
377 Variables Created By RANK
378
379
380
381 x into xl(RANK of x)
382
383 Variables Created By RANK
384
385
386
387 x into xh(RANK of x)
388
389 Variables Created By RANK
390
391
392
393 x into xc(RANK of x)
394
395 Variables Created By RANK
396
397
398
399 x into Nx(NORMAL of x using VW)
400
401 Table: Data List
402 x,w,xl,xh,xc,Nx
403 1.00,.10,.000,.100,1.000,-1.938
404 2.00,.10,.100,.200,2.000,-1.412
405 3.00,.10,.200,.300,3.000,-1.119
406 4.00,.20,.300,.500,4.000,-.8046
407 5.00,.10,.500,.600,5.000,-.5549
408 6.00,.10,.600,.700,6.000,-.4067
409 7.00,.10,.700,.800,7.000,-.2670
410 8.00,.10,.800,.900,8.000,-.1323
411 ])
412 AT_CLEANUP
413
414 AT_SETUP([RANK variable name fallback])
415 AT_DATA([rank.sps], [dnl
416 DATA LIST LIST NOTABLE /foo * rfoo * ran003 *.
417 BEGIN DATA.
418 0 3 2
419 1 3 2
420 2 3 2
421 2 3 2
422 4 3 2
423 5 3 2
424 6 3 2
425 7 3 2
426 8 3 2
427 9 3 2
428 END DATA.
429
430 RANK foo.
431
432
433 DISPLAY DICTIONARY.
434 ])
435 AT_CHECK([pspp -o pspp.csv rank.sps])
436 AT_CHECK([cat pspp.csv], [0], [dnl
437 Variables Created By RANK
438
439
440
441 foo into RAN001(RANK of foo)
442
443 Variable,Description,,Position
444 foo,Format: F8.2,,1
445 ,Measure: Scale,,
446 ,Display Alignment: Right,,
447 ,Display Width: 8,,
448 rfoo,Format: F8.2,,2
449 ,Measure: Scale,,
450 ,Display Alignment: Right,,
451 ,Display Width: 8,,
452 ran003,Format: F8.2,,3
453 ,Measure: Scale,,
454 ,Display Alignment: Right,,
455 ,Display Width: 8,,
456 RAN001,RANK of foo,,4
457 ,Format: F9.3,,
458 ,Measure: Scale,,
459 ,Display Alignment: Right,,
460 ,Display Width: 8,,
461 ])
462 AT_CLEANUP
463
464 AT_SETUP([RANK robust variable name creation])
465 AT_DATA([rank.sps], [dnl
466 DATA LIST LIST notable /x * rx * ran001 TO ran999.
467 BEGIN DATA.
468 1
469 2
470 3
471 4
472 5
473 6
474 7
475 END DATA.
476
477 RANK x.
478
479 DELETE VAR ran001 TO ran999.
480
481 LIST.
482 ])
483 AT_CHECK([pspp -O format=csv rank.sps], [0], [dnl
484 "rank.sps:3: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
485
486 "rank.sps:4: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
487
488 "rank.sps:5: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
489
490 "rank.sps:6: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
491
492 "rank.sps:7: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
493
494 "rank.sps:8: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
495
496 "rank.sps:9: warning: BEGIN DATA: Missing value(s) for all variables from rx onward.  These will be filled with the system-missing value or blanks, as appropriate."
497
498 Variables Created By RANK
499
500
501
502 x into RNKRA01(RANK of x)
503
504 Table: Data List
505 x,rx,RNKRA01
506 1.00,.  ,1.000
507 2.00,.  ,2.000
508 3.00,.  ,3.000
509 4.00,.  ,4.000
510 5.00,.  ,5.000
511 6.00,.  ,6.000
512 7.00,.  ,7.000
513 ])
514 AT_CLEANUP
515
516 dnl Test for proper behaviour in the face of invalid input.
517 AT_SETUP([RANK handling of invalid input])
518 AT_DATA([rank.sps], [dnl
519 DATA LIST LIST NOTABLE /x * a (a2).
520 BEGIN DATA.
521 -1 s
522 0  s
523 1  s
524 2  s
525 2  s
526 4  s
527 5  s
528 END DATA.
529
530 DEBUG XFORM FAIL.
531
532 RANK x.
533 ])
534 AT_CHECK([pspp -O format=csv --testing-mode rank.sps], [1], [dnl
535 Variables Created By RANK
536
537
538
539 x into Rx(RANK of x)
540
541 rank.sps:14: error: RANK: DEBUG XFORM FAIL transformation executed
542 ])
543 AT_CLEANUP
544
545 AT_SETUP([RANK handling of invalid syntax])
546 AT_DATA([rank.sps], [dnl
547 DATA LIST LIST NOTABLE /x * a (a2).
548 BEGIN DATA.
549 -1 s
550 0  s
551 1  s
552 2  s
553 2  s
554 4  s
555 5  s
556 END DATA.
557
558 * invalid NTILES (no parameter)
559 RANK x 
560   /NTILES
561 .
562
563 * invalid NTILES (not an integer)
564 RANK x 
565   /NTILES(d)
566 .
567
568
569 * destination variable already exists
570 RANK x 
571  /RANK INTO x.
572
573
574 * Too many variables in INTO
575 RANK x 
576  /RANK INTO foo  bar wiz.
577 ])
578 AT_CHECK([pspp -O format=csv rank.sps], [1], [dnl
579 rank.sps:15.1: error: RANK: Syntax error at end of command: expecting `@{:@'.
580
581 rank.sps:19.11: error: RANK: Syntax error at `d': expecting integer.
582
583 rank.sps:25: error: RANK: Variable x already exists.
584
585 rank.sps:30: error: RANK: Too many variables in INTO clause.
586 ])
587 AT_CLEANUP