df08f78239fc7e8e5bac936e01e56d76a8d2a3ba
[pspp-builds.git] / tests / stats / percentiles-enhanced.sh
1 #! /bin/sh
2
3 # Tests calculation of percentiles with the 
4 # ENHANCED 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 STAT_CONFIG_PATH=$top_srcdir/config
14 export STAT_CONFIG_PATH
15
16
17 cleanup()
18 {
19      cd /
20      rm -rf $TEMPDIR
21      :
22 }
23
24
25 fail()
26 {
27     echo $activity
28     echo FAILED
29     cleanup;
30     exit 1;
31 }
32
33
34 no_result()
35 {
36     echo $activity
37     echo NO RESULT;
38     cleanup;
39     exit 2;
40 }
41
42 pass()
43 {
44     cleanup;
45     exit 0;
46 }
47
48 mkdir -p $TEMPDIR
49
50 cd $TEMPDIR
51
52
53 i=1;
54
55 activity="create program $i"
56 cat > $TEMPDIR/prog.sps <<EOF
57 DATA LIST LIST notable /X * .
58 BEGIN DATA.
59
60
61
62
63 5
64 END DATA.
65
66 FREQUENCIES 
67         VAR=x
68         /PERCENTILES = 0 25 50 75 100
69
70 EOF
71 if [ $? -ne 0 ] ; then no_result; fi
72
73 activity="run program $i"
74 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
75 if [ $? -ne 0 ] ; then no_result ; fi
76
77 activity="compare output $i"
78 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
79 diff  -b $TEMPDIR/pspp.list - <<EOF
80 1.1 FREQUENCIES.  X: 
81 +-----------+--------+---------+--------+--------+--------+
82 |           |        |         |        |  Valid |   Cum  |
83 |Value Label|  Value |Frequency| Percent| Percent| Percent|
84 #===========#========#=========#========#========#========#
85 |           |    1.00|        1|    20.0|    20.0|    20.0|
86 |           |    2.00|        1|    20.0|    20.0|    40.0|
87 |           |    3.00|        1|    20.0|    20.0|    60.0|
88 |           |    4.00|        1|    20.0|    20.0|    80.0|
89 |           |    5.00|        1|    20.0|    20.0|   100.0|
90 #===========#========#=========#========#========#========#
91 |               Total|        5|   100.0|   100.0|        |
92 +--------------------+---------+--------+--------+--------+
93 +-------------------+-----+
94 |N           Valid  |    5|
95 |            Missing|    0|
96 |Mean               |3.000|
97 |Std Dev            |1.581|
98 |Minimum            |1.000|
99 |Maximum            |5.000|
100 |Percentiles 0      |1.000|
101 |            25     |2.000|
102 |            50     |3.000|
103 |            75     |4.000|
104 |            100    |5.000|
105 +-------------------+-----+
106 EOF
107 if [ $? -ne 0 ] ; then fail ; fi
108
109
110
111 i=$[$i+1];
112
113 activity="create program $i"
114 cat > $TEMPDIR/prog.sps <<EOF
115 DATA LIST LIST notable /X * F *.
116 BEGIN DATA.
117 1 2
118 2 2
119 3 2
120 4 1
121 4 1
122 5 1
123 5 1
124 END DATA.
125
126 WEIGHT BY f.
127
128 FREQUENCIES 
129         VAR=x
130         /PERCENTILES = 0 25 50 75 100
131
132 EOF
133 if [ $? -ne 0 ] ; then no_result; fi
134
135
136 activity="run program $i"
137 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
138 if [ $? -ne 0 ] ; then no_result ; fi
139
140 activity="compare output $i"
141 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
142 diff  -b $TEMPDIR/pspp.list - <<EOF
143 1.1 FREQUENCIES.  X: 
144 +-----------+--------+---------+--------+--------+--------+
145 |           |        |         |        |  Valid |   Cum  |
146 |Value Label|  Value |Frequency| Percent| Percent| Percent|
147 #===========#========#=========#========#========#========#
148 |           |    1.00|        2|    20.0|    20.0|    20.0|
149 |           |    2.00|        2|    20.0|    20.0|    40.0|
150 |           |    3.00|        2|    20.0|    20.0|    60.0|
151 |           |    4.00|        2|    20.0|    20.0|    80.0|
152 |           |    5.00|        2|    20.0|    20.0|   100.0|
153 #===========#========#=========#========#========#========#
154 |               Total|       10|   100.0|   100.0|        |
155 +--------------------+---------+--------+--------+--------+
156 +-------------------+-----+
157 |N           Valid  |   10|
158 |            Missing|    0|
159 |Mean               |3.000|
160 |Std Dev            |1.491|
161 |Minimum            |1.000|
162 |Maximum            |5.000|
163 |Percentiles 0      |1.000|
164 |            25     |2.000|
165 |            50     |3.000|
166 |            75     |4.000|
167 |            100    |5.000|
168 +-------------------+-----+
169 EOF
170 if [ $? -ne 0 ] ; then fail ; fi
171
172
173
174 i=$[$i+1];
175
176 activity="create program $i"
177 cat > $TEMPDIR/prog.sps <<EOF
178 DATA LIST LIST notable /X * F *.
179 BEGIN DATA.
180 1 1
181 3 2
182 4 1
183 5 1
184 5 1
185 END DATA.
186
187 WEIGHT BY f.
188
189 FREQUENCIES 
190         VAR=x
191         /PERCENTILES = 0 25 50 75 100
192
193 EOF
194 if [ $? -ne 0 ] ; then no_result; fi
195
196
197 activity="run program $i"
198 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
199 if [ $? -ne 0 ] ; then no_result ; fi
200
201 activity="compare output $i"
202 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
203 diff  -b $TEMPDIR/pspp.list - <<EOF
204 1.1 FREQUENCIES.  X: 
205 +-----------+--------+---------+--------+--------+--------+
206 |           |        |         |        |  Valid |   Cum  |
207 |Value Label|  Value |Frequency| Percent| Percent| Percent|
208 #===========#========#=========#========#========#========#
209 |           |    1.00|        1|    16.7|    16.7|    16.7|
210 |           |    3.00|        2|    33.3|    33.3|    50.0|
211 |           |    4.00|        1|    16.7|    16.7|    66.7|
212 |           |    5.00|        2|    33.3|    33.3|   100.0|
213 #===========#========#=========#========#========#========#
214 |               Total|        6|   100.0|   100.0|        |
215 +--------------------+---------+--------+--------+--------+
216 +-------------------+-----+
217 |N           Valid  |    6|
218 |            Missing|    0|
219 |Mean               |3.500|
220 |Std Dev            |1.517|
221 |Minimum            |1.000|
222 |Maximum            |5.000|
223 |Percentiles 0      |1.000|
224 |            25     |3.000|
225 |            50     |3.500|
226 |            75     |4.750|
227 |            100    |5.000|
228 +-------------------+-----+
229 EOF
230 if [ $? -ne 0 ] ; then fail ; fi
231
232 i=$[$i+1];
233
234 activity="create program $i"
235 cat > $TEMPDIR/prog.sps <<EOF
236 DATA LIST LIST notable /X * F *.
237 BEGIN DATA.
238 1 1
239 3 2
240 4 1
241 5 1
242 5 1
243 99 4
244 END DATA.
245
246 MISSING VALUE x (99.0) .
247 WEIGHT BY f.
248
249 FREQUENCIES 
250         VAR=x
251         /PERCENTILES = 0 25 50 75 100
252
253 EOF
254 if [ $? -ne 0 ] ; then no_result; fi
255
256
257 activity="run program $i"
258 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
259 if [ $? -ne 0 ] ; then no_result ; fi
260
261 activity="compare output $i"
262 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
263 diff -b $TEMPDIR/pspp.list - <<EOF
264 1.1 FREQUENCIES.  X: 
265 +-----------+--------+---------+--------+--------+--------+
266 |           |        |         |        |  Valid |   Cum  |
267 |Value Label|  Value |Frequency| Percent| Percent| Percent|
268 #===========#========#=========#========#========#========#
269 |           |    1.00|        1|    10.0|    16.7|    16.7|
270 |           |    3.00|        2|    20.0|    33.3|    50.0|
271 |           |    4.00|        1|    10.0|    16.7|    66.7|
272 |           |    5.00|        2|    20.0|    33.3|   100.0|
273 |           |   99.00|        4|    40.0| Missing|        |
274 #===========#========#=========#========#========#========#
275 |               Total|       10|   100.0|   100.0|        |
276 +--------------------+---------+--------+--------+--------+
277 +-------------------+-----+
278 |N           Valid  |    6|
279 |            Missing|    4|
280 |Mean               |3.500|
281 |Std Dev            |1.517|
282 |Minimum            |1.000|
283 |Maximum            |5.000|
284 |Percentiles 0      |1.000|
285 |            25     |3.000|
286 |            50     |3.500|
287 |            75     |4.750|
288 |            100    |5.000|
289 +-------------------+-----+
290 EOF
291 if [ $? -ne 0 ] ; then fail ; fi
292
293 pass;