Fix missing @clicksequence problem with older Texinfo versions.
[pspp-builds.git] / 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
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 -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 --testing-mode -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 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.
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 --testing-mode $TESTFILE
363 if [ $? -ne 0 ] ; then no_result ; fi
364
365
366 activity="compare output 3"
367 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
368 diff  -b $TEMPDIR/pspp.list - <<EOF
369 Simple example using defaults
370 Variables Created By RANK
371 x into Rx(RANK of x)
372        x        Rx
373 -------- ---------
374       -1     1.000 
375        0     2.000 
376        1     3.000 
377        2     4.500 
378        2     4.500 
379        4     6.000 
380        5     7.000 
381 Variables Created By RANK
382 a into Ra(RANK of a)
383 b into Rb(RANK of b)
384 a into RFR001(RFRACTION of a)
385 b into RFR002(RFRACTION of b)
386 a into count(N of a)
387 b into Nb(N of b)
388 1.1 DISPLAY.  
389 +--------+-------------------------------------------+--------+
390 |Variable|Description                                |Position|
391 #========#===========================================#========#
392 |a       |Format: F8.2                               |       1|
393 |        |Measure: Scale                             |        |
394 |        |Display Alignment: Right                   |        |
395 |        |Display Width: 8                           |        |
396 +--------+-------------------------------------------+--------+
397 |b       |Format: F8.2                               |       2|
398 |        |Measure: Scale                             |        |
399 |        |Display Alignment: Right                   |        |
400 |        |Display Width: 8                           |        |
401 +--------+-------------------------------------------+--------+
402 |count   |N of a                                     |       3|
403 |        |Format: F6.0                               |        |
404 |        |Measure: Scale                             |        |
405 |        |Display Alignment: Right                   |        |
406 |        |Display Width: 8                           |        |
407 +--------+-------------------------------------------+--------+
408 |Ra      |RANK of a                                  |       4|
409 |        |Format: F9.3                               |        |
410 |        |Measure: Scale                             |        |
411 |        |Display Alignment: Right                   |        |
412 |        |Display Width: 8                           |        |
413 +--------+-------------------------------------------+--------+
414 |Rb      |RANK of b                                  |       5|
415 |        |Format: F9.3                               |        |
416 |        |Measure: Scale                             |        |
417 |        |Display Alignment: Right                   |        |
418 |        |Display Width: 8                           |        |
419 +--------+-------------------------------------------+--------+
420 |RFR001  |RFRACTION of a                             |       6|
421 |        |Format: F6.4                               |        |
422 |        |Measure: Scale                             |        |
423 |        |Display Alignment: Right                   |        |
424 |        |Display Width: 8                           |        |
425 +--------+-------------------------------------------+--------+
426 |RFR002  |RFRACTION of b                             |       7|
427 |        |Format: F6.4                               |        |
428 |        |Measure: Scale                             |        |
429 |        |Display Alignment: Right                   |        |
430 |        |Display Width: 8                           |        |
431 +--------+-------------------------------------------+--------+
432 |Nb      |N of b                                     |       8|
433 |        |Format: F6.0                               |        |
434 |        |Measure: Scale                             |        |
435 |        |Display Alignment: Right                   |        |
436 |        |Display Width: 8                           |        |
437 +--------+-------------------------------------------+--------+
438        a        b  count        Ra        Rb RFR001 RFR002     Nb
439 -------- -------- ------ --------- --------- ------ ------ ------
440      .00    24.00     10    10.000     8.000 1.0000  .8889      9 
441     1.00    32.00     10     9.000     4.000  .9000  .4444      9 
442     2.00    31.00     10     8.000     5.000  .8000  .5556      9 
443     2.00    32.00     10     8.000     4.000  .8000  .4444      9 
444     4.00    30.00     10     6.000     6.000  .6000  .6667      9 
445     5.00    29.00     10     5.000     7.000  .5000  .7778      9 
446     6.00     1.00     10     4.000     9.000  .4000 1.0000      9 
447     7.00    43.00     10     3.000     2.000  .3000  .2222      9 
448     8.00      .       10     2.000      .     .2000  .          . 
449     9.00    45.00     10     1.000     1.000  .1000  .1111      9 
450 Test variable name fallback
451 Variables Created By RANK
452 foo into RAN001(RANK of foo)
453 2.1 DISPLAY.  
454 +--------+-------------------------------------------+--------+
455 |Variable|Description                                |Position|
456 #========#===========================================#========#
457 |foo     |Format: F8.2                               |       1|
458 |        |Measure: Scale                             |        |
459 |        |Display Alignment: Right                   |        |
460 |        |Display Width: 8                           |        |
461 +--------+-------------------------------------------+--------+
462 |rfoo    |Format: F8.2                               |       2|
463 |        |Measure: Scale                             |        |
464 |        |Display Alignment: Right                   |        |
465 |        |Display Width: 8                           |        |
466 +--------+-------------------------------------------+--------+
467 |ran003  |Format: F8.2                               |       3|
468 |        |Measure: Scale                             |        |
469 |        |Display Alignment: Right                   |        |
470 |        |Display Width: 8                           |        |
471 +--------+-------------------------------------------+--------+
472 |RAN001  |RANK of foo                                |       4|
473 |        |Format: F9.3                               |        |
474 |        |Measure: Scale                             |        |
475 |        |Display Alignment: Right                   |        |
476 |        |Display Width: 8                           |        |
477 +--------+-------------------------------------------+--------+
478 Variables Created By RANK
479 a into Sa(SAVAGE of a)
480 a into Pa(PERCENT of a)
481 a into PRO001(PROPORTION of a using BLOM)
482 a into Na(NTILES of a)
483 a into NOR001(NORMAL of a using BLOM)
484        a        b       Sa     Pa PRO001  Na NOR001
485 -------- -------- -------- ------ ------ --- ------
486      .00    24.00   -.9000  10.00  .0610   1 -1.547 
487     1.00    32.00   -.7889  20.00  .1585   1 -1.000 
488     2.00    31.00   -.5925  30.00  .2561   2 -.6554 
489     2.00    32.00   -.5925  30.00  .2561   2 -.6554 
490     4.00    30.00   -.3544  40.00  .3537   2 -.3755 
491     5.00    29.00   -.1544  50.00  .4512   2 -.1226 
492     6.00     1.00    .0956  60.00  .5488   3  .1226 
493     7.00    43.00    .4290  70.00  .6463   3  .3755 
494     8.00     8.00    .9290  80.00  .7439   3  .6554 
495     9.00    45.00   1.9290  90.00  .8415   4 1.0005 
496 Variables Created By RANK
497 a into Ra(RANK of a BY g2 g1)
498 a into Na(NORMAL of a using RANKIT BY g2 g1)
499 Variables Created By RANK
500 a into RAN001(RANK of a BY g2)
501 a into NOR001(NORMAL of a using RANKIT BY g2)
502        a       g1       g2        Ra     Na    RAN001 NOR001 
503 -------- -------- -------- --------- ------ --------- ------ 
504     2.00     1.00     2.00     8.000  .9674     4.000  .5244  
505     2.00     1.00     2.00     8.000  .9674     4.000  .5244  
506     3.00     1.00     2.00     7.000  .5895     3.000  .0000  
507     4.00     1.00     2.00     6.000  .2822     2.000 -.5244  
508     5.00     1.00     2.00     5.000  .0000     1.000 -1.282  
509     1.00      .00     2.00     8.000 1.5341     8.000 1.5341  
510     2.00      .00     2.00     7.000  .8871     7.000  .8871  
511     3.00      .00     2.00     6.000  .4888     6.000  .4888  
512     4.00      .00     2.00     5.000  .1573     5.000  .1573  
513     5.00      .00     2.00     4.000 -.1573     4.000 -.1573  
514     6.00      .00     2.00     3.000 -.4888     3.000 -.4888  
515     7.00      .00     2.00     2.000 -.8871     2.000 -.8871  
516     8.00      .00     2.00     1.000 -1.534     1.000 -1.534  
517     6.00     1.00     2.00     4.000 -.2822     4.000 1.1503  
518     7.00     1.00     2.00     2.000 -.9674     2.000 -.3186  
519     7.00     1.00     2.00     2.000 -.9674     2.000 -.3186  
520     8.00     1.00     2.00     1.000 -1.593     1.000 -1.150  
521     9.00     1.00     1.00     1.000  .0000     1.000  .0000  
522 fractional ranks ( including small ones for special case of SAVAGE ranks)
523 Variables Created By RANK
524 a into Pa(PROPORTION of a using TUKEY)
525 a into Sa(SAVAGE of a)
526        a        w     Pa       Sa
527 -------- -------- ------ --------
528     1.00     1.50  .1285   -.8016 
529     2.00      .20  .1776   -.6905 
530     3.00      .10  .1986   -.6905 
531     4.00     1.00  .3458   -.5305 
532     5.00     1.00  .4860   -.2905 
533     6.00     1.00  .6262    .0262 
534     7.00     1.00  .7664    .4929 
535     8.00     1.00  .9065   1.3929 
536 test all the ties cases with low caseweight values
537 Variables Created By RANK
538 x into xl(RANK of x)
539 Variables Created By RANK
540 x into xh(RANK of x)
541 Variables Created By RANK
542 x into xc(RANK of x)
543 Variables Created By RANK
544 x into Nx(NORMAL of x using VW)
545        x        w        xl        xh        xc     Nx
546 -------- -------- --------- --------- --------- ------
547     1.00      .10      .000      .100     1.000 -1.938 
548     2.00      .10      .100      .200     2.000 -1.412 
549     3.00      .10      .200      .300     3.000 -1.119 
550     4.00      .20      .300      .500     4.000 -.8046 
551     5.00      .10      .500      .600     5.000 -.5549 
552     6.00      .10      .600      .700     6.000 -.4067 
553     7.00      .10      .700      .800     7.000 -.2670 
554     8.00      .10      .800      .900     8.000 -.1323 
555 EOF
556 if [ $? -ne 0 ] ; then fail ; fi
557
558
559
560 # A test to make sure that variable name creation is really robust
561 activity="create file 4"
562 cat > $TESTFILE <<EOF
563 DATA LIST LIST notable /x * rx * ran001 TO ran999.
564 BEGIN DATA.
565 1
566 2
567 3
568 4
569 5
570 6
571 7
572 END DATA.
573
574 RANK x.
575
576 DELETE VAR ran001 TO ran999.
577
578 LIST.
579
580 EOF
581 if [ $? -ne 0 ] ; then no_result ; fi
582
583 activity="run program 4"
584 $SUPERVISOR $PSPP --testing-mode -e /dev/null $TESTFILE 
585 if [ $? -ne 0 ] ; then fail ; fi
586
587
588 activity="compare output 4"
589 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
590 diff  -b $TEMPDIR/pspp.list - << EOF
591 $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.
592 $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.
593 $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.
594 $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.
595 $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.
596 $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.
597 $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.
598 Variables Created By RANK
599 x into RNKRA01(RANK of x)
600        x       rx   RNKRA01
601 -------- -------- ---------
602     1.00      .       1.000 
603     2.00      .       2.000 
604     3.00      .       3.000 
605     4.00      .       4.000 
606     5.00      .       5.000 
607     6.00      .       6.000 
608     7.00      .       7.000 
609 EOF
610 if [ $? -ne 0 ] ; then fail ; fi
611
612 pass;