b16cd58b95978830a192c115dda0c584ed842b38
[pspp-builds.git] / tests / stats / percentiles-compatible.sh
1 #! /bin/sh
2
3 # Tests calculation of percentiles with the 
4 # COMPATIBLE algorithm set.
5
6 TEMPDIR=/tmp/pspp-tst-$$
7
8 here=`pwd`;
9
10 # ensure that top_srcdir is absolute
11 cd $top_srcdir; top_srcdir=`pwd`
12
13 export STAT_CONFIG_PATH=$top_srcdir/config
14
15
16 cleanup()
17 {
18      rm -rf $TEMPDIR
19      :
20 }
21
22
23 fail()
24 {
25     echo $activity
26     echo FAILED
27     cleanup;
28     exit 1;
29 }
30
31
32 no_result()
33 {
34     echo $activity
35     echo NO RESULT;
36     cleanup;
37     exit 2;
38 }
39
40 pass()
41 {
42     cleanup;
43     exit 0;
44 }
45
46 mkdir -p $TEMPDIR
47
48 cd $TEMPDIR
49
50
51 i=1;
52
53 activity="create program $i"
54 cat > $TEMPDIR/prog.sps <<EOF
55 DATA LIST LIST notable /X * .
56 BEGIN DATA.
57
58
59
60
61 5
62 END DATA.
63
64 FREQUENCIES 
65         VAR=x
66         /ALGORITHM=COMPATIBLE
67         /PERCENTILES = 0 25 50 75 100
68
69 EOF
70 if [ $? -ne 0 ] ; then no_result; fi
71
72 activity="run program $i"
73 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
74 if [ $? -ne 0 ] ; then no_result ; fi
75
76 activity="compare output $i"
77 diff -B -b $TEMPDIR/pspp.list - <<EOF
78 1.1 FREQUENCIES.  X: 
79 +-----------+--------+---------+--------+--------+--------+
80 |           |        |         |        |  Valid |   Cum  |
81 |Value Label|  Value |Frequency| Percent| Percent| Percent|
82 #===========#========#=========#========#========#========#
83 |           |    1.00|        1|    20.0|    20.0|    20.0|
84 |           |    2.00|        1|    20.0|    20.0|    40.0|
85 |           |    3.00|        1|    20.0|    20.0|    60.0|
86 |           |    4.00|        1|    20.0|    20.0|    80.0|
87 |           |    5.00|        1|    20.0|    20.0|   100.0|
88 #===========#========#=========#========#========#========#
89 |               Total|        5|   100.0|   100.0|        |
90 +--------------------+---------+--------+--------+--------+
91
92 +-------------------+-----+
93 |N           Valid  |    5|
94 |            Missing|    0|
95 |Mean               |3.000|
96 |Std Dev            |1.581|
97 |Minimum            |1.000|
98 |Maximum            |5.000|
99 |Percentiles 0      |1.000|
100 |            25     |1.500|
101 |            50     |3.000|
102 |            75     |4.500|
103 |            100    |5.000|
104 +-------------------+-----+
105 EOF
106 if [ $? -ne 0 ] ; then fail ; fi
107
108 pass;