Added "cd /" to the test scripts which don't already have it. This avoids warnings...
[pspp-builds.git] / tests / command / npar-chisquare.sh
1 #!/bin/sh
2
3 # This program tests the chisquare subcommand of the NPAR command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
29      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61 activity="create file 1"
62 cat <<EOF > $TESTFILE
63 DATA LIST NOTABLE LIST /x * y * w *.
64 BEGIN DATA.
65 1   2  1
66 2   1  3
67 3.1 1  4
68 3.2 2  1
69 4   2  2
70 5   3  1
71 1   4  2
72 END DATA.
73
74 WEIGHT BY w.
75
76 NPAR TESTS
77   CHISQUARE=x y
78   .
79
80 NPAR TESTS
81   CHISQUARE=y
82   /EXPECTED=3 4 5 4
83   .
84
85 NPAR TESTS
86   CHISQUARE=x y(2, 4)
87   /EXPECTED = 6 10 3
88   .
89
90 EOF
91 if [ $? -ne 0 ] ; then no_result ; fi
92
93
94 activity="run program 1"
95 $SUPERVISOR $PSPP --testing-mode $TESTFILE
96 if [ $? -ne 0 ] ; then no_result ; fi
97
98 activity="compare output 1"
99 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
100 diff -b $TEMPDIR/pspp.list - << EOF
101 1.1 NPAR TESTS.  x
102 +--------#----------+----------+--------+
103 |        #Observed N|Expected N|Residual|
104 +--------#----------+----------+--------+
105 |    1.00#         3|      2.33|     .67|
106 |    2.00#         3|      2.33|     .67|
107 |    3.10#         4|      2.33|    1.67|
108 |    3.20#         1|      2.33|   -1.33|
109 |    4.00#         2|      2.33|    -.33|
110 |    5.00#         1|      2.33|   -1.33|
111 |Total   #        14|          |        |
112 +--------#----------+----------+--------+
113 1.2 NPAR TESTS.  y
114 +--------#----------+----------+--------+
115 |        #Observed N|Expected N|Residual|
116 +--------#----------+----------+--------+
117 |    1.00#         7|      3.50|    3.50|
118 |    2.00#         4|      3.50|     .50|
119 |    3.00#         1|      3.50|   -2.50|
120 |    4.00#         2|      3.50|   -1.50|
121 |Total   #        14|          |        |
122 +--------#----------+----------+--------+
123 1.3 NPAR TESTS.  Test Statistics
124 +-----------#-----+-----+
125 |           #  x  |  y  |
126 +-----------#-----+-----+
127 |Chi-Square #3.143|6.000|
128 |df         #    5|    3|
129 |Asymp. Sig.# .678| .112|
130 +-----------#-----+-----+
131 2.1 NPAR TESTS.  y
132 +--------#----------+----------+--------+
133 |        #Observed N|Expected N|Residual|
134 +--------#----------+----------+--------+
135 |    1.00#         7|      2.63|    4.38|
136 |    2.00#         4|      3.50|     .50|
137 |    3.00#         1|      4.38|   -3.38|
138 |    4.00#         2|      3.50|   -1.50|
139 |Total   #        14|          |        |
140 +--------#----------+----------+--------+
141 2.2 NPAR TESTS.  Test Statistics
142 +-----------#------+
143 |           #   y  |
144 +-----------#------+
145 |Chi-Square #10.610|
146 |df         #     3|
147 |Asymp. Sig.#  .014|
148 +-----------#------+
149 3.1 NPAR TESTS.  Frequencies
150 +-----#---------------------------------------#---------------------------------------+
151 |     #                   x                   #                   y                   |
152 |     #--------+----------+----------+--------#--------+----------+----------+--------+
153 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
154 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
155 |1    #    2.00|         3|      3.16|    -.16#    2.00|         4|      2.21|    1.79|
156 |2    #    3.00|         5|      5.26|    -.26#    3.00|         1|      3.68|   -2.68|
157 |3    #    4.00|         2|      1.58|     .42#    4.00|         2|      1.11|     .89|
158 |Total#        |        10|          |        #        |         7|          |        |
159 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
160 3.2 NPAR TESTS.  Test Statistics
161 +-----------#----+-----+
162 |           #  x |  y  |
163 +-----------#----+-----+
164 |Chi-Square #.133|4.129|
165 |df         #   2|    2|
166 |Asymp. Sig.#.936| .127|
167 +-----------#----+-----+
168 EOF
169 if [ $? -ne 0 ] ; then fail ; fi
170
171
172 activity="create file 2"
173 cat <<EOF > $TESTFILE
174 DATA LIST NOTABLE LIST /x * y * w *.
175 BEGIN DATA.
176 1   2  1
177 2   1  3
178 3.1 1  4
179 3.2 2  1
180 4   2  2
181 5   3  1
182 1   4  2
183 END DATA.
184
185 WEIGHT BY w.
186
187 NPAR TESTS
188   CHISQUARE=y
189   /EXPECTED = 3 4 5 4 3 1
190   .
191 EOF
192 if [ $? -ne 0 ] ; then no_result ; fi
193
194
195 activity="run program 2"
196 $SUPERVISOR $PSPP --testing-mode $TESTFILE  > $TEMPDIR/output
197 if [ $? -eq 0 ] ; then no_result ; fi
198
199 activity="compare errors 2"
200 perl -pi -e 's/^\s*$//g' $TEMPDIR/output
201 diff -b  $TEMPDIR/output - << EOF
202 error: CHISQUARE test specified 6 expected values, but 4 distinct values were encountered in variable y.
203 EOF
204 if [ $? -ne 0 ] ; then fail ; fi
205
206
207 activity="create file 3"
208 cat <<EOF > $TESTFILE
209 DATA LIST NOTABLE LIST /x * y * w * .
210 BEGIN DATA.
211 1   2  1 
212 2   1  3
213 3.1 1  4
214 3.2 2  1
215 4   2  2
216 5   3  1
217 1   4  2
218 .   5  1
219 END DATA.
220
221 WEIGHT BY w.
222
223 MISSING VALUES x (4).
224
225 NPAR TESTS
226   CHISQUARE=x y(-2,5)
227   /MISSING=ANALYSIS
228   /STATISTICS=DESCRIPTIVES
229   .
230 EOF
231 if [ $? -ne 0 ] ; then no_result ; fi
232
233
234 activity="run program 3"
235 $SUPERVISOR $PSPP --testing-mode $TESTFILE 
236 if [ $? -ne 0 ] ; then no_result ; fi
237
238
239 activity="compare output 3"
240 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
241 diff -b $TEMPDIR/pspp.list - <<EOF
242 1.1 NPAR TESTS.  Frequencies
243 +-----#---------------------------------------#---------------------------------------+
244 |     #                   x                   #                   y                   |
245 |     #--------+----------+----------+--------#--------+----------+----------+--------+
246 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
247 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
248 |1    #   -2.00|         0|      1.50|   -1.50#   -2.00|         0|      1.88|   -1.88|
249 |2    #   -1.00|         0|      1.50|   -1.50#   -1.00|         0|      1.88|   -1.88|
250 |3    #     .00|         0|      1.50|   -1.50#     .00|         0|      1.88|   -1.88|
251 |4    #    1.00|         3|      1.50|    1.50#    1.00|         7|      1.88|    5.13|
252 |5    #    2.00|         3|      1.50|    1.50#    2.00|         4|      1.88|    2.13|
253 |6    #    3.00|         5|      1.50|    3.50#    3.00|         1|      1.88|    -.88|
254 |7    #    4.00|         0|      1.50|   -1.50#    4.00|         2|      1.88|     .13|
255 |8    #    5.00|         1|      1.50|    -.50#    5.00|         1|      1.88|    -.88|
256 |Total#        |        12|          |        #        |        15|          |        |
257 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
258 1.2 NPAR TESTS.  Test Statistics
259 +-----------#------+------+
260 |           #   x  |   y  |
261 +-----------#------+------+
262 |Chi-Square #17.333|22.867|
263 |df         #     7|     7|
264 |Asymp. Sig.#  .015|  .002|
265 +-----------#------+------+
266 1.3 NPAR TESTS.  Descriptive Statistics
267 +-#--+-----+-----+-----+-----+
268 | # N| Mean| Std.|Minim|Maxim|
269 | #  |     |Devia|  um |  um |
270 #=#==#=====#=====#=====#=====#
271 |x#12|2.467|1.193|1.000|5.000|
272 |y#15|2.067|1.335|1.000|5.000|
273 +-#--+-----+-----+-----+-----+
274 EOF
275 if [ $? -ne 0 ] ; then fail ; fi
276
277
278 activity="create file 4"
279 cat <<EOF > $TESTFILE
280 DATA LIST NOTABLE LIST /x * y * w * .
281 BEGIN DATA.
282 1   2  1 
283 2   1  3
284 3.1 1  4
285 3.2 2  1
286 4   2  2
287 5   3  1
288 1   4  2
289 .   5  1
290 END DATA.
291
292 WEIGHT BY w.
293
294 * MISSING VALUES x (4).
295
296 NPAR TESTS
297   CHISQUARE=x y(-2,5)
298   /MISSING=LISTWISE
299   /STATISTICS=DESCRIPTIVES
300   .
301 EOF
302 if [ $? -ne 0 ] ; then no_result ; fi
303
304
305 activity="run program 4"
306 $SUPERVISOR $PSPP --testing-mode $TESTFILE 
307 if [ $? -ne 0 ] ; then no_result ; fi
308
309
310 activity="compare output 4"
311 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
312 diff -b $TEMPDIR/pspp.list - <<EOF
313 1.1 NPAR TESTS.  Frequencies
314 +-----#---------------------------------------#---------------------------------------+
315 |     #                   x                   #                   y                   |
316 |     #--------+----------+----------+--------#--------+----------+----------+--------+
317 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
318 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
319 |1    #   -2.00|         0|      1.75|   -1.75#   -2.00|         0|      1.75|   -1.75|
320 |2    #   -1.00|         0|      1.75|   -1.75#   -1.00|         0|      1.75|   -1.75|
321 |3    #     .00|         0|      1.75|   -1.75#     .00|         0|      1.75|   -1.75|
322 |4    #    1.00|         3|      1.75|    1.25#    1.00|         7|      1.75|    5.25|
323 |5    #    2.00|         3|      1.75|    1.25#    2.00|         4|      1.75|    2.25|
324 |6    #    3.00|         5|      1.75|    3.25#    3.00|         1|      1.75|    -.75|
325 |7    #    4.00|         2|      1.75|     .25#    4.00|         2|      1.75|     .25|
326 |8    #    5.00|         1|      1.75|    -.75#    5.00|         0|      1.75|   -1.75|
327 |Total#        |        14|          |        #        |        14|          |        |
328 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
329 1.2 NPAR TESTS.  Test Statistics
330 +-----------#------+------+
331 |           #   x  |   y  |
332 +-----------#------+------+
333 |Chi-Square #13.429|26.000|
334 |df         #     7|     7|
335 |Asymp. Sig.#  .062|  .001|
336 +-----------#------+------+
337 1.3 NPAR TESTS.  Descriptive Statistics
338 +-#--+-----+-----+-----+-----+
339 | # N| Mean| Std.|Minim|Maxim|
340 | #  |     |Devia|  um |  um |
341 #=#==#=====#=====#=====#=====#
342 |x#14|2.686|1.231|1.000|5.000|
343 |y#14|1.857|1.099|1.000|4.000|
344 +-#--+-----+-----+-----+-----+
345 EOF
346 if [ $? -ne 0 ] ; then fail ; fi
347
348
349 pass;