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