3 # This program tests the RANK command.
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
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`
14 PSPP=$top_builddir/src/ui/terminal/pspp
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
25 if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then
26 echo "NOT cleaning $TEMPDIR"
62 # Some tests for proper behaviour in the face of invalid input.
63 activity="create file 1"
65 DATA LIST LIST NOTABLE /x * a (a2).
81 if [ $? -ne 0 ] ; then no_result ; fi
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
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.
93 if [ $? -ne 0 ] ; then fail ; fi
96 #Now for some general error conditions.
97 activity="create file 2"
99 DATA LIST LIST NOTABLE /x * a (a2).
110 * invalid NTILES (no parameter)
115 * invalid NTILES (not an integer)
121 * destination variable already exists
126 * Too many variables in INTO
128 /RANK INTO foo bar wiz.
130 if [ $? -ne 0 ] ; then no_result ; fi
133 activity="run program (syntax errors)"
134 $SUPERVISOR $PSPP -o pspp.csv -e $TEMPDIR/errs $TESTFILE
135 if [ $? -ne 1 ] ; then fail ; fi
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 expecting \`(' at end of command.
141 $TEMPDIR/rank.sh.sps:19: error: RANK: Syntax error expecting integer at \`d'.
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.
145 if [ $? -ne 0 ] ; then fail ; fi
147 # Now some real tests.
149 activity="create file 3"
150 cat > $TESTFILE <<EOF
151 DATA LIST LIST NOTABLE /x (f8).
162 ECHO 'Simple example using defaults'.
169 DATA LIST LIST NOTABLE /a * b *.
196 ECHO 'Test variable name fallback'.
199 DATA LIST LIST NOTABLE /foo * rfoo * ran003 *.
220 DATA LIST LIST NOTABLE /a * b *.
247 DATA LIST LIST NOTABLE /a * g1 g2 *.
294 ECHO 'fractional ranks ( including small ones for special case of SAVAGE ranks)'
296 DATA LIST LIST NOTABLE /a * w * .
319 ECHO 'test all the ties cases with low caseweight values'.
322 DATA LIST LIST NOTABLE /x * w *.
358 if [ $? -ne 0 ] ; then no_result ; fi
361 activity="run program 3"
362 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
363 if [ $? -ne 0 ] ; then no_result ; fi
366 activity="compare output 3"
367 diff -c $TEMPDIR/pspp.csv - <<EOF
368 Simple example using defaults
370 Variables Created By RANK
386 Variables Created By RANK
394 a into RFR001(RFRACTION of a)
396 b into RFR002(RFRACTION of b)
402 Variable,Description,,Position
405 ,Display Alignment: Right,,
409 ,Display Alignment: Right,,
414 ,Display Alignment: Right,,
419 ,Display Alignment: Right,,
424 ,Display Alignment: Right,,
426 RFR001,RFRACTION of a,,6
429 ,Display Alignment: Right,,
431 RFR002,RFRACTION of b,,7
434 ,Display Alignment: Right,,
439 ,Display Alignment: Right,,
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
455 Test variable name fallback
457 Variables Created By RANK
461 foo into RAN001(RANK of foo)
463 Variable,Description,,Position
466 ,Display Alignment: Right,,
470 ,Display Alignment: Right,,
472 ran003,Format: F8.2,,3
474 ,Display Alignment: Right,,
476 RAN001,RANK of foo,,4
479 ,Display Alignment: Right,,
482 Variables Created By RANK
486 a into Sa(SAVAGE of a)
488 a into Pa(PERCENT of a)
490 a into PRO001(PROPORTION of a using BLOM)
492 a into Na(NTILES of a)
494 a into NOR001(NORMAL of a using BLOM)
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
509 Variables Created By RANK
513 a into Ra(RANK of a BY g2 g1)
515 a into Na(NORMAL of a using RANKIT BY g2 g1)
517 Variables Created By RANK
521 a into RAN001(RANK of a BY g2)
523 a into NOR001(NORMAL of a using RANKIT BY g2)
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
546 fractional ranks ( including small ones for special case of SAVAGE ranks)
548 Variables Created By RANK
552 a into Pa(PROPORTION of a using TUKEY)
554 a into Sa(SAVAGE of a)
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
567 test all the ties cases with low caseweight values
569 Variables Created By RANK
575 Variables Created By RANK
581 Variables Created By RANK
587 Variables Created By RANK
591 x into Nx(NORMAL of x using VW)
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
604 if [ $? -ne 0 ] ; then fail ; fi
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.
624 DELETE VAR ran001 TO ran999.
629 if [ $? -ne 0 ] ; then no_result ; fi
631 activity="run program 4"
632 $SUPERVISOR $PSPP -o pspp.csv -e /dev/null $TESTFILE
633 if [ $? -ne 0 ] ; then fail ; fi
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."
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."
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."
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."
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."
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."
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."
652 Variables Created By RANK
656 x into RNKRA01(RANK of x)
668 if [ $? -ne 0 ] ; then fail ; fi