Checkin of new directory structure.
[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
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
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 cat > $TESTFILE <<EOF
55 title 'Test COUNT transformation'.
56
57 * we're going to count the 2s 4s and 1s in the data
58 data list /V1 to V2 1-4(a).
59 begin data.
60 1234
61 321      <----
62 2 13     <----
63 4121
64 1104     ---- this is not '4', but '04' (v1 and v2 are string format )
65 03 4     <----
66 0193
67 end data.
68 count C=v1 to v2('2',' 4','1').
69 list.
70 EOF
71 if [ $? -ne 0 ] ; then no_result ; fi
72
73
74 $SUPERVISOR $top_builddir/src/pspp -o raw-ascii $TESTFILE
75 if [ $? -ne 0 ] ; then no_result ; fi
76
77
78 activity="compare results"
79 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
80 diff -b  $TEMPDIR/pspp.list - <<EOF
81 1.1 DATA LIST.  Reading 1 record from INLINE.
82 +--------+------+-------+------+
83 |Variable|Record|Columns|Format|
84 #========#======#=======#======#
85 |V1      |     1|  1-  2|A2    |
86 |V2      |     1|  3-  4|A2    |
87 +--------+------+-------+------+
88 V1 V2        C
89 -- -- --------
90 12 34      .00 
91 32 1      1.00 
92 2  13     1.00 
93 41 21      .00 
94 11 04      .00 
95 03  4     1.00 
96 01 93      .00 
97 EOF
98 if [ $? -ne 0 ] ; then no_result ; fi
99
100
101 pass;