4a2c167e2eda2a1b088370b006b38e42482c2dec
[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 # 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         /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 $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     |2.000|
106 |            50     |3.000|
107 |            75     |4.000|
108 |            100    |5.000|
109 +-------------------+-----+
110 EOF
111 if [ $? -ne 0 ] ; then fail ; fi
112
113
114
115 i=$[$i+1];
116
117 activity="create program $i"
118 cat > $TEMPDIR/prog.sps <<EOF
119 DATA LIST LIST notable /X * F *.
120 BEGIN DATA.
121 1 2
122 2 2
123 3 2
124 4 1
125 4 1
126 5 1
127 5 1
128 END DATA.
129
130 WEIGHT BY f.
131
132 FREQUENCIES 
133         VAR=x
134         /PERCENTILES = 0 25 50 75 100
135
136 EOF
137 if [ $? -ne 0 ] ; then no_result; fi
138
139
140 activity="run program $i"
141 $SUPERVISOR $PSPP -o raw-ascii $TEMPDIR/prog.sps
142 if [ $? -ne 0 ] ; then no_result ; fi
143
144 activity="compare output $i"
145 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
146 diff  -b $TEMPDIR/pspp.list - <<EOF
147 1.1 FREQUENCIES.  X: 
148 +-----------+--------+---------+--------+--------+--------+
149 |           |        |         |        |  Valid |   Cum  |
150 |Value Label|  Value |Frequency| Percent| Percent| Percent|
151 #===========#========#=========#========#========#========#
152 |           |    1.00|        2|    20.0|    20.0|    20.0|
153 |           |    2.00|        2|    20.0|    20.0|    40.0|
154 |           |    3.00|        2|    20.0|    20.0|    60.0|
155 |           |    4.00|        2|    20.0|    20.0|    80.0|
156 |           |    5.00|        2|    20.0|    20.0|   100.0|
157 #===========#========#=========#========#========#========#
158 |               Total|       10|   100.0|   100.0|        |
159 +--------------------+---------+--------+--------+--------+
160 +-------------------+-----+
161 |N           Valid  |   10|
162 |            Missing|    0|
163 |Mean               |3.000|
164 |Std Dev            |1.491|
165 |Minimum            |1.000|
166 |Maximum            |5.000|
167 |Percentiles 0      |1.000|
168 |            25     |2.000|
169 |            50     |3.000|
170 |            75     |4.000|
171 |            100    |5.000|
172 +-------------------+-----+
173 EOF
174 if [ $? -ne 0 ] ; then fail ; fi
175
176
177
178 i=$[$i+1];
179
180 activity="create program $i"
181 cat > $TEMPDIR/prog.sps <<EOF
182 DATA LIST LIST notable /X * F *.
183 BEGIN DATA.
184 1 1
185 3 2
186 4 1
187 5 1
188 5 1
189 END DATA.
190
191 WEIGHT BY f.
192
193 FREQUENCIES 
194         VAR=x
195         /PERCENTILES = 0 25 50 75 100
196
197 EOF
198 if [ $? -ne 0 ] ; then no_result; fi
199
200
201 activity="run program $i"
202 $SUPERVISOR $PSPP -o raw-ascii $TEMPDIR/prog.sps
203 if [ $? -ne 0 ] ; then no_result ; fi
204
205 activity="compare output $i"
206 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
207 diff  -b $TEMPDIR/pspp.list - <<EOF
208 1.1 FREQUENCIES.  X: 
209 +-----------+--------+---------+--------+--------+--------+
210 |           |        |         |        |  Valid |   Cum  |
211 |Value Label|  Value |Frequency| Percent| Percent| Percent|
212 #===========#========#=========#========#========#========#
213 |           |    1.00|        1|    16.7|    16.7|    16.7|
214 |           |    3.00|        2|    33.3|    33.3|    50.0|
215 |           |    4.00|        1|    16.7|    16.7|    66.7|
216 |           |    5.00|        2|    33.3|    33.3|   100.0|
217 #===========#========#=========#========#========#========#
218 |               Total|        6|   100.0|   100.0|        |
219 +--------------------+---------+--------+--------+--------+
220 +-------------------+-----+
221 |N           Valid  |    6|
222 |            Missing|    0|
223 |Mean               |3.500|
224 |Std Dev            |1.517|
225 |Minimum            |1.000|
226 |Maximum            |5.000|
227 |Percentiles 0      |1.000|
228 |            25     |3.000|
229 |            50     |3.500|
230 |            75     |4.750|
231 |            100    |5.000|
232 +-------------------+-----+
233 EOF
234 if [ $? -ne 0 ] ; then fail ; fi
235
236 i=$[$i+1];
237
238 activity="create program $i"
239 cat > $TEMPDIR/prog.sps <<EOF
240 DATA LIST LIST notable /X * F *.
241 BEGIN DATA.
242 1 1
243 3 2
244 4 1
245 5 1
246 5 1
247 99 4
248 END DATA.
249
250 MISSING VALUE x (99.0) .
251 WEIGHT BY f.
252
253 FREQUENCIES 
254         VAR=x
255         /PERCENTILES = 0 25 50 75 100
256
257 EOF
258 if [ $? -ne 0 ] ; then no_result; fi
259
260
261 activity="run program $i"
262 $SUPERVISOR $PSPP -o raw-ascii $TEMPDIR/prog.sps
263 if [ $? -ne 0 ] ; then no_result ; fi
264
265 activity="compare output $i"
266 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
267 diff -b $TEMPDIR/pspp.list - <<EOF
268 1.1 FREQUENCIES.  X: 
269 +-----------+--------+---------+--------+--------+--------+
270 |           |        |         |        |  Valid |   Cum  |
271 |Value Label|  Value |Frequency| Percent| Percent| Percent|
272 #===========#========#=========#========#========#========#
273 |           |    1.00|        1|    10.0|    16.7|    16.7|
274 |           |    3.00|        2|    20.0|    33.3|    50.0|
275 |           |    4.00|        1|    10.0|    16.7|    66.7|
276 |           |    5.00|        2|    20.0|    33.3|   100.0|
277 |           |   99.00|        4|    40.0| Missing|        |
278 #===========#========#=========#========#========#========#
279 |               Total|       10|   100.0|   100.0|        |
280 +--------------------+---------+--------+--------+--------+
281 +-------------------+-----+
282 |N           Valid  |    6|
283 |            Missing|    4|
284 |Mean               |3.500|
285 |Std Dev            |1.517|
286 |Minimum            |1.000|
287 |Maximum            |5.000|
288 |Percentiles 0      |1.000|
289 |            25     |3.000|
290 |            50     |3.500|
291 |            75     |4.750|
292 |            100    |5.000|
293 +-------------------+-----+
294 EOF
295 if [ $? -ne 0 ] ; then fail ; fi
296
297 pass;