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