FREQUENCIES: Make frequency table headings easier to translate.
[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 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
89 diff  -b $TEMPDIR/pspp.list - <<EOF
90 1.1 FREQUENCIES.  X
91 +-----------+--------+---------+--------+-------------+-----------+
92 |Value Label|  Value |Frequency| Percent|Valid Percent|Cum Percent|
93 #===========#========#=========#========#=============#===========#
94 |           |    1.00|        1|   20.00|        20.00|      20.00|
95 |           |    2.00|        1|   20.00|        20.00|      40.00|
96 |           |    3.00|        1|   20.00|        20.00|      60.00|
97 |           |    4.00|        1|   20.00|        20.00|      80.00|
98 |           |    5.00|        1|   20.00|        20.00|     100.00|
99 #===========#========#=========#========#=============#===========#
100 |               Total|        5|   100.0|        100.0|           |
101 +--------------------+---------+--------+-------------+-----------+
102 +-----------------------+----+
103 |N           Valid      |   5|
104 |            Missing    |   0|
105 |Mean                   |3.00|
106 |Std Dev                |1.58|
107 |Minimum                |1.00|
108 |Maximum                |5.00|
109 |Percentiles 0          |1.00|
110 |            25         |2.00|
111 |            50 (Median)|3.00|
112 |            75         |4.00|
113 |            100        |5.00|
114 +-----------------------+----+
115 EOF
116 if [ $? -ne 0 ] ; then fail ; fi
117
118
119
120 i=$[$i+1];
121
122 activity="create program $i"
123 cat > $TEMPDIR/prog.sps <<EOF
124 DATA LIST LIST notable /X * F *.
125 BEGIN DATA.
126 1 2
127 2 2
128 3 2
129 4 1
130 4 1
131 5 1
132 5 1
133 END DATA.
134
135 WEIGHT BY f.
136
137 FREQUENCIES 
138         VAR=x
139         /PERCENTILES = 0 25 50 75 100
140
141 EOF
142 if [ $? -ne 0 ] ; then no_result; fi
143
144
145 activity="run program $i"
146 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/prog.sps
147 if [ $? -ne 0 ] ; then no_result ; fi
148
149 activity="compare output $i"
150 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
151 diff  -b $TEMPDIR/pspp.list - <<EOF
152 1.1 FREQUENCIES.  X
153 +-----------+--------+---------+--------+-------------+-----------+
154 |Value Label|  Value |Frequency| Percent|Valid Percent|Cum Percent|
155 #===========#========#=========#========#=============#===========#
156 |           |    1.00|     2.00|   20.00|        20.00|      20.00|
157 |           |    2.00|     2.00|   20.00|        20.00|      40.00|
158 |           |    3.00|     2.00|   20.00|        20.00|      60.00|
159 |           |    4.00|     2.00|   20.00|        20.00|      80.00|
160 |           |    5.00|     2.00|   20.00|        20.00|     100.00|
161 #===========#========#=========#========#=============#===========#
162 |               Total|    10.00|   100.0|        100.0|           |
163 +--------------------+---------+--------+-------------+-----------+
164 +-----------------------+-----+
165 |N           Valid      |10.00|
166 |            Missing    |  .00|
167 |Mean                   | 3.00|
168 |Std Dev                | 1.49|
169 |Minimum                | 1.00|
170 |Maximum                | 5.00|
171 |Percentiles 0          | 1.00|
172 |            25         | 2.00|
173 |            50 (Median)| 3.00|
174 |            75         | 4.00|
175 |            100        | 5.00|
176 +-----------------------+-----+
177 EOF
178 if [ $? -ne 0 ] ; then fail ; fi
179
180
181
182 i=$[$i+1];
183
184 activity="create program $i"
185 cat > $TEMPDIR/prog.sps <<EOF
186 DATA LIST LIST notable /X * F *.
187 BEGIN DATA.
188 1 1
189 3 2
190 4 1
191 5 1
192 5 1
193 END DATA.
194
195 WEIGHT BY f.
196
197 FREQUENCIES 
198         VAR=x
199         /PERCENTILES = 0 25 50 75 100
200
201 EOF
202 if [ $? -ne 0 ] ; then no_result; fi
203
204
205 activity="run program $i"
206 $SUPERVISOR $PSPP --testing-mode $TEMPDIR/prog.sps
207 if [ $? -ne 0 ] ; then no_result ; fi
208
209 activity="compare output $i"
210 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
211 diff  -b $TEMPDIR/pspp.list - <<EOF
212 1.1 FREQUENCIES.  X
213 +-----------+--------+---------+--------+-------------+-----------+
214 |Value Label|  Value |Frequency| Percent|Valid Percent|Cum Percent|
215 #===========#========#=========#========#=============#===========#
216 |           |    1.00|     1.00|   16.67|        16.67|      16.67|
217 |           |    3.00|     2.00|   33.33|        33.33|      50.00|
218 |           |    4.00|     1.00|   16.67|        16.67|      66.67|
219 |           |    5.00|     2.00|   33.33|        33.33|     100.00|
220 #===========#========#=========#========#=============#===========#
221 |               Total|     6.00|   100.0|        100.0|           |
222 +--------------------+---------+--------+-------------+-----------+
223 +-----------------------+----+
224 |N           Valid      |6.00|
225 |            Missing    | .00|
226 |Mean                   |3.50|
227 |Std Dev                |1.52|
228 |Minimum                |1.00|
229 |Maximum                |5.00|
230 |Percentiles 0          |1.00|
231 |            25         |3.00|
232 |            50 (Median)|3.50|
233 |            75         |4.75|
234 |            100        |5.00|
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 --testing-mode $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 |Value Label|  Value |Frequency| Percent|Valid Percent|Cum Percent|
274 #===========#========#=========#========#=============#===========#
275 |           |    1.00|     1.00|   10.00|        16.67|      16.67|
276 |           |    3.00|     2.00|   20.00|        33.33|      50.00|
277 |           |    4.00|     1.00|   10.00|        16.67|      66.67|
278 |           |    5.00|     2.00|   20.00|        33.33|     100.00|
279 |           |   99.00|     4.00|   40.00|      Missing|           |
280 #===========#========#=========#========#=============#===========#
281 |               Total|    10.00|   100.0|        100.0|           |
282 +--------------------+---------+--------+-------------+-----------+
283 +-----------------------+----+
284 |N           Valid      |6.00|
285 |            Missing    |4.00|
286 |Mean                   |3.50|
287 |Std Dev                |1.52|
288 |Minimum                |1.00|
289 |Maximum                |5.00|
290 |Percentiles 0          |1.00|
291 |            25         |3.00|
292 |            50 (Median)|3.50|
293 |            75         |4.75|
294 |            100        |5.00|
295 +-----------------------+----+
296 EOF
297 if [ $? -ne 0 ] ; then fail ; fi
298
299 pass;