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