lexer: Improve translatability of lex_error().
[pspp] / tests / command / rank.sh
1 #!/bin/sh
2
3 # This program tests the RANK command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp$EXEEXT
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61
62 # Some tests for proper behaviour in the face of invalid input.
63 activity="create file 1"
64 cat > $TESTFILE <<EOF
65 DATA LIST LIST NOTABLE /x * a (a2).
66 BEGIN DATA.
67 -1 s
68 0  s
69 1  s
70 2  s
71 2  s
72 4  s
73 5  s
74 END DATA.
75
76 DEBUG XFORM FAIL.
77
78 RANK x.
79
80 EOF
81 if [ $? -ne 0 ] ; then no_result ; fi
82
83 # Check that it properly handles failed transformations.
84 activity="run program 1"
85 $SUPERVISOR $PSPP --testing-mode -o pspp.csv -e $TEMPDIR/err $TESTFILE 
86 if [ $? -ne 1 ] ; then fail ; fi
87
88 activity="diff 1"
89 perl -pi -e 's/^\s*$//g' $TEMPDIR/err
90 diff  -b $TEMPDIR/err - <<EOF
91 $TEMPDIR/rank.sh.sps:14: error: Stopping syntax file processing here to avoid a cascade of dependent command failures.
92 EOF
93 if [ $? -ne 0 ] ; then fail ; fi
94
95
96 #Now for some general error conditions.
97 activity="create file 2"
98 cat > $TESTFILE <<EOF
99 DATA LIST LIST NOTABLE /x * a (a2).
100 BEGIN DATA.
101 -1 s
102 0  s
103 1  s
104 2  s
105 2  s
106 4  s
107 5  s
108 END DATA.
109
110 * invalid NTILES (no parameter)
111 RANK x 
112   /NTILES
113 .
114
115 * invalid NTILES (not an integer)
116 RANK x 
117   /NTILES(d)
118 .
119
120
121 * destination variable already exists
122 RANK x 
123  /RANK INTO x.
124
125
126 * Too many variables in INTO
127 RANK x 
128  /RANK INTO foo  bar wiz.
129 EOF
130 if [ $? -ne 0 ] ; then no_result ; fi
131
132
133 activity="run program (syntax errors)"
134 $SUPERVISOR $PSPP -o pspp.csv -e $TEMPDIR/errs $TESTFILE 
135 if [ $? -ne 1 ] ; then fail ; fi
136
137 activity="compare errors"
138 perl -pi -e 's/^\s*$//g' $TEMPDIR/errs
139 diff -b $TEMPDIR/errs - << EOF
140 $TEMPDIR/rank.sh.sps:15: error: RANK: Syntax error at end of command:  expecting \`('.
141 $TEMPDIR/rank.sh.sps:19: error: RANK: Syntax error at \`d':  expecting integer.
142 $TEMPDIR/rank.sh.sps:25: error: RANK: Variable x already exists.
143 $TEMPDIR/rank.sh.sps:30: error: RANK: Too many variables in INTO clause.
144 EOF
145 if [ $? -ne 0 ] ; then fail ; fi
146
147 # Now some real tests.
148
149 activity="create file 3"
150 cat > $TESTFILE <<EOF
151 DATA LIST LIST NOTABLE /x (f8).
152 BEGIN DATA.
153 -1
154
155
156
157
158
159
160 END DATA.
161
162 ECHO  'Simple example using defaults'.
163
164 RANK x.
165
166 LIST.
167
168 NEW FILE.
169 DATA LIST LIST NOTABLE /a * b *.
170 BEGIN DATA.
171 0 24
172 1 32
173 2 31
174 2 32
175 4 30
176 5 29
177 6 1
178 7 43
179 8 .
180 9 45
181 END DATA.
182
183 RANK a b (D)
184    /PRINT=YES 
185    /RANK
186    /TIES=HIGH
187    /RFRACTION
188    /N INTO count
189    .
190
191 DISPLAY DICTIONARY.
192
193 LIST.
194
195
196 ECHO  'Test variable name fallback'.
197
198 NEW FILE.
199 DATA LIST LIST NOTABLE /foo * rfoo * ran003 *.
200 BEGIN DATA.
201 0 3 2
202 1 3 2
203 2 3 2
204 2 3 2
205 4 3 2
206 5 3 2
207 6 3 2
208 7 3 2
209 8 3 2
210 9 3 2
211 END DATA.
212
213 RANK foo.
214
215
216 DISPLAY DICTIONARY.
217
218
219 NEW FILE.
220 DATA LIST LIST NOTABLE /a * b *.
221 BEGIN DATA.
222 0 24
223 1 32
224 2 31
225 2 32
226 4 30
227 5 29
228 6 1
229 7 43
230 8 8 
231 9 45
232 END DATA.
233
234 RANK a
235   /PRINT=YES
236   /TIES=CONDENSE
237   /SAVAGE
238   /PERCENT
239   /PROPORTION
240   /NTILES(4)
241   /NORMAL
242 .
243
244 LIST.
245
246 NEW FILE.
247 DATA LIST LIST NOTABLE /a * g1 g2 *.
248 BEGIN DATA.
249 2 1 2
250 2 1 2
251 3 1 2
252 4 1 2
253 5 1 2
254 1 0 2
255 2 0 2
256 3 0 2
257 4 0 2
258 5 0 2
259 6 0 2
260 7 0 2
261 8 0 2
262 6 1 2
263 7 1 2
264 7 1 2
265 8 1 2
266 9 1 1
267 END DATA.
268
269 RANK a (D) BY g2 g1
270   /PRINT=YES
271   /TIES=LOW
272   /MISSING=INCLUDE
273   /FRACTION=RANKIT
274   /RANK
275   /NORMAL
276   .
277
278 SPLIT FILE BY g1.
279
280 RANK a (D) BY g2
281   /PRINT=YES
282   /TIES=LOW
283   /MISSING=INCLUDE
284   /FRACTION=RANKIT
285   /RANK
286   /NORMAL
287   .
288
289 SPLIT FILE OFF.
290
291 LIST.
292
293
294 ECHO 'fractional ranks ( including small ones for special case of SAVAGE ranks)'
295 NEW FILE.
296 DATA LIST LIST NOTABLE  /a *  w * .
297 BEGIN DATA.
298 1 1.5
299 2 0.2
300 3 0.1
301 4 1
302 5 1
303 6 1
304 7 1
305 8 1
306 END DATA.
307
308 WEIGHT BY w.
309
310 RANK a 
311   /FRACTION=TUKEY
312   /PROPORTION
313   /SAVAGE
314 .
315
316 LIST.
317
318
319 ECHO 'test all the ties cases with low caseweight values'.
320
321 NEW FILE.
322 DATA LIST LIST NOTABLE /x * w *.
323 BEGIN DATA.
324 1 0.1
325 2 0.1
326 3 0.1
327 4 0.2
328 5 0.1
329 6 0.1
330 7 0.1
331 8 0.1
332 END DATA.
333
334 WEIGHT BY w.
335
336 RANK x
337  /TIES=low
338  /RANK into xl.
339
340
341 RANK x
342  /TIES=high
343  /RANK into xh.
344
345 RANK x
346  /TIES=condense
347  /RANK into xc.
348
349
350 * Test VW fraction
351
352 RANK x
353  /FRACTION=VW
354  /NORMAL.
355
356 LIST.
357 EOF
358 if [ $? -ne 0 ] ; then no_result ; fi
359
360
361 activity="run program 3"
362 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
363 if [ $? -ne 0 ] ; then no_result ; fi
364
365
366 activity="compare output 3"
367 diff -c $TEMPDIR/pspp.csv - <<EOF
368 Simple example using defaults
369
370 Variables Created By RANK
371
372
373
374 x into Rx(RANK of x)
375
376 Table: Data List
377 x,Rx
378 -1,1.000
379 0,2.000
380 1,3.000
381 2,4.500
382 2,4.500
383 4,6.000
384 5,7.000
385
386 Variables Created By RANK
387
388
389
390 a into Ra(RANK of a)
391
392 b into Rb(RANK of b)
393
394 a into RFR001(RFRACTION of a)
395
396 b into RFR002(RFRACTION of b)
397
398 a into count(N of a)
399
400 b into Nb(N of b)
401
402 Variable,Description,,Position
403 a,Format: F8.2,,1
404 ,Measure: Scale,,
405 ,Display Alignment: Right,,
406 ,Display Width: 8,,
407 b,Format: F8.2,,2
408 ,Measure: Scale,,
409 ,Display Alignment: Right,,
410 ,Display Width: 8,,
411 count,N of a,,3
412 ,Format: F6.0,,
413 ,Measure: Scale,,
414 ,Display Alignment: Right,,
415 ,Display Width: 8,,
416 Ra,RANK of a,,4
417 ,Format: F9.3,,
418 ,Measure: Scale,,
419 ,Display Alignment: Right,,
420 ,Display Width: 8,,
421 Rb,RANK of b,,5
422 ,Format: F9.3,,
423 ,Measure: Scale,,
424 ,Display Alignment: Right,,
425 ,Display Width: 8,,
426 RFR001,RFRACTION of a,,6
427 ,Format: F6.4,,
428 ,Measure: Scale,,
429 ,Display Alignment: Right,,
430 ,Display Width: 8,,
431 RFR002,RFRACTION of b,,7
432 ,Format: F6.4,,
433 ,Measure: Scale,,
434 ,Display Alignment: Right,,
435 ,Display Width: 8,,
436 Nb,N of b,,8
437 ,Format: F6.0,,
438 ,Measure: Scale,,
439 ,Display Alignment: Right,,
440 ,Display Width: 8,,
441
442 Table: Data List
443 a,b,count,Ra,Rb,RFR001,RFR002,Nb
444 .00,24.00,10,10.000,8.000,1.0000,.8889,9
445 1.00,32.00,10,9.000,4.000,.9000,.4444,9
446 2.00,31.00,10,8.000,5.000,.8000,.5556,9
447 2.00,32.00,10,8.000,4.000,.8000,.4444,9
448 4.00,30.00,10,6.000,6.000,.6000,.6667,9
449 5.00,29.00,10,5.000,7.000,.5000,.7778,9
450 6.00,1.00,10,4.000,9.000,.4000,1.0000,9
451 7.00,43.00,10,3.000,2.000,.3000,.2222,9
452 8.00,.  ,10,2.000,.   ,.2000,.    ,.
453 9.00,45.00,10,1.000,1.000,.1000,.1111,9
454
455 Test variable name fallback
456
457 Variables Created By RANK
458
459
460
461 foo into RAN001(RANK of foo)
462
463 Variable,Description,,Position
464 foo,Format: F8.2,,1
465 ,Measure: Scale,,
466 ,Display Alignment: Right,,
467 ,Display Width: 8,,
468 rfoo,Format: F8.2,,2
469 ,Measure: Scale,,
470 ,Display Alignment: Right,,
471 ,Display Width: 8,,
472 ran003,Format: F8.2,,3
473 ,Measure: Scale,,
474 ,Display Alignment: Right,,
475 ,Display Width: 8,,
476 RAN001,RANK of foo,,4
477 ,Format: F9.3,,
478 ,Measure: Scale,,
479 ,Display Alignment: Right,,
480 ,Display Width: 8,,
481
482 Variables Created By RANK
483
484
485
486 a into Sa(SAVAGE of a)
487
488 a into Pa(PERCENT of a)
489
490 a into PRO001(PROPORTION of a using BLOM)
491
492 a into Na(NTILES of a)
493
494 a into NOR001(NORMAL of a using BLOM)
495
496 Table: Data List
497 a,b,Sa,Pa,PRO001,Na,NOR001
498 .00,24.00,-.9000,10.00,.0610,1,-1.547
499 1.00,32.00,-.7889,20.00,.1585,1,-1.000
500 2.00,31.00,-.5925,30.00,.2561,2,-.6554
501 2.00,32.00,-.5925,30.00,.2561,2,-.6554
502 4.00,30.00,-.3544,40.00,.3537,2,-.3755
503 5.00,29.00,-.1544,50.00,.4512,2,-.1226
504 6.00,1.00,.0956,60.00,.5488,3,.1226
505 7.00,43.00,.4290,70.00,.6463,3,.3755
506 8.00,8.00,.9290,80.00,.7439,3,.6554
507 9.00,45.00,1.9290,90.00,.8415,4,1.0005
508
509 Variables Created By RANK
510
511
512
513 a into Ra(RANK of a BY g2 g1)
514
515 a into Na(NORMAL of a using RANKIT BY g2 g1)
516
517 Variables Created By RANK
518
519
520
521 a into RAN001(RANK of a BY g2)
522
523 a into NOR001(NORMAL of a using RANKIT BY g2)
524
525 Table: Data List
526 a,g1,g2,Ra,Na,RAN001,NOR001
527 2.00,1.00,2.00,8.000,.9674,4.000,.5244
528 2.00,1.00,2.00,8.000,.9674,4.000,.5244
529 3.00,1.00,2.00,7.000,.5895,3.000,.0000
530 4.00,1.00,2.00,6.000,.2822,2.000,-.5244
531 5.00,1.00,2.00,5.000,.0000,1.000,-1.282
532 1.00,.00,2.00,8.000,1.5341,8.000,1.5341
533 2.00,.00,2.00,7.000,.8871,7.000,.8871
534 3.00,.00,2.00,6.000,.4888,6.000,.4888
535 4.00,.00,2.00,5.000,.1573,5.000,.1573
536 5.00,.00,2.00,4.000,-.1573,4.000,-.1573
537 6.00,.00,2.00,3.000,-.4888,3.000,-.4888
538 7.00,.00,2.00,2.000,-.8871,2.000,-.8871
539 8.00,.00,2.00,1.000,-1.534,1.000,-1.534
540 6.00,1.00,2.00,4.000,-.2822,4.000,1.1503
541 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
542 7.00,1.00,2.00,2.000,-.9674,2.000,-.3186
543 8.00,1.00,2.00,1.000,-1.593,1.000,-1.150
544 9.00,1.00,1.00,1.000,.0000,1.000,.0000
545
546 fractional ranks ( including small ones for special case of SAVAGE ranks)
547
548 Variables Created By RANK
549
550
551
552 a into Pa(PROPORTION of a using TUKEY)
553
554 a into Sa(SAVAGE of a)
555
556 Table: Data List
557 a,w,Pa,Sa
558 1.00,1.50,.1285,-.8016
559 2.00,.20,.1776,-.6905
560 3.00,.10,.1986,-.6905
561 4.00,1.00,.3458,-.5305
562 5.00,1.00,.4860,-.2905
563 6.00,1.00,.6262,.0262
564 7.00,1.00,.7664,.4929
565 8.00,1.00,.9065,1.3929
566
567 test all the ties cases with low caseweight values
568
569 Variables Created By RANK
570
571
572
573 x into xl(RANK of x)
574
575 Variables Created By RANK
576
577
578
579 x into xh(RANK of x)
580
581 Variables Created By RANK
582
583
584
585 x into xc(RANK of x)
586
587 Variables Created By RANK
588
589
590
591 x into Nx(NORMAL of x using VW)
592
593 Table: Data List
594 x,w,xl,xh,xc,Nx
595 1.00,.10,.000,.100,1.000,-1.938
596 2.00,.10,.100,.200,2.000,-1.412
597 3.00,.10,.200,.300,3.000,-1.119
598 4.00,.20,.300,.500,4.000,-.8046
599 5.00,.10,.500,.600,5.000,-.5549
600 6.00,.10,.600,.700,6.000,-.4067
601 7.00,.10,.700,.800,7.000,-.2670
602 8.00,.10,.800,.900,8.000,-.1323
603 EOF
604 if [ $? -ne 0 ] ; then fail ; fi
605
606
607
608 # A test to make sure that variable name creation is really robust
609 activity="create file 4"
610 cat > $TESTFILE <<EOF
611 DATA LIST LIST notable /x * rx * ran001 TO ran999.
612 BEGIN DATA.
613 1
614 2
615 3
616 4
617 5
618 6
619 7
620 END DATA.
621
622 RANK x.
623
624 DELETE VAR ran001 TO ran999.
625
626 LIST.
627
628 EOF
629 if [ $? -ne 0 ] ; then no_result ; fi
630
631 activity="run program 4"
632 $SUPERVISOR $PSPP -o pspp.csv -e /dev/null $TESTFILE 
633 if [ $? -ne 0 ] ; then fail ; fi
634
635
636 activity="compare output 4"
637 diff -c $TEMPDIR/pspp.csv - << EOF
638 "$TEMPDIR/rank.sh.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."
639
640 "$TEMPDIR/rank.sh.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."
641
642 "$TEMPDIR/rank.sh.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."
643
644 "$TEMPDIR/rank.sh.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."
645
646 "$TEMPDIR/rank.sh.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."
647
648 "$TEMPDIR/rank.sh.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."
649
650 "$TEMPDIR/rank.sh.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."
651
652 Variables Created By RANK
653
654
655
656 x into RNKRA01(RANK of x)
657
658 Table: Data List
659 x,rx,RNKRA01
660 1.00,.  ,1.000
661 2.00,.  ,2.000
662 3.00,.  ,3.000
663 4.00,.  ,4.000
664 5.00,.  ,5.000
665 6.00,.  ,6.000
666 7.00,.  ,7.000
667 EOF
668 if [ $? -ne 0 ] ; then fail ; fi
669
670 pass;