Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / correlation.sh
1 #!/bin/sh
2
3 # This program tests the CORRELATIONS 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      rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="create program 1"
61 cat << EOF > $TESTFILE
62 set format = F11.3.
63 data list notable list /foo * bar * wiz * bang *.
64 begin data.
65 1   0   3   1
66 3   9 -50   5
67 3   4   3 203
68 4  -9   0  -4
69 98 78 104   2
70 3  50 -49 200
71 .   4   4   4
72 5   3   0   .
73 end data.
74
75 correlations 
76         variables = foo bar wiz bang
77         /print nosig
78         /missing = listwise
79         .
80
81 correlations 
82         variables = bar wiz
83         /print nosig
84         /missing = listwise
85         .
86
87 correlations 
88         variables = foo bar wiz bang
89         /print nosig
90         /missing = pairwise
91         .
92 EOF
93 if [ $? -ne 0 ] ; then no_result ; fi
94
95
96 activity="run program 1"
97 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
98 if [ $? -ne 0 ] ; then no_result ; fi
99
100 activity="compare results 1"
101 diff -c $TEMPDIR/pspp.csv - << EOF
102 Table: Correlations
103 ,,foo,bar,wiz,bang
104 foo,Pearson Correlation,1.000,.802,.890,-.308
105 ,Sig. (2-tailed),,.055,.017,.553
106 bar,Pearson Correlation,.802,1.000,.519,.118
107 ,Sig. (2-tailed),.055,,.291,.824
108 wiz,Pearson Correlation,.890,.519,1.000,-.344
109 ,Sig. (2-tailed),.017,.291,,.505
110 bang,Pearson Correlation,-.308,.118,-.344,1.000
111 ,Sig. (2-tailed),.553,.824,.505,
112
113 Table: Correlations
114 ,,bar,wiz
115 bar,Pearson Correlation,1.000,.497
116 ,Sig. (2-tailed),,.210
117 wiz,Pearson Correlation,.497,1.000
118 ,Sig. (2-tailed),.210,
119
120 Table: Correlations
121 ,,foo,bar,wiz,bang
122 foo,Pearson Correlation,1.000,.805,.883,-.308
123 ,Sig. (2-tailed),,.029,.008,.553
124 ,N,7,7,7,6
125 bar,Pearson Correlation,.805,1.000,.497,.164
126 ,Sig. (2-tailed),.029,,.210,.725
127 ,N,7,8,8,7
128 wiz,Pearson Correlation,.883,.497,1.000,-.337
129 ,Sig. (2-tailed),.008,.210,,.460
130 ,N,7,8,8,7
131 bang,Pearson Correlation,-.308,.164,-.337,1.000
132 ,Sig. (2-tailed),.553,.725,.460,
133 ,N,6,7,7,7
134 EOF
135 if [ $? -ne 0 ] ; then fail ; fi
136
137
138 # Now test that weights are properly handled.
139
140 activity="create program 2"
141 cat << EOF > $TESTFILE
142 set format = F11.3.
143 data list notable list /foo * bar * wiz * bang * w *.
144 begin data.
145 1   0   3   1  1
146 3   9 -50   5  2
147 3   4   3 203  1
148 4  -9   0  -4  1
149 98 78 104   2  3
150 3  50 -49 200  1
151 end data.
152
153 weight by w.
154
155 correlations 
156         variables = foo bar wiz bang
157         /statistics=descriptives xprod
158         .
159
160 EOF
161 if [ $? -ne 0 ] ; then no_result ; fi
162
163
164 activity="run program 2"
165 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
166 if [ $? -ne 0 ] ; then no_result ; fi
167
168 activity="copy results"
169 cp $TEMPDIR/pspp.csv $TEMPDIR/weighted
170 if [ $? -ne 0 ] ; then no_result ; fi
171
172 activity="create program 3"
173 cat << EOF > $TESTFILE
174 set format = F11.3.
175 data list notable list /foo * bar * wiz * bang * w *.
176 begin data.
177 1   0   3   1  1
178 3   9 -50   5  1
179 3   9 -50   5  1
180 3   4   3 203  1
181 4  -9   0  -4  1
182 98 78 104   2  1
183 98 78 104   2  1
184 98 78 104   2  1
185 3  50 -49 200  1
186 end data.
187
188 weight by w.
189
190 correlations 
191         variables = foo bar wiz bang
192         /statistics=descriptives xprod
193         .
194
195 EOF
196 if [ $? -ne 0 ] ; then no_result ; fi
197
198 activity="run program 3"
199 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
200 if [ $? -ne 0 ] ; then no_result ; fi
201
202 activity="Compare weighted and unweighted results"
203 diff $TEMPDIR/pspp.csv $TEMPDIR/weighted
204 if [ $? -ne 0 ] ; then fail ; fi
205
206 pass;