Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / tests / command / match-files.sh
1 #!/bin/sh
2
3 # This program tests the MATCH FILES procedure
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/match-files.pspp
7
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18
19 STAT_CONFIG_PATH=$top_srcdir/config
20 export STAT_CONFIG_PATH
21
22 cleanup()
23 {
24      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
25         echo "NOT cleaning $TEMPDIR" 
26         return ; 
27      fi
28     cd /
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="data create"
61 cat > a.data <<EOF
62 0aA
63 1aB
64 1aC
65 2aD
66 3aE
67 4aF
68 5aG
69 5aH
70 6aI
71 7aJ
72 7aK
73 7aL
74 8aM
75 EOF
76 if [ $? -ne 0 ] ; then no_result ; fi
77 cat > b.data <<EOF
78 1bN
79 3bO
80 4bP
81 6bQ
82 7bR
83 9bS
84 EOF
85 if [ $? -ne 0 ] ; then no_result ; fi
86
87 cat > ff.out <<EOF
88 A B C D INA INB FIRST LAST
89 - - - - --- --- ----- ----
90 0 a A     1   0     1    1
91 1 a B N   1   1     1    0
92 1 a C     1   0     0    1
93 2 a D     1   0     1    1
94 3 a E O   1   1     1    1
95 4 a F P   1   1     1    1
96 5 a G     1   0     1    0
97 5 a H     1   0     0    1
98 6 a I Q   1   1     1    1
99 7 a J R   1   1     1    0
100 7 a K     1   0     0    0
101 7 a L     1   0     0    1
102 8 a M     1   0     1    1
103 9 b   S   0   1     1    1
104 EOF
105
106 cat > ft.out <<EOF
107 A B C D INA INB FIRST LAST
108 - - - - --- --- ----- ----
109 0 a A     1   0     1    1
110 1 a B N   1   1     1    0
111 1 a C N   1   1     0    1
112 2 a D     1   0     1    1
113 3 a E O   1   1     1    1
114 4 a F P   1   1     1    1
115 5 a G     1   0     1    0
116 5 a H     1   0     0    1
117 6 a I Q   1   1     1    1
118 7 a J R   1   1     1    0
119 7 a K R   1   1     0    0
120 7 a L R   1   1     0    1
121 8 a M     1   0     1    1
122 EOF
123
124 # Test nonparallel match and table lookup.
125 dla="data list notable file='a.data' /A B C 1-3 (a)."
126 sa="save outfile='a.sys'."
127 dlb="data list notable file='b.data' /A B C 1-3 (a)."
128 sb="save outfile='b.sys'."
129 for types in ff ft; do
130     type1=file
131     if [ $types = ff ]; then 
132         type2=file
133     else
134         type2=table
135     fi
136     for sources in ss sa as; do
137         name="$types-$sources"
138         activity="create $name.pspp"
139         {
140             if [ $sources = ss ]; then
141                 cat <<EOF
142 $dla
143 $sa
144 $dlb
145 $sb
146 match files $type1='a.sys' /in=INA /$type2='b.sys' /in=INB /rename c=D /by a
147             /first=FIRST /last=LAST.
148 EOF
149             elif [ $sources = sa ]; then
150                 cat <<EOF
151 $dla
152 $sa
153 $dlb
154 match files $type1='a.sys' /in=INA /$type2=* /in=INB /rename c=D /by a
155             /first=FIRST /last=LAST.
156 EOF
157             elif [ $sources = as ]; then
158                 cat <<EOF
159 $dlb
160 $sb
161 $dla
162 match files $type1=* /in=INA /$type2='b.sys' /in=INB /rename c=D /by a
163             /first=FIRST /last=LAST.
164 EOF
165             else
166                 activity="internal error"
167                 no_result
168             fi
169             echo 'list.'
170         } > $name.pspp
171         if [ $? -ne 0 ] ; then no_result ; fi
172
173         activity="run $name.pspp"
174         $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
175         if [ $? -ne 0 ] ; then no_result ; fi
176
177         activity="check $name output"
178         perl -pi -e 's/^\s*$//g' pspp.list
179         perl -pi -e 's/^\s*$//g' $types.out
180         diff -b -w pspp.list $types.out
181         if [ $? -ne 0 ] ; then fail ; fi
182     done
183 done
184
185 # Test parallel match.  
186 name="parallel"
187 activity="create $name.pspp"
188 cat > $name.pspp <<EOF
189 $dla
190 $sa
191 $dlb
192 $sb
193 match files file='a.sys' /file='b.sys' /rename (a b c=D E F).
194 list.
195 EOF
196 if [ $? -ne 0 ] ; then no_result ; fi
197
198 activity="run $name.pspp"
199 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
200 if [ $? -ne 0 ] ; then no_result ; fi
201
202 activity="check $name output"
203 perl -pi -e 's/^\s*$//g' pspp.list
204 diff -b -w - pspp.list <<EOF
205 A B C D E F
206 - - - - - -
207 0 a A 1 b N
208 1 a B 3 b O
209 1 a C 4 b P
210 2 a D 6 b Q
211 3 a E 7 b R
212 4 a F 9 b S
213 5 a G
214 5 a H
215 6 a I
216 7 a J
217 7 a K
218 7 a L
219 8 a M
220 EOF
221 if [ $? -ne 0 ] ; then fail ; fi
222
223 # Test bug handling TABLE from active file found by John Darrington.
224 name="active-table"
225 activity="create $name.pspp"
226 cat > $name.pspp <<EOF
227 DATA LIST LIST NOTABLE /x * y *.
228 BEGIN DATA
229 3 30
230 2 21
231 1 22
232 END DATA.
233
234 SAVE OUTFILE='bar.sav'.
235
236 DATA LIST LIST NOTABLE /x * z *.
237 BEGIN DATA
238 3 8
239 2 9
240 END DATA.
241
242 MATCH FILES TABLE=* /FILE='bar.sav' /BY=x.
243 LIST.
244 EOF
245 if [ $? -ne 0 ] ; then no_result ; fi
246
247 activity="run $name.pspp"
248 $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
249 if [ $? -ne 0 ] ; then no_result ; fi
250
251 activity="check $name output"
252 perl -pi -e 's/^\s*$//g' pspp.list
253 diff -b -w - pspp.list <<EOF | perl -e 's/^\s*$//g'
254         x        z        y
255  -------- -------- --------
256      3.00     8.00    30.00 
257      2.00      .      21.00 
258      1.00      .      22.00 
259 EOF
260 if [ $? -ne 0 ] ; then fail ; fi
261
262
263 pass;