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