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