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