e1a16993ac071bbabbe637d092c97ddffc913f33
[pspp-builds.git] / tests / command / lag.sh
1 #!/bin/sh
2
3 # This program tests the LAG function
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 activity="create program"
51 cat > $TEMPDIR/lag.stat <<EOF
52 data list /W 1.
53 begin data.
54 1
55 2
56 3
57 4
58 5
59 end data.
60
61 compute X=lag(w,1).
62 compute Y=lag(x).
63 compute Z=lag(w,2).
64 list.
65 EOF
66 if [ $? -ne 0 ] ; then no_result ; fi
67
68 activity="run program"
69 $SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/lag.stat
70 if [ $? -ne 0 ] ; then no_result ; fi
71
72 activity="compare result"
73 diff -b -B $TEMPDIR/pspp.list - <<EOF
74 1.1 DATA LIST.  Reading 1 record from the command file.
75 +--------+------+-------+------+
76 |Variable|Record|Columns|Format|
77 #========#======#=======#======#
78 |W       |     1|  1-  1|F1.0  |
79 +--------+------+-------+------+
80
81 W        X        Y        Z
82 - -------- -------- --------
83 1      .        .        .   
84 2     1.00      .        .   
85 3     2.00     1.00     1.00 
86 4     3.00     2.00     2.00 
87 5     4.00     3.00     3.00 
88 EOF
89 if [ $? -ne 0 ] ; then fail ; fi
90
91
92 pass;