Merge commit 'origin/stable'
[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      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
23         echo "NOT cleaning $TEMPDIR" 
24         return ; 
25      fi
26      cd /
27      rm -rf $TEMPDIR
28 }
29
30
31 fail()
32 {
33     echo $activity
34     echo FAILED
35     cleanup;
36     exit 1;
37 }
38
39
40 no_result()
41 {
42     echo $activity
43     echo NO RESULT;
44     cleanup;
45     exit 2;
46 }
47
48 pass()
49 {
50     cleanup;
51     exit 0;
52 }
53
54 mkdir -p $TEMPDIR
55
56 cd $TEMPDIR
57
58 activity="data create"
59 cat > aggregate.data <<EOF
60 2 42
61 1001
62 4 41
63 3112
64 1112
65 2661
66 1221
67 2771
68 1331
69 1441
70 2881
71 1551
72 EOF
73 if [ $? -ne 0 ] ; then no_result ; fi
74
75 activity="command skeleton create"
76 cat > agg-skel.pspp <<EOF
77         /document
78         /break=g
79         /N = n
80         /NI = n./
81         NU = nu
82         /NUI = nu./
83         NFGT2 = fgt(n, 2)
84         /NFGT2I = fgt.(n, 2)
85         /SFGT2 = fgt(s, '2')
86         /SFGT2I = fgt.(s, '2')
87         /NFIN23 = fin(n, 2, 3)
88         /NFIN23I = fin.(n, 2, 3)
89         /SFIN23 = fin(s, '2', '3')
90         /SFIN23I = fin.(s, '2', '3')
91         /NFLT2 = flt(n, 2)
92         /NFLT2I = flt.(n, 2)
93         /SFLT2 = flt(s, '2')
94         /SFLT2I = flt.(s, '2')
95         /NFIRST = first(n)
96         /NFIRSTI = first.(n)
97         /SFIRST = first(s)
98         /SFIRSTI = first.(s)
99         /NFOUT23 = fout(n, 3, 2)
100         /NFOUT23I = fout.(n, 3, 2)
101         /SFOUT23 = fout(s, '3', '2')
102         /SFOUT23I = fout.(s, '3', '2')
103         /NLAST = last(n)
104         /NLASTI = last.(n)
105         /SLAST = last(s)
106         /SLASTI = last.(s)
107         /NMAX = max(n)
108         /NMAXI = max.(n)
109         /SMAX = max(s)
110         /SMAXI = max.(s)
111         /NMEAN = mean(n)
112         /NMEANI = mean.(n)
113         /NMIN = min(n)
114         /NMINI = min.(n)
115         /SMIN = min(s)
116         /SMINI = min.(s)
117         /NN = n(n)
118         /NNI = n.(n)
119         /SN = n(s)
120         /SNI = n.(s)
121         /NNMISS = nmiss(n)
122         /NNMISSI = nmiss.(n)
123         /SNMISS = nmiss(s)
124         /SNMISSI = nmiss.(s)
125         /NNU = nu(n)
126         /NNUI = nu.(n)
127         /SNU = nu(s)
128         /SNUI = nu.(s)
129         /NNUMISS = numiss(n)
130         /NNUMISSI = numiss.(n)
131         /SNUMISS = numiss(s)
132         /SNUMISSI = numiss.(s)
133         /NPGT2 = pgt(n, 2)
134         /NPGT2I = pgt.(n, 2)
135         /SPGT2 = pgt(s, '2')
136         /SPGT2I = pgt.(s, '2')
137         /NPIN23 = pin(n, 2, 3)
138         /NPIN23I = pin.(n, 2, 3)
139         /SPIN23 = pin(s, '2', '3')
140         /SPIN23I = pin.(s, '2', '3')
141         /NPLT2 = plt(n, 2)
142         /NPLT2I = plt.(n, 2)
143         /SPLT2 = plt(s, '2')
144         /SPLT2I = plt.(s, '2')
145         /NPOUT23 = pout(n, 2, 3)
146         /NPOUT23I = pout.(n, 2, 3)
147         /SPOUT23 = pout(s, '2', '3')
148         /SPOUT23I = pout.(s, '2', '3')
149         /NMEDIAN = median(n)
150         /NMEDIANI = median.(n)
151         /NSD = sd(n)
152         /NSDI = sd.(n)
153         /NSUM = sum(n)
154         /NSUMI = sum.(n).
155 EOF
156
157 activity="expected output (itemwise missing) create"
158 cat > agg-itemwise.out <<EOF
159 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.
160 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.
161 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.
162 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.
163 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  NMEDIAN NMEDIANI      NSD     NSDI     NSUM    NSUMI
164 - -------- -------- ------- ------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------ ------- ------ ------- ------- -------- ------- -------- ----- ------ ----- ------ ---- ----- ---- ----- -------- -------- ---- ----- ---- ----- -------- -------- -------- -------- -------- -------- -------- -------- ------- ------- ------- ------- ------- -------- ------- -------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------- -------- ------- -------- -------- -------- -------- -------- -------- --------
165 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.50     2.00     1.79     1.80    12.00    16.00 
166 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     7.00     7.00     1.00     1.00    21.00    21.00 
167 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     1.00     1.00      .00      .00     2.00     2.00 
168 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      NaN      NaN      .        .        .        .   
169
170 EOF
171
172 activity="expected output (columnwise missing) create"
173 cat > agg-columnwise.out <<EOF
174 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.
175 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.
176 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.
177 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.
178 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  NMEDIAN NMEDIANI      NSD     NSDI     NSUM    NSUMI
179 - -------- -------- ------- ------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------ ------- ------ ------- ------- -------- ------- -------- ----- ------ ----- ------ ---- ----- ---- ----- -------- -------- ---- ----- ---- ----- -------- -------- -------- -------- -------- -------- -------- -------- ------- ------- ------- ------- ------- -------- ------- -------- ----- ------ ----- ------ ------ ------- ------ ------- ----- ------ ----- ------ ------- -------- ------- -------- -------- -------- -------- -------- -------- --------
180 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      .       2.00      .       1.80      .      16.00 
181 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      .        .        .        .        .        .   
182 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     1.00     1.00      .00      .00     2.00     2.00 
183 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      .        .        .        .        .        .   
184 EOF
185
186 for outfile in scratch active external; do
187     for sort in presorted unsorted; do
188         for missing in itemwise columnwise; do
189             name=$outfile-$sort-$missing
190
191             activity="create $name.pspp"
192             {
193                 echo "data list notable file='aggregate.data' /G N 1-2 S 3(a) W 4."
194                 echo "weight by w."
195                 echo "missing values n(4) s('4')."
196                 if [ "$sort" = "presorted" ]; then
197                     echo "sort cases by g."
198                 fi
199                 echo "aggregate"
200                 if [ "$outfile" = "active" ]; then
201                     echo "      outfile=*"
202                 elif [ "$outfile" = "external" ]; then
203                     echo "      outfile='aggregate.sys'"
204                 else
205                     echo "      outfile=#AGGREGATE"
206                 fi
207                 if [ "$sort" = "presorted" ]; then
208                     echo "      /presorted"
209                 fi
210                 if [ "$missing" = "columnwise" ]; then
211                     echo "      /missing=columnwise"
212                 fi
213                 cat agg-skel.pspp
214                 if [ "$outfile" = "external" ]; then
215                     echo "get file='aggregate.sys'."
216                 elif [ "$outfile" = "scratch" ]; then
217                     echo "get file=#AGGREGATE."
218                 fi
219                 echo "list."
220             } > $name.pspp
221             if [ $? -ne 0 ] ; then no_result ; fi
222             
223             activity="run $name.pspp"
224             $SUPERVISOR $PSPP --testing-mode -e /dev/null $name.pspp 
225             if [ $? -ne 0 ] ; then no_result ; fi
226
227             activity="check $name output"
228             perl -pi -e 's/^\s*$//g;s/^.*:\d+: //;' pspp.list agg-$missing.out
229             diff -b -w pspp.list agg-$missing.out
230             if [ $? -ne 0 ] ; then fail ; fi
231         done
232     done
233 done
234
235 pass;