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