Fix crash when opening empty dataset
[pspp-builds.git] / tests / command / examine.sh
1 #!/bin/sh
2
3 # This program tests  the EXAMINE command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_builddir  are absolute
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 top_builddir=`cd $top_builddir; pwd`
12 PSPP=$top_builddir/src/ui/terminal/pspp
13
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20 LANG=C
21 export LANG
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 program"
62 cat > $TESTFILE <<EOF
63 DATA LIST LIST /QUALITY * W * BRAND * .
64 BEGIN DATA
65 3  1  1
66 2  2  1
67 1  2  1
68 1  1  1
69 4  1  1
70 4  1  1
71 5  1  2
72 2  1  2
73 4  4  2
74 2  1  2
75 3  1  2
76 7  1  3
77 4  2  3
78 5  3  3
79 3  1  3
80 6  1  3
81 END DATA
82
83 WEIGHT BY w.
84
85 VARIABLE LABELS brand   'Manufacturer'.
86 VARIABLE LABELS quality 'Breaking Strain'.
87
88 VALUE LABELS /brand 1 'Aspeger' 2 'Bloggs' 3 'Charlies'.
89
90 LIST /FORMAT=NUMBERED.
91
92 EXAMINE
93         quality BY brand
94         /STATISTICS descriptives extreme(3)
95         .
96 EOF
97 if [ $? -ne 0 ] ; then no_result ; fi
98
99
100 activity="run program"
101 $SUPERVISOR $PSPP --testing-mode $TESTFILE
102 if [ $? -ne 0 ] ; then no_result ; fi
103
104 # NOTE:  In the following data: Only the extreme values have been checked
105 # The descriptives have been blindly pasted.
106 activity="compare results"
107 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
108 diff -b  $TEMPDIR/pspp.list - << EOF
109 1.1 DATA LIST.  Reading free-form data from INLINE.
110 +--------+------+
111 |Variable|Format|
112 #========#======#
113 |QUALITY |F8.0  |
114 |W       |F8.0  |
115 |BRAND   |F8.0  |
116 +--------+------+
117 Case#  QUALITY        W    BRAND
118 ----- -------- -------- --------
119     1     3.00     1.00     1.00 
120     2     2.00     2.00     1.00 
121     3     1.00     2.00     1.00 
122     4     1.00     1.00     1.00 
123     5     4.00     1.00     1.00 
124     6     4.00     1.00     1.00 
125     7     5.00     1.00     2.00 
126     8     2.00     1.00     2.00 
127     9     4.00     4.00     2.00 
128    10     2.00     1.00     2.00 
129    11     3.00     1.00     2.00 
130    12     7.00     1.00     3.00 
131    13     4.00     2.00     3.00 
132    14     5.00     3.00     3.00 
133    15     3.00     1.00     3.00 
134    16     6.00     1.00     3.00 
135 2.1 EXAMINE.  Case Processing Summary
136 #===============#=======================================#
137 #               #                 Cases                 #
138 #               #-------------+-----------+-------------#
139 #               #    Valid    |  Missing  |    Total    #
140 #               #-----+-------+---+-------+-----+-------#
141 #               #  N  |Percent| N |Percent|  N  |Percent#
142 #===============#=====#=======#===#=======#=====#=======#
143 #Breaking Strain#24.00|   100%|.00|     0%|24.00|   100%#
144 #===============#=====#=======#===#=======#=====#=======#
145 2.2 EXAMINE.  Extreme Values
146 #=========================#===========#=====#
147 #                         #Case Number|Value#
148 #=========================#===========#=====#
149 #Breaking Strain Highest 1#         12| 7.00#
150 #                        2#         16| 6.00#
151 #                        3#          7| 5.00#
152 #               ----------#-----------+-----#
153 #                 Lowest 1#          3| 1.00#
154 #                        2#          3| 1.00#
155 #                        3#          4| 1.00#
156 #=========================#===========#=====#
157 2.3 EXAMINE.  Descriptives
158 #============================================================#=========#==========#
159 #                                                            #Statistic|Std. Error#
160 #============================================================#=========#==========#
161 #Breaking Strain Mean                                        #   3.54  |    .32   #
162 #                95% Confidence Interval for Mean Lower Bound#   2.87  |          #
163 #                                                 Upper Bound#   4.21  |          #
164 #                5% Trimmed Mean                             #   3.50  |          #
165 #                Median                                      #   4.00  |          #
166 #                Variance                                    #   2.52  |          #
167 #                Std. Deviation                              #   1.59  |          #
168 #                Minimum                                     #   1.00  |          #
169 #                Maximum                                     #   7.00  |          #
170 #                Range                                       #   6.00  |          #
171 #                Interquartile Range                         #   2.75  |          #
172 #                Skewness                                    #   .06   |    .47   #
173 #                Kurtosis                                    #   -.36  |    .92   #
174 #============================================================#=========#==========#
175 2.4 EXAMINE.  Case Processing Summary
176 #============================#=====================================#
177 #                            #                Cases                #
178 #                            #------------+-----------+------------#
179 #                            #    Valid   |  Missing  |    Total   #
180 #                            #----+-------+---+-------+----+-------#
181 #                Manufacturer#  N |Percent| N |Percent|  N |Percent#
182 #============================#====#=======#===#=======#====#=======#
183 #Breaking Strain Aspeger     #8.00|   100%|.00|     0%|8.00|   100%#
184 #                Bloggs      #8.00|   100%|.00|     0%|8.00|   100%#
185 #                Charlies    #8.00|   100%|.00|     0%|8.00|   100%#
186 #============================#====#=======#===#=======#====#=======#
187 2.5 EXAMINE.  Extreme Values
188 #======================================#===========#=====#
189 #                Manufacturer          #Case Number|Value#
190 #======================================#===========#=====#
191 #Breaking Strain Aspeger      Highest 1#          5| 4.00#
192 #                                     2#          6| 4.00#
193 #                                     3#          1| 3.00#
194 #                            ----------#-----------+-----#
195 #                              Lowest 1#          3| 1.00#
196 #                                     2#          3| 1.00#
197 #                                     3#          4| 1.00#
198 #               -----------------------#-----------+-----#
199 #                Bloggs       Highest 1#          7| 5.00#
200 #                                     2#          9| 4.00#
201 #                                     3#          9| 4.00#
202 #                            ----------#-----------+-----#
203 #                              Lowest 1#          8| 2.00#
204 #                                     2#         10| 2.00#
205 #                                     3#         11| 3.00#
206 #               -----------------------#-----------+-----#
207 #                Charlies     Highest 1#         12| 7.00#
208 #                                     2#         16| 6.00#
209 #                                     3#         14| 5.00#
210 #                            ----------#-----------+-----#
211 #                              Lowest 1#         15| 3.00#
212 #                                     2#         13| 4.00#
213 #                                     3#         13| 4.00#
214 #======================================#===========#=====#
215 2.6 EXAMINE.  Descriptives
216 #=========================================================================#=========#==========#
217 #                Manufacturer                                             #Statistic|Std. Error#
218 #=========================================================================#=========#==========#
219 #Breaking Strain Aspeger      Mean                                        #   2.25  |    .45   #
220 #                             95% Confidence Interval for Mean Lower Bound#   1.18  |          #
221 #                                                              Upper Bound#   3.32  |          #
222 #                             5% Trimmed Mean                             #   2.22  |          #
223 #                             Median                                      #   2.00  |          #
224 #                             Variance                                    #   1.64  |          #
225 #                             Std. Deviation                              #   1.28  |          #
226 #                             Minimum                                     #   1.00  |          #
227 #                             Maximum                                     #   4.00  |          #
228 #                             Range                                       #   3.00  |          #
229 #                             Interquartile Range                         #   2.75  |          #
230 #                             Skewness                                    #   .47   |    .75   #
231 #                             Kurtosis                                    #  -1.55  |   1.48   #
232 #               ----------------------------------------------------------#---------+----------#
233 #                Bloggs       Mean                                        #   3.50  |    .38   #
234 #                             95% Confidence Interval for Mean Lower Bound#   2.61  |          #
235 #                                                              Upper Bound#   4.39  |          #
236 #                             5% Trimmed Mean                             #   3.50  |          #
237 #                             Median                                      #   4.00  |          #
238 #                             Variance                                    #   1.14  |          #
239 #                             Std. Deviation                              #   1.07  |          #
240 #                             Minimum                                     #   2.00  |          #
241 #                             Maximum                                     #   5.00  |          #
242 #                             Range                                       #   3.00  |          #
243 #                             Interquartile Range                         #   1.75  |          #
244 #                             Skewness                                    #   -.47  |    .75   #
245 #                             Kurtosis                                    #   -.83  |   1.48   #
246 #               ----------------------------------------------------------#---------+----------#
247 #                Charlies     Mean                                        #   4.88  |    .44   #
248 #                             95% Confidence Interval for Mean Lower Bound#   3.83  |          #
249 #                                                              Upper Bound#   5.92  |          #
250 #                             5% Trimmed Mean                             #   4.86  |          #
251 #                             Median                                      #   5.00  |          #
252 #                             Variance                                    #   1.55  |          #
253 #                             Std. Deviation                              #   1.25  |          #
254 #                             Minimum                                     #   3.00  |          #
255 #                             Maximum                                     #   7.00  |          #
256 #                             Range                                       #   4.00  |          #
257 #                             Interquartile Range                         #   1.75  |          #
258 #                             Skewness                                    #   .30   |    .75   #
259 #                             Kurtosis                                    #   .15   |   1.48   #
260 #=========================================================================#=========#==========#
261 EOF
262 if [ $? -ne 0 ] ; then fail ; fi
263
264 pass