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 Perl program"
80 cat > num-in.pl <<'EOF'
89 for my $number (0, 1, .5, .015625, 123) {
90 my ($base_exp) = floor ($number ? log10 ($number) : 0);
91 for my $offset (-3...3) {
92 my ($exponent) = $base_exp + $offset;
93 my ($fraction) = $number / 10**$offset;
95 permute_zeros ($fraction, $exponent);
100 my ($fraction, $exponent) = @_;
102 my ($frac_rep) = sprintf ("%f", $fraction);
103 my ($leading_zeros) = length (($frac_rep =~ /^(0*)/)[0]);
104 my ($trailing_zeros) = length (($frac_rep =~ /(\.?0*)$/)[0]);
105 for my $i (0...$leading_zeros) {
106 for my $j (0...$trailing_zeros) {
107 my ($trimmed) = substr ($frac_rep, $i,
108 length ($frac_rep) - $i - $j);
109 next if $trimmed eq '.' || $trimmed eq '';
111 permute_commas ($trimmed, $exponent);
117 my ($frac_rep, $exponent) = @_;
118 permute_dot_comma ($frac_rep, $exponent);
119 my ($pos) = int (my_rand (length ($frac_rep) + 1));
120 $frac_rep = substr ($frac_rep, 0, $pos) . "," . substr ($frac_rep, $pos);
121 permute_dot_comma ($frac_rep, $exponent);
124 sub permute_dot_comma {
125 my ($frac_rep, $exponent) = @_;
126 permute_exponent_syntax ($frac_rep, $exponent);
127 if ($frac_rep =~ /[,.]/) {
128 $frac_rep =~ tr/.,/,./;
129 permute_exponent_syntax ($frac_rep, $exponent);
133 sub permute_exponent_syntax {
134 my ($frac_rep, $exponent) = @_;
136 if ($exponent == 0) {
137 @exp_reps = pick ('', 'e0', 'e-0', 'e+0', '-0', '+0');
138 } elsif ($exponent > 0) {
139 @exp_reps = pick ("e$exponent", "e+$exponent", "+$exponent");
141 my ($abs_exp) = -$exponent;
142 @exp_reps = pick ("e-$abs_exp", , "e-$abs_exp", "-$abs_exp");
144 permute_sign_and_affix ($frac_rep, $_) foreach @exp_reps;
147 sub permute_sign_and_affix {
148 my ($frac_rep, $exp_rep) = @_;
149 for my $prefix (pick ('', '$'),
150 pick ('-', '-$', '$-', '$-$'),
151 pick ('+', '+$', '$+', '$+$')) {
152 for my $suffix ('', '%') {
153 permute_spaces ("$prefix$frac_rep$exp_rep$suffix");
160 $s =~ s/([-+\$e%])/ $1 /g;
161 my (@fields) = split (' ', $s);
162 print join ('', @fields), "\n";
165 my ($pos) = int (my_rand ($#fields)) + 1;
166 print join ('', @fields[0...$pos - 1]);
168 print join ('', @fields[$pos...$#fields]);
174 return $_[int (my_rand ($#_ + 1))];
178 activity="generate data"
179 $PERL num-in.pl > num-in.data
180 if [ $? -ne 0 ] ; then no_result ; fi
183 activity="generate pspp syntax"
184 cat > num-in.pspp <<EOF
187 SET MXWARNS=10000000.
188 DATA LIST FILE='num-in.data' /
195 PRINT OUTFILE='num-in.out'/all (6f10.4).
198 if [ $? -ne 0 ] ; then no_result ; fi
201 activity="run program"
202 $SUPERVISOR $PSPP --testing-mode num-in.pspp
203 if [ $? -ne 0 ] ; then no_result ; fi
206 activity="gunzip expected results"
207 gzip -cd < $top_srcdir/tests/formats/num-in.expected.gz > num-in.expected
208 if [ $? -ne 0 ] ; then no_result ; fi
211 activity="compare output"
212 diff -u num-in.expected num-in.out
213 if [ $? -ne 0 ] ; then fail ; fi