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