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