(main): When testing mode is enabled, use a built-in output driver
[pspp-builds.git] / tests / command / aggregate.sh
1 #!/bin/sh
2
3 # This program tests the aggregate procedure
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/aggregate.pspp
7
8
9 # ensure that top_srcdir and top_builddir  are absolute
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
12 top_srcdir=`cd $top_srcdir; pwd`
13 top_builddir=`cd $top_builddir; pwd`
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20 cleanup()
21 {
22      cd /
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53
54 activity="data create"
55 cat > aggregate.data <<EOF
56 2 42
57 1001
58 4 41
59 3112
60 1112
61 2661
62 1221
63 2771
64 1331
65 1441
66 2881
67 1551
68 EOF
69 if [ $? -ne 0 ] ; then no_result ; fi
70
71 activity="command skeleton create"
72 cat > agg-skel.pspp <<EOF
73         /document
74         /break=g
75         /N = n
76         /NI = n./
77         NU = nu
78         /NUI = nu./
79         NFGT2 = fgt(n, 2)
80         /NFGT2I = fgt.(n, 2)
81         /SFGT2 = fgt(s, '2')
82         /SFGT2I = fgt.(s, '2')
83         /NFIN23 = fin(n, 2, 3)
84         /NFIN23I = fin.(n, 2, 3)
85         /SFIN23 = fin(s, '2', '3')
86         /SFIN23I = fin.(s, '2', '3')
87         /NFLT2 = flt(n, 2)
88         /NFLT2I = flt.(n, 2)
89         /SFLT2 = flt(s, '2')
90         /SFLT2I = flt.(s, '2')
91         /NFIRST = first(n)
92         /NFIRSTI = first.(n)
93         /SFIRST = first(s)
94         /SFIRSTI = first.(s)
95         /NFOUT23 = fout(n, 3, 2)
96         /NFOUT23I = fout.(n, 3, 2)
97         /SFOUT23 = fout(s, '3', '2')
98         /SFOUT23I = fout.(s, '3', '2')
99         /NLAST = last(n)
100         /NLASTI = last.(n)
101         /SLAST = last(s)
102         /SLASTI = last.(s)
103         /NMAX = max(n)
104         /NMAXI = max.(n)
105         /SMAX = max(s)
106         /SMAXI = max.(s)
107         /NMEAN = mean(n)
108         /NMEANI = mean.(n)
109         /NMIN = min(n)
110         /NMINI = min.(n)
111         /SMIN = min(s)
112         /SMINI = min.(s)
113         /NN = n(n)
114         /NNI = n.(n)
115         /SN = n(s)
116         /SNI = n.(s)
117         /NNMISS = nmiss(n)
118         /NNMISSI = nmiss.(n)
119         /SNMISS = nmiss(s)
120         /SNMISSI = nmiss.(s)
121         /NNU = nu(n)
122         /NNUI = nu.(n)
123         /SNU = nu(s)
124         /SNUI = nu.(s)
125         /NNUMISS = numiss(n)
126         /NNUMISSI = numiss.(n)
127         /SNUMISS = numiss(s)
128         /SNUMISSI = numiss.(s)
129         /NPGT2 = pgt(n, 2)
130         /NPGT2I = pgt.(n, 2)
131         /SPGT2 = pgt(s, '2')
132         /SPGT2I = pgt.(s, '2')
133         /NPIN23 = pin(n, 2, 3)
134         /NPIN23I = pin.(n, 2, 3)
135         /SPIN23 = pin(s, '2', '3')
136         /SPIN23I = pin.(s, '2', '3')
137         /NPLT2 = plt(n, 2)
138         /NPLT2I = plt.(n, 2)
139         /SPLT2 = plt(s, '2')
140         /SPLT2I = plt.(s, '2')
141         /NPOUT23 = pout(n, 2, 3)
142         /NPOUT23I = pout.(n, 2, 3)
143         /SPOUT23 = pout(s, '2', '3')
144         /SPOUT23I = pout.(s, '2', '3')
145         /NSD = sd(n)
146         /NSDI = sd.(n)
147         /NSUM = sum(n)
148         /NSUMI = sum.(n).
149 EOF
150
151 activity="expected output (itemwise missing) create"
152 cat > agg-itemwise.out <<EOF
153 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
154 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
155 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
156 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
157 G        N       NI      NU     NUI NFGT2 NFGT2I SFGT2 SFGT2I NFIN23 NFIN23I SFIN23 SFIN23I NFLT2 NFLT2I SFLT2 SFLT2I NFIRST NFIRSTI SFIRST SFIRSTI NFOUT23 NFOUT23I SFOUT23 SFOUT23I NLAST NLASTI SLAST SLASTI NMAX NMAXI SMAX SMAXI    NMEAN   NMEANI NMIN NMINI SMIN SMINI       NN      NNI       SN      SNI   NNMISS  NNMISSI   SNMISS  SNMISSI     NNU    NNUI     SNU    SNUI NNUMISS NNUMISSI SNUMISS SNUMISSI NPGT2 NPGT2I SPGT2 SPGT2I NPIN23 NPIN23I SPIN23 SPIN23I NPLT2 NPLT2I SPLT2 SPLT2I NPOUT23 NPOUT23I SPOUT23 SPOUT23I      NSD     NSDI     NSUM    NSUMI
158 - -------- -------- ------- ------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------ ------- ------ ------- ------- -------- ------- -------- ----- ------ ----- ------ ---- ----- ---- ----- -------- -------- ---- ----- ---- ----- -------- -------- -------- -------- -------- -------- -------- -------- ------- ------- ------- ------- ------- -------- ------- -------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------- -------- ------- -------- -------- -------- -------- --------
159 1     7.00     7.00       6       6  .333   .429  .333   .429   .333    .286   .333    .286  .500   .429  .500   .429      0       0      0       0    .667     .714    .667     .714     5      5     5      5    5     5    5     5     2.00     2.29    0     0    0     0     6.00     7.00     6.00     7.00     1.00      .00     1.00      .00       5       6       5       6       1        0       1        0  33.3   42.9  33.3   42.9   33.3    28.6   33.3    28.6  50.0   42.9  50.0   42.9    66.7     71.4    66.7     71.4     1.79     1.80    12.00    16.00 
160 2     5.00     5.00       4       4 1.000  1.000 1.000  1.000   .000    .000   .000    .000  .000   .000  .000   .000      6       6      6       4   1.000    1.000   1.000    1.000     8      8     8      8    8     8    8     8     7.00     7.00    6     6    6     4     3.00     3.00     3.00     5.00     2.00     2.00     2.00      .00       3       3       3       4       1        1       1        0 100.0  100.0 100.0  100.0     .0      .0     .0      .0    .0     .0    .0     .0   100.0    100.0   100.0    100.0     1.00     1.00    21.00    21.00 
161 3     2.00     2.00       1       1  .000   .000  .000   .000   .000    .000   .000    .000 1.000  1.000 1.000  1.000      1       1      1       1   1.000    1.000   1.000    1.000     1      1     1      1    1     1    1     1     1.00     1.00    1     1    1     1     2.00     2.00     2.00     2.00      .00      .00      .00      .00       1       1       1       1       0        0       0        0    .0     .0    .0     .0     .0      .0     .0      .0 100.0  100.0 100.0  100.0   100.0    100.0   100.0    100.0      .00      .00     2.00     2.00 
162 4     1.00     1.00       1       1  .      .     .     1.000   .       .      .       .000  .      .     .      .000      .       .              4    .        .       .       1.000     .      .            4    .     .          4      .        .      .     .          4      .00      .00      .00     1.00     1.00     1.00     1.00      .00       0       0       0       1       1        1       1        0    .      .     .   100.0     .       .      .       .0    .      .     .      .0      .        .       .     100.0      .        .        .        .   
163 EOF
164
165 activity="expected output (columnwise missing) create"
166 cat > agg-columnwise.out <<EOF
167 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
168 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
169 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
170 warning: AGGREGATE: The value arguments passed to the FOUT function are out-of-order.  They will be treated as if they had been specified in the correct order.
171 G        N       NI      NU     NUI NFGT2 NFGT2I SFGT2 SFGT2I NFIN23 NFIN23I SFIN23 SFIN23I NFLT2 NFLT2I SFLT2 SFLT2I NFIRST NFIRSTI SFIRST SFIRSTI NFOUT23 NFOUT23I SFOUT23 SFOUT23I NLAST NLASTI SLAST SLASTI NMAX NMAXI SMAX SMAXI    NMEAN   NMEANI NMIN NMINI SMIN SMINI       NN      NNI       SN      SNI   NNMISS  NNMISSI   SNMISS  SNMISSI     NNU    NNUI     SNU    SNUI NNUMISS NNUMISSI SNUMISS SNUMISSI NPGT2 NPGT2I SPGT2 SPGT2I NPIN23 NPIN23I SPIN23 SPIN23I NPLT2 NPLT2I SPLT2 SPLT2I NPOUT23 NPOUT23I SPOUT23 SPOUT23I      NSD     NSDI     NSUM    NSUMI
172 - -------- -------- ------- ------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------ ------- ------ ------- ------- -------- ------- -------- ----- ------ ----- ------ ---- ----- ---- ----- -------- -------- ---- ----- ---- ----- -------- -------- -------- -------- -------- -------- -------- -------- ------- ------- ------- ------- ------- -------- ------- -------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------- -------- ------- -------- -------- -------- -------- --------
173 1     7.00     7.00       6       6  .      .429  .      .429   .       .286   .       .286  .      .429  .      .429      .       0              0    .        .714    .        .714     .      5            5    .     5          5      .       2.29    .     0          0     6.00     7.00     6.00     7.00     1.00      .00     1.00      .00       5       6       5       6       1        0       1        0    .    42.9    .    42.9     .     28.6     .     28.6    .    42.9    .    42.9      .      71.4      .      71.4      .       1.80      .      16.00 
174 2     5.00     5.00       4       4  .      .     .     1.000   .       .      .       .000  .      .     .      .000      .       .              4    .        .       .       1.000     .      .            8    .     .          8      .        .      .     .          4     3.00     3.00     3.00     5.00     2.00     2.00     2.00      .00       3       3       3       4       1        1       1        0    .      .     .   100.0     .       .      .       .0    .      .     .      .0      .        .       .     100.0      .        .        .        .   
175 3     2.00     2.00       1       1  .000   .000  .000   .000   .000    .000   .000    .000 1.000  1.000 1.000  1.000      1       1      1       1   1.000    1.000   1.000    1.000     1      1     1      1    1     1    1     1     1.00     1.00    1     1    1     1     2.00     2.00     2.00     2.00      .00      .00      .00      .00       1       1       1       1       0        0       0        0    .0     .0    .0     .0     .0      .0     .0      .0 100.0  100.0 100.0  100.0   100.0    100.0   100.0    100.0      .00      .00     2.00     2.00 
176 4     1.00     1.00       1       1  .      .     .     1.000   .       .      .       .000  .      .     .      .000      .       .              4    .        .       .       1.000     .      .            4    .     .          4      .        .      .     .          4      .00      .00      .00     1.00     1.00     1.00     1.00      .00       0       0       0       1       1        1       1        0    .      .     .   100.0     .       .      .       .0    .      .     .      .0      .        .       .     100.0      .        .        .        .   
177 EOF
178
179 for outfile in scratch active external; do
180     for sort in presorted unsorted; do
181         for missing in itemwise columnwise; do
182             name=$outfile-$sort-$missing
183
184             activity="create $name.pspp"
185             {
186                 echo "data list notable file='aggregate.data' /G N 1-2 S 3(a) W 4."
187                 echo "weight by w."
188                 echo "missing values n(4) s('4')."
189                 if [ "$sort" = "presorted" ]; then
190                     echo "sort cases by g."
191                 fi
192                 echo "aggregate"
193                 if [ "$outfile" = "active" ]; then
194                     echo "      outfile=*"
195                 elif [ "$outfile" = "external" ]; then
196                     echo "      outfile='aggregate.sys'"
197                 else
198                     echo "      outfile=#AGGREGATE"
199                 fi
200                 if [ "$sort" = "presorted" ]; then
201                     echo "      /presorted"
202                 fi
203                 if [ "$missing" = "columnwise" ]; then
204                     echo "      /missing=columnwise"
205                 fi
206                 cat agg-skel.pspp
207                 if [ "$outfile" = "external" ]; then
208                     echo "get file='aggregate.sys'."
209                 elif [ "$outfile" = "scratch" ]; then
210                     echo "get file=#AGGREGATE."
211                 fi
212                 echo "list."
213             } > $name.pspp
214             if [ $? -ne 0 ] ; then no_result ; fi
215             
216             activity="run $name.pspp"
217             $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
218             if [ $? -ne 0 ] ; then no_result ; fi
219
220             activity="check $name output"
221             perl -pi -e 's/^\s*$//g;s/^.*:\d+: //;' pspp.list agg-$missing.out
222             diff -b -w pspp.list agg-$missing.out
223             if [ $? -ne 0 ] ; then fail ; fi
224         done
225     done
226 done
227
228 pass;