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
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
41 activity="write PRNG fragment"
42 cat > my-rand.pl <<'EOF'
43 # This random number generator and the test for it below are drawn
44 # from Park and Miller, "Random Number Generators: Good Ones are Hard
45 # to Come By", Communications of the ACM 31:10 (October 1988). It is
46 # documented to function properly on systems with a 46-bit or longer
47 # real significand, which includes systems that have 64-bit IEEE reals
48 # (with 53-bit significand). The test should catch any systems for
49 # which this is not true, in any case.
56 my ($tmp) = $a * $seed;
57 $seed = $tmp - $m * int ($tmp / $m);
58 return $seed % $modulo;
61 if [ $? -ne 0 ] ; then no_result ; fi
63 activity="write PRNG test program"
64 cat > test-my-rand.pl <<'EOF'
69 my_rand (1) foreach 1...10000;
71 die $seed if $seed != 1043618065;
73 if [ $? -ne 0 ] ; then no_result ; fi
77 if [ $? -ne 0 ] ; then no_result ; fi
79 activity="write program to generate PSPP syntax and data"
80 cat > time-in.pl <<'EOF'
88 my @formats = (["time", "+H:M", "+H:M:S"],
89 ["dtime", "+D H:M", "+D H:M:S"]);
91 my @times = (# D HH MM SS
103 [555, 16, 45, 44.12],
104 [120, 21, 30, 57.27],
111 [ 22, 1, 56, 51.18]);
113 open (SYNTAX, '>', 'time-in.pspp') or die "time-in.pspp: create: $!\n";
114 for my $format (@formats) {
115 my ($name) = @$format;
116 print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
117 print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
118 print SYNTAX "EXECUTE.\n";
122 for my $format (@formats) {
123 my ($fmt_name, @templates) = @$format;
124 my ($fn) = "$fmt_name.data";
125 open (DATA, '>', $fn) or die "$fn: create: $!\n";
127 for my $template (@templates) {
128 for my $time (@times) {
129 print_time_with_template ($time, $template) for 1...10;
135 sub print_time_with_template {
136 my ($time, $template) = @_;
137 my ($day, $hour, $minute, $second) = @$time;
138 for my $c (split ('', $template)) {
140 print +pick ('', '-', '+');
141 } elsif ($c eq 'D') {
142 printf (+pick ('%d', '%02d'), $day);
144 } elsif ($c eq 'H') {
145 printf (+pick ('%d', '%02d'), $hour + 24 * $day);
146 } elsif ($c eq 'M') {
147 printf (+pick ('%d', '%02d'), $minute);
148 } elsif ($c eq 'S') {
149 printf (+pick ('%.0f', '%02.0f', '%.1f', '%.2f'), $second);
150 } elsif ($c eq ':') {
151 print +pick (' ', ':');
152 } elsif ($c eq ' ') {
162 return $_[int (my_rand ($#_ + 1))];
165 if [ $? -ne 0 ] ; then no_result ; fi
167 activity="generate PSPP syntax and data"
169 if [ $? -ne 0 ] ; then no_result ; fi
171 activity="run program"
172 $SUPERVISOR $PSPP --testing-mode time-in.pspp
173 if [ $? -ne 0 ] ; then no_result ; fi
175 activity="compare time.out output"
176 diff -u time.out - <<EOF
578 if [ $? -ne 0 ] ; then fail ; fi
580 activity="compare dtime.out output"
581 diff -u dtime.out - <<EOF
983 if [ $? -ne 0 ] ; then fail ; fi