Rewrite PSPP output engine.
[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 diff -c $TEMPDIR/pspp.csv - <<EOF
89 Table: X
90 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
91 ,1.00,1,20.00,20.00,20.00
92 ,2.00,1,20.00,20.00,40.00
93 ,3.00,1,20.00,20.00,60.00
94 ,4.00,1,20.00,20.00,80.00
95 ,5.00,1,20.00,20.00,100.00
96 Total,,5,100.0,100.0,
97
98 N,Valid,5
99 ,Missing,0
100 Mean,,3.00
101 Std Dev,,1.58
102 Minimum,,1.00
103 Maximum,,5.00
104 Percentiles,0,1.00
105 ,25,2.00
106 ,50 (Median),3.00
107 ,75,4.00
108 ,100,5.00
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 $PSPP --testing-mode $TEMPDIR/prog.sps
141 if [ $? -ne 0 ] ; then no_result ; fi
142
143 activity="compare output $i"
144 diff -c $TEMPDIR/pspp.csv - <<EOF
145 Table: X
146 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
147 ,1.00,2.00,20.00,20.00,20.00
148 ,2.00,2.00,20.00,20.00,40.00
149 ,3.00,2.00,20.00,20.00,60.00
150 ,4.00,2.00,20.00,20.00,80.00
151 ,5.00,2.00,20.00,20.00,100.00
152 Total,,10.00,100.0,100.0,
153
154 N,Valid,10.00
155 ,Missing,.00
156 Mean,,3.00
157 Std Dev,,1.49
158 Minimum,,1.00
159 Maximum,,5.00
160 Percentiles,0,1.00
161 ,25,2.00
162 ,50 (Median),3.00
163 ,75,4.00
164 ,100,5.00
165 EOF
166 if [ $? -ne 0 ] ; then fail ; fi
167
168
169
170 i=$[$i+1];
171
172 activity="create program $i"
173 cat > $TEMPDIR/prog.sps <<EOF
174 DATA LIST LIST notable /X * F *.
175 BEGIN DATA.
176 1 1
177 3 2
178 4 1
179 5 1
180 5 1
181 END DATA.
182
183 WEIGHT BY f.
184
185 FREQUENCIES 
186         VAR=x
187         /PERCENTILES = 0 25 50 75 100
188
189 EOF
190 if [ $? -ne 0 ] ; then no_result; fi
191
192
193 activity="run program $i"
194 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/prog.sps
195 if [ $? -ne 0 ] ; then no_result ; fi
196
197 activity="compare output $i"
198 diff -c $TEMPDIR/pspp.csv - <<EOF
199 Table: X
200 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
201 ,1.00,1.00,16.67,16.67,16.67
202 ,3.00,2.00,33.33,33.33,50.00
203 ,4.00,1.00,16.67,16.67,66.67
204 ,5.00,2.00,33.33,33.33,100.00
205 Total,,6.00,100.0,100.0,
206
207 N,Valid,6.00
208 ,Missing,.00
209 Mean,,3.50
210 Std Dev,,1.52
211 Minimum,,1.00
212 Maximum,,5.00
213 Percentiles,0,1.00
214 ,25,3.00
215 ,50 (Median),3.50
216 ,75,4.75
217 ,100,5.00
218 EOF
219 if [ $? -ne 0 ] ; then fail ; fi
220
221 i=$[$i+1];
222
223 activity="create program $i"
224 cat > $TEMPDIR/prog.sps <<EOF
225 DATA LIST LIST notable /X * F *.
226 BEGIN DATA.
227 1 1
228 3 2
229 4 1
230 5 1
231 5 1
232 99 4
233 END DATA.
234
235 MISSING VALUE x (99.0) .
236 WEIGHT BY f.
237
238 FREQUENCIES 
239         VAR=x
240         /PERCENTILES = 0 25 50 75 100
241
242 EOF
243 if [ $? -ne 0 ] ; then no_result; fi
244
245
246 activity="run program $i"
247 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/prog.sps
248 if [ $? -ne 0 ] ; then no_result ; fi
249
250 activity="compare output $i"
251 diff -c $TEMPDIR/pspp.csv - <<EOF
252 Table: X
253 Value Label,Value,Frequency,Percent,Valid Percent,Cum Percent
254 ,1.00,1.00,10.00,16.67,16.67
255 ,3.00,2.00,20.00,33.33,50.00
256 ,4.00,1.00,10.00,16.67,66.67
257 ,5.00,2.00,20.00,33.33,100.00
258 ,99.00,4.00,40.00,Missing,
259 Total,,10.00,100.0,100.0,
260
261 N,Valid,6.00
262 ,Missing,4.00
263 Mean,,3.50
264 Std Dev,,1.52
265 Minimum,,1.00
266 Maximum,,5.00
267 Percentiles,0,1.00
268 ,25,3.00
269 ,50 (Median),3.50
270 ,75,4.75
271 ,100,5.00
272 EOF
273 if [ $? -ne 0 ] ; then fail ; fi
274
275 pass;