Made BSD diff compatible
[pspp] / 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      cd /
20      rm -rf $TEMPDIR
21      :
22 }
23
24
25 fail()
26 {
27     echo $activity
28     echo FAILED
29     cleanup;
30     exit 1;
31 }
32
33
34 no_result()
35 {
36     echo $activity
37     echo NO RESULT;
38     cleanup;
39     exit 2;
40 }
41
42 pass()
43 {
44     cleanup;
45     exit 0;
46 }
47
48 mkdir -p $TEMPDIR
49
50 cd $TEMPDIR
51
52
53 i=1;
54
55 activity="create program $i"
56 cat > $TEMPDIR/prog.sps <<EOF
57 DATA LIST LIST notable /X * .
58 BEGIN DATA.
59
60
61
62
63 5
64 END DATA.
65
66 FREQUENCIES 
67         VAR=x
68         /PERCENTILES = 0 25 50 75 100
69
70 EOF
71 if [ $? -ne 0 ] ; then no_result; fi
72
73 activity="run program $i"
74 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
75 if [ $? -ne 0 ] ; then no_result ; fi
76
77 activity="compare output $i"
78 perl -pi -e s/^\s*\$//g $TEMPDIR/pspp.list
79 diff  -b $TEMPDIR/pspp.list - <<EOF | perl -e 's/^\s*$//g'
80 1.1 FREQUENCIES.  X: 
81 +-----------+--------+---------+--------+--------+--------+
82 |           |        |         |        |  Valid |   Cum  |
83 |Value Label|  Value |Frequency| Percent| Percent| Percent|
84 #===========#========#=========#========#========#========#
85 |           |    1.00|        1|    20.0|    20.0|    20.0|
86 |           |    2.00|        1|    20.0|    20.0|    40.0|
87 |           |    3.00|        1|    20.0|    20.0|    60.0|
88 |           |    4.00|        1|    20.0|    20.0|    80.0|
89 |           |    5.00|        1|    20.0|    20.0|   100.0|
90 #===========#========#=========#========#========#========#
91 |               Total|        5|   100.0|   100.0|        |
92 +--------------------+---------+--------+--------+--------+
93
94 +-------------------+-----+
95 |N           Valid  |    5|
96 |            Missing|    0|
97 |Mean               |3.000|
98 |Std Dev            |1.581|
99 |Minimum            |1.000|
100 |Maximum            |5.000|
101 |Percentiles 0      |1.000|
102 |            25     |2.000|
103 |            50     |3.000|
104 |            75     |4.000|
105 |            100    |5.000|
106 +-------------------+-----+
107 EOF
108 if [ $? -ne 0 ] ; then fail ; fi
109
110
111
112 i=$[$i+1];
113
114 activity="create program $i"
115 cat > $TEMPDIR/prog.sps <<EOF
116 DATA LIST LIST notable /X * F *.
117 BEGIN DATA.
118 1 2
119 2 2
120 3 2
121 4 1
122 4 1
123 5 1
124 5 1
125 END DATA.
126
127 WEIGHT BY f.
128
129 FREQUENCIES 
130         VAR=x
131         /PERCENTILES = 0 25 50 75 100
132
133 EOF
134 if [ $? -ne 0 ] ; then no_result; fi
135
136
137 activity="run program $i"
138 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
139 if [ $? -ne 0 ] ; then no_result ; fi
140
141 activity="compare output $i"
142 perl -pi -e s/^\s*\$//g $TEMPDIR/pspp.list
143 diff  -b $TEMPDIR/pspp.list - <<EOF | perl -e 's/^\s*$//g'
144 1.1 FREQUENCIES.  X: 
145 +-----------+--------+---------+--------+--------+--------+
146 |           |        |         |        |  Valid |   Cum  |
147 |Value Label|  Value |Frequency| Percent| Percent| Percent|
148 #===========#========#=========#========#========#========#
149 |           |    1.00|        2|    20.0|    20.0|    20.0|
150 |           |    2.00|        2|    20.0|    20.0|    40.0|
151 |           |    3.00|        2|    20.0|    20.0|    60.0|
152 |           |    4.00|        2|    20.0|    20.0|    80.0|
153 |           |    5.00|        2|    20.0|    20.0|   100.0|
154 #===========#========#=========#========#========#========#
155 |               Total|       10|   100.0|   100.0|        |
156 +--------------------+---------+--------+--------+--------+
157
158 +-------------------+-----+
159 |N           Valid  |   10|
160 |            Missing|    0|
161 |Mean               |3.000|
162 |Std Dev            |1.491|
163 |Minimum            |1.000|
164 |Maximum            |5.000|
165 |Percentiles 0      |1.000|
166 |            25     |2.000|
167 |            50     |3.000|
168 |            75     |4.000|
169 |            100    |5.000|
170 +-------------------+-----+
171 EOF
172 if [ $? -ne 0 ] ; then fail ; fi
173
174
175
176 i=$[$i+1];
177
178 activity="create program $i"
179 cat > $TEMPDIR/prog.sps <<EOF
180 DATA LIST LIST notable /X * F *.
181 BEGIN DATA.
182 1 1
183 3 2
184 4 1
185 5 1
186 5 1
187 END DATA.
188
189 WEIGHT BY f.
190
191 FREQUENCIES 
192         VAR=x
193         /PERCENTILES = 0 25 50 75 100
194
195 EOF
196 if [ $? -ne 0 ] ; then no_result; fi
197
198
199 activity="run program $i"
200 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/prog.sps
201 if [ $? -ne 0 ] ; then no_result ; fi
202
203 activity="compare output $i"
204 perl -pi -e s/^\s*\$//g $TEMPDIR/pspp.list
205 diff  -b $TEMPDIR/pspp.list - <<EOF | perl -e 's/^\s*$//g'
206 1.1 FREQUENCIES.  X: 
207 +-----------+--------+---------+--------+--------+--------+
208 |           |        |         |        |  Valid |   Cum  |
209 |Value Label|  Value |Frequency| Percent| Percent| Percent|
210 #===========#========#=========#========#========#========#
211 |           |    1.00|        1|    16.7|    16.7|    16.7|
212 |           |    3.00|        2|    33.3|    33.3|    50.0|
213 |           |    4.00|        1|    16.7|    16.7|    66.7|
214 |           |    5.00|        2|    33.3|    33.3|   100.0|
215 #===========#========#=========#========#========#========#
216 |               Total|        6|   100.0|   100.0|        |
217 +--------------------+---------+--------+--------+--------+
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 $here/../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 | perl -e 's/^\s*$//g'
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 +-------------------+-----+
282 |N           Valid  |    6|
283 |            Missing|    4|
284 |Mean               |3.500|
285 |Std Dev            |1.517|
286 |Minimum            |1.000|
287 |Maximum            |5.000|
288 |Percentiles 0      |1.000|
289 |            25     |3.000|
290 |            50     |3.500|
291 |            75     |4.750|
292 |            100    |5.000|
293 +-------------------+-----+
294 EOF
295 if [ $? -ne 0 ] ; then fail ; fi
296
297 pass;