641747b7173972d228238c19798cb18f99bc4795
[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 here=`pwd`;
9
10 # ensure that top_srcdir is absolute
11 cd $top_srcdir; top_srcdir=`pwd`
12
13 export STAT_CONFIG_PATH=$top_srcdir/config
14
15
16 cleanup()
17 {
18      rm -rf $TEMPDIR
19 }
20
21
22 fail()
23 {
24     echo $activity
25     echo FAILED
26     cleanup;
27     exit 1;
28 }
29
30
31 no_result()
32 {
33     echo $activity
34     echo NO RESULT;
35     cleanup;
36     exit 2;
37 }
38
39 pass()
40 {
41     cleanup;
42     exit 0;
43 }
44
45 mkdir -p $TEMPDIR
46
47 cd $TEMPDIR
48
49 cat > $TESTFILE <<EOF
50 title 'Test COUNT transformation'.
51
52 * we're going to count the 2s 4s and 1s in the data
53 data list /V1 to V2 1-4(a).
54 begin data.
55 1234
56 321      <----
57 2 13     <----
58 4121
59 1104     ---- this is not '4', but '04' (v1 and v2 are string format )
60 03 4     <----
61 0193
62 end data.
63 count C=v1 to v2('2',' 4','1').
64 list.
65 EOF
66 if [ $? -ne 0 ] ; then no_result ; fi
67
68
69 $SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE
70 if [ $? -ne 0 ] ; then no_result ; fi
71
72
73 activity="compare results"
74 diff -b -B $TEMPDIR/pspp.list - <<EOF
75 1.1 DATA LIST.  Reading 1 record from the command file.
76 +--------+------+-------+------+
77 |Variable|Record|Columns|Format|
78 #========#======#=======#======#
79 |V1      |     1|  1-  2|A2    |
80 |V2      |     1|  3-  4|A2    |
81 +--------+------+-------+------+
82
83 V1 V2        C
84 -- -- --------
85 12 34      .00 
86 32 1      1.00 
87 2  13     1.00 
88 41 21      .00 
89 11 04      .00 
90 03  4     1.00 
91 01 93      .00 
92 EOF
93 if [ $? -ne 0 ] ; then no_result ; fi
94
95
96 pass;