dd4cfd97e408e3aa38bbc91c41709ea7189c9ba6
[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
21 cleanup()
22 {
23      cd /
24      rm -rf $TEMPDIR
25 }
26
27
28 fail()
29 {
30     echo $activity
31     echo FAILED
32     cleanup;
33     exit 1;
34 }
35
36
37 no_result()
38 {
39     echo $activity
40     echo NO RESULT;
41     cleanup;
42     exit 2;
43 }
44
45 pass()
46 {
47     cleanup;
48     exit 0;
49 }
50
51 mkdir -p $TEMPDIR
52
53 cd $TEMPDIR
54
55 activity="Create File 1"
56 cat > $TESTFILE <<EOF
57 title 'Test COUNT transformation'.
58
59 * we're going to count the 2s 4s and 1s in the data
60 data list /V1 to V2 1-4(a).
61 begin data.
62 1234
63 321      <----
64 2 13     <----
65 4121
66 1104     ---- this is not '4', but '04' (v1 and v2 are string format )
67 03 4     <----
68 0193
69 end data.
70 count C=v1 to v2('2',' 4','1').
71 list.
72 EOF
73 if [ $? -ne 0 ] ; then no_result ; fi
74
75
76 activity="Run pspp 1"
77 $SUPERVISOR $PSPP -o raw-ascii $TESTFILE
78 if [ $? -ne 0 ] ; then no_result ; fi
79
80
81 activity="compare results"
82 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
83 diff -b  $TEMPDIR/pspp.list - <<EOF
84 1.1 DATA LIST.  Reading 1 record from INLINE.
85 +--------+------+-------+------+
86 |Variable|Record|Columns|Format|
87 #========#======#=======#======#
88 |V1      |     1|  1-  2|A2    |
89 |V2      |     1|  3-  4|A2    |
90 +--------+------+-------+------+
91 V1 V2        C
92 -- -- --------
93 12 34      .00 
94 32 1      1.00 
95 2  13     1.00 
96 41 21      .00 
97 11 04      .00 
98 03  4     1.00 
99 01 93      .00 
100 EOF
101 if [ $? -ne 0 ] ; then no_result ; fi
102
103
104
105
106 activity="Create file 2"
107 cat > $TESTFILE <<EOF
108 data list list /x * y *.
109 begin data.
110 1 2
111 2 3
112 4 5
113 2 2
114 5 6
115 end data.
116
117 count C=x y (2).
118
119 list.
120 EOF
121 if [ $? -ne 0 ] ; then no_result ; fi
122
123
124 activity="Run pspp 2"
125 $SUPERVISOR $PSPP -o raw-ascii $TESTFILE
126 if [ $? -ne 0 ] ; then no_result ; fi
127
128
129 activity="compare results"
130 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
131 diff -b  $TEMPDIR/pspp.list - <<EOF
132 1.1 DATA LIST.  Reading free-form data from INLINE.
133 +--------+------+
134 |Variable|Format|
135 #========#======#
136 |x       |F8.0  |
137 |y       |F8.0  |
138 +--------+------+
139        x        y        C
140 -------- -------- --------
141     1.00     2.00     1.00 
142     2.00     3.00     1.00 
143     4.00     5.00      .00 
144     2.00     2.00     2.00 
145     5.00     6.00      .00 
146 EOF
147 if [ $? -ne 0 ] ; then fail ; fi
148
149 pass;