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