3 TEMPDIR=/tmp/pspp-tst-$$
5 trap 'cd /; rm -rf $TEMPDIR' 0
7 # ensure that top_builddir are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp$EXEEXT
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
42 activity="write PRNG fragment"
43 cat > my-rand.pl <<'EOF'
44 # This random number generator and the test for it below are drawn
45 # from Park and Miller, "Random Number Generators: Good Ones are Hard
46 # to Come By", Communications of the ACM 31:10 (October 1988). It is
47 # documented to function properly on systems with a 46-bit or longer
48 # real significand, which includes systems that have 64-bit IEEE reals
49 # (with 53-bit significand). The test should catch any systems for
50 # which this is not true, in any case.
57 my ($tmp) = $a * $seed;
58 $seed = $tmp - $m * int ($tmp / $m);
59 return $seed % $modulo;
62 if [ $? -ne 0 ] ; then no_result ; fi
64 activity="write PRNG test program"
65 cat > test-my-rand.pl <<'EOF'
70 my_rand (1) foreach 1...10000;
72 die $seed if $seed != 1043618065;
74 if [ $? -ne 0 ] ; then no_result ; fi
78 if [ $? -ne 0 ] ; then no_result ; fi
80 activity="write program to generate PSPP syntax and data"
81 cat > time-in.pl <<'EOF'
89 my @formats = (["time", "+H:M", "+H:M:S"],
90 ["dtime", "+D H:M", "+D H:M:S"]);
92 my @times = (# D HH MM SS
100 [ 52, 15, 43, 49.27],
104 [555, 16, 45, 44.12],
105 [120, 21, 30, 57.27],
112 [ 22, 1, 56, 51.18]);
114 open (SYNTAX, '>', 'time-in.pspp') or die "time-in.pspp: create: $!\n";
115 for my $format (@formats) {
116 my ($name) = @$format;
117 print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
118 print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
119 print SYNTAX "EXECUTE.\n";
123 for my $format (@formats) {
124 my ($fmt_name, @templates) = @$format;
125 my ($fn) = "$fmt_name.data";
126 open (DATA, '>', $fn) or die "$fn: create: $!\n";
128 for my $template (@templates) {
129 for my $time (@times) {
130 print_time_with_template ($time, $template) for 1...10;
136 sub print_time_with_template {
137 my ($time, $template) = @_;
138 my ($day, $hour, $minute, $second) = @$time;
139 for my $c (split ('', $template)) {
141 print +pick ('', '-', '+');
142 } elsif ($c eq 'D') {
143 printf (+pick ('%d', '%02d'), $day);
145 } elsif ($c eq 'H') {
146 printf (+pick ('%d', '%02d'), $hour + 24 * $day);
147 } elsif ($c eq 'M') {
148 printf (+pick ('%d', '%02d'), $minute);
149 } elsif ($c eq 'S') {
150 printf (+pick ('%.0f', '%02.0f', '%.1f', '%.2f'), $second);
151 } elsif ($c eq ':') {
152 print +pick (' ', ':');
153 } elsif ($c eq ' ') {
163 return $_[int (my_rand ($#_ + 1))];
166 if [ $? -ne 0 ] ; then no_result ; fi
168 activity="generate PSPP syntax and data"
170 if [ $? -ne 0 ] ; then no_result ; fi
172 activity="run program"
173 $SUPERVISOR $PSPP -o pspp.csv time-in.pspp
174 if [ $? -ne 0 ] ; then no_result ; fi
176 activity="compare time.out output"
177 diff -u time.out - <<EOF
579 if [ $? -ne 0 ] ; then fail ; fi
581 activity="compare dtime.out output"
582 diff -u dtime.out - <<EOF
984 if [ $? -ne 0 ] ; then fail ; fi