263bf8156a68c7f65d8dd8bccf3b66d845ecedac
[pspp-builds.git] / tests / bugs / random.sh
1 #!/bin/sh
2
3 # This program tests for a bug which caused UNIFORM(x) to always return zero.
4
5
6 TEMPDIR=/tmp/pspp-tst-$$
7 TESTFILE=$TEMPDIR/`basename $0`.sps
8
9 here=`pwd`;
10
11 # ensure that top_srcdir is absolute
12 cd $top_srcdir; top_srcdir=`pwd`
13
14 STAT_CONFIG_PATH=$top_srcdir/config
15 export STAT_CONFIG_PATH
16
17
18 cleanup()
19 {
20      cd /
21      rm -rf $TEMPDIR
22 }
23
24
25 fail()
26 {
27     echo $activity
28     echo FAILED
29     cleanup;
30     exit 1;
31 }
32
33
34 no_result()
35 {
36     echo $activity
37     echo NO RESULT;
38     cleanup;
39     exit 2;
40 }
41
42 pass()
43 {
44     cleanup;
45     exit 0;
46 }
47
48 mkdir -p $TEMPDIR
49
50 cd $TEMPDIR
51
52 activity="create program"
53 cat > $TESTFILE <<EOF
54 set seed=10.
55 input program.
56 + loop #i = 1 to 20.
57 +    do repeat response=R1.
58 +       compute response = uniform(10).
59 +    end repeat.
60 +    end case.
61 + end loop.
62 + end file.
63 end input program.                                                              
64
65 list.
66 EOF
67 if [ $? -ne 0 ] ; then no_result ; fi
68
69 activity="run program"
70 $SUPERVISOR $here/../src/pspp -o raw-ascii $TESTFILE
71 if [ $? -ne 0 ] ; then no_result ; fi
72
73
74 activity="compare output"
75 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
76 diff -b  -w $TEMPDIR/pspp.list - << EOF
77       R1
78 --------
79      7.71 
80      2.99 
81       .21 
82      4.95 
83      6.34 
84      4.43 
85      7.49 
86      8.32 
87      4.99 
88      5.83 
89      2.25 
90       .25 
91      1.98 
92      7.09 
93      7.61 
94      2.66 
95      1.69 
96      2.64 
97       .88 
98      1.50 
99 EOF
100 if [ $? -ne 0 ] ; then fail ; fi
101
102 pass;