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