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