tests: Fix bug in NPAR TESTS subtest for CHISQUARE command.
[pspp-builds.git] / tests / command / autorecod.sh
1 #!/bin/sh
2
3 # This program tests the autorecode command
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8
9 # ensure that top_builddir  are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
14
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
17
18 STAT_CONFIG_PATH=$top_srcdir/config
19 export STAT_CONFIG_PATH
20
21 LANG=C
22 export LANG
23
24 cleanup()
25 {
26      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
27         echo "NOT cleaning $TEMPDIR" 
28         return ; 
29      fi
30      cd /
31      rm -rf $TEMPDIR
32 }
33
34
35 fail()
36 {
37     echo $activity
38     echo FAILED
39     cleanup;
40     exit 1;
41 }
42
43
44 no_result()
45 {
46     echo $activity
47     echo NO RESULT;
48     cleanup;
49     exit 2;
50 }
51
52 pass()
53 {
54     cleanup;
55     exit 0;
56 }
57
58 mkdir -p $TEMPDIR
59
60 cd $TEMPDIR
61
62 activity="create program"
63 cat > $TESTFILE <<EOF
64 /* Tries AUTORECODE on some random but similar strings of characters.
65 data list /X 1-5(a) Y 7.
66 begin data.
67 lasdj 1 1                                                           3
68 asdfk 0 3 <---- These are the numbers that should be produced for a 4
69 asdfj 2 4                                                           2
70 asdfj 1 4                                                           3
71 asdfk 2 3                                                           2
72 asdfj 9 4                                                           1
73 lajks 9 2                                                           1
74 asdfk 0 3 These are the numbers that should be produced for b ----> 4
75 asdfk 1 3                                                           3
76 end data.
77
78 autorecode x y into A B/descend.
79
80 list.
81 /* Just to make sure it works on second & subsequent executions,
82 /* try it again.
83 compute Z=trunc(y/2).
84 autorecode z into W.
85 list.
86 EOF
87 if [ $? -ne 0 ] ; then no_result ; fi
88
89 activity="run program"
90 $SUPERVISOR $PSPP -o pspp.csv $TESTFILE
91 if [ $? -ne 0 ] ; then no_result ; fi
92
93 activity="test output"
94 diff -b $TEMPDIR/pspp.csv - <<EOF
95 Table: Reading 1 record from INLINE.
96 Variable,Record,Columns,Format
97 X,1,1-  5,A5
98 Y,1,7-  7,F1.0
99
100 Table: Data List
101 X,Y,A,B
102 lasdj,1,1.00,3.00
103 asdfk,0,3.00,4.00
104 asdfj,2,4.00,2.00
105 asdfj,1,4.00,3.00
106 asdfk,2,3.00,2.00
107 asdfj,9,4.00,1.00
108 lajks,9,2.00,1.00
109 asdfk,0,3.00,4.00
110 asdfk,1,3.00,3.00
111
112 Table: Data List
113 X,Y,A,B,Z,W
114 lasdj,1,1.00,3.00,.00,1.00
115 asdfk,0,3.00,4.00,.00,1.00
116 asdfj,2,4.00,2.00,1.00,2.00
117 asdfj,1,4.00,3.00,.00,1.00
118 asdfk,2,3.00,2.00,1.00,2.00
119 asdfj,9,4.00,1.00,4.00,3.00
120 lajks,9,2.00,1.00,4.00,3.00
121 asdfk,0,3.00,4.00,.00,1.00
122 asdfk,1,3.00,3.00,.00,1.00
123 EOF
124 if [ $? -ne 0 ] ; then fail ; fi
125
126 pass
127
128
129