Rewrite PSPP output engine.
[pspp-builds.git] / tests / command / count.sh
1 #!/bin/sh
2
3 # This program tests the count transformation
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 File 1"
62 cat > $TESTFILE <<EOF
63 title 'Test COUNT transformation'.
64
65 * we're going to count the 2s 4s and 1s in the data
66 data list /V1 to V2 1-4(a).
67 begin data.
68 1234
69 321      <----
70 2 13     <----
71 4121
72 1104     ---- this is not '4', but '04' (v1 and v2 are string format )
73 03 4     <----
74 0193
75 end data.
76 count C=v1 to v2('2',' 4','1').
77 list.
78 EOF
79 if [ $? -ne 0 ] ; then no_result ; fi
80
81
82 activity="Run pspp 1"
83 $SUPERVISOR $PSPP --testing-mode $TESTFILE
84 if [ $? -ne 0 ] ; then no_result ; fi
85
86
87 activity="compare results 1"
88 diff -c $TEMPDIR/pspp.csv - <<EOF
89 Title: Test COUNT transformation
90
91 Table: Reading 1 record from INLINE.
92 Variable,Record,Columns,Format
93 V1,1,1-  2,A2
94 V2,1,3-  4,A2
95
96 Table: Data List
97 V1,V2,C
98 12,34,.00
99 32,1 ,1.00
100 2 ,13,1.00
101 41,21,.00
102 11,04,.00
103 03,4,1.00
104 01,93,.00
105 EOF
106 if [ $? -ne 0 ] ; then no_result ; fi
107
108
109
110
111 activity="Create file 2"
112 cat > $TESTFILE <<EOF
113 data list list /x * y *.
114 begin data.
115 1 2
116 2 3
117 4 5
118 2 2
119 5 6
120 end data.
121
122 count C=x y (2).
123
124 list.
125 EOF
126 if [ $? -ne 0 ] ; then no_result ; fi
127
128
129 activity="Run pspp 2"
130 $SUPERVISOR $PSPP --testing-mode $TESTFILE
131 if [ $? -ne 0 ] ; then no_result ; fi
132
133
134 activity="compare results"
135 diff -c $TEMPDIR/pspp.csv - <<EOF
136 Table: Reading free-form data from INLINE.
137 Variable,Format
138 x,F8.0
139 y,F8.0
140
141 Table: Data List
142 x,y,C
143 1.00,2.00,1.00
144 2.00,3.00,1.00
145 4.00,5.00,.00
146 2.00,2.00,2.00
147 5.00,6.00,.00
148 EOF
149 if [ $? -ne 0 ] ; then fail ; fi
150
151 pass;