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 Perl program"
81 cat > num-in.pl <<'EOF'
90 for my $number (0, 1, .5, .015625, 123) {
91 my ($base_exp) = floor ($number ? log10 ($number) : 0);
92 for my $offset (-3...3) {
93 my ($exponent) = $base_exp + $offset;
94 my ($fraction) = $number / 10**$offset;
96 permute_zeros ($fraction, $exponent);
101 my ($fraction, $exponent) = @_;
103 my ($frac_rep) = sprintf ("%f", $fraction);
104 my ($leading_zeros) = length (($frac_rep =~ /^(0*)/)[0]);
105 my ($trailing_zeros) = length (($frac_rep =~ /(\.?0*)$/)[0]);
106 for my $i (0...$leading_zeros) {
107 for my $j (0...$trailing_zeros) {
108 my ($trimmed) = substr ($frac_rep, $i,
109 length ($frac_rep) - $i - $j);
110 next if $trimmed eq '.' || $trimmed eq '';
112 permute_commas ($trimmed, $exponent);
118 my ($frac_rep, $exponent) = @_;
119 permute_dot_comma ($frac_rep, $exponent);
120 my ($pos) = int (my_rand (length ($frac_rep) + 1));
121 $frac_rep = substr ($frac_rep, 0, $pos) . "," . substr ($frac_rep, $pos);
122 permute_dot_comma ($frac_rep, $exponent);
125 sub permute_dot_comma {
126 my ($frac_rep, $exponent) = @_;
127 permute_exponent_syntax ($frac_rep, $exponent);
128 if ($frac_rep =~ /[,.]/) {
129 $frac_rep =~ tr/.,/,./;
130 permute_exponent_syntax ($frac_rep, $exponent);
134 sub permute_exponent_syntax {
135 my ($frac_rep, $exponent) = @_;
137 if ($exponent == 0) {
138 @exp_reps = pick ('', 'e0', 'e-0', 'e+0', '-0', '+0');
139 } elsif ($exponent > 0) {
140 @exp_reps = pick ("e$exponent", "e+$exponent", "+$exponent");
142 my ($abs_exp) = -$exponent;
143 @exp_reps = pick ("e-$abs_exp", , "e-$abs_exp", "-$abs_exp");
145 permute_sign_and_affix ($frac_rep, $_) foreach @exp_reps;
148 sub permute_sign_and_affix {
149 my ($frac_rep, $exp_rep) = @_;
150 for my $prefix (pick ('', '$'),
151 pick ('-', '-$', '$-', '$-$'),
152 pick ('+', '+$', '$+', '$+$')) {
153 for my $suffix ('', '%') {
154 permute_spaces ("$prefix$frac_rep$exp_rep$suffix");
161 $s =~ s/([-+\$e%])/ $1 /g;
162 my (@fields) = split (' ', $s);
163 print join ('', @fields), "\n";
166 my ($pos) = int (my_rand ($#fields)) + 1;
167 print join ('', @fields[0...$pos - 1]);
169 print join ('', @fields[$pos...$#fields]);
175 return $_[int (my_rand ($#_ + 1))];
179 activity="generate data"
180 $PERL num-in.pl > num-in.data
181 if [ $? -ne 0 ] ; then no_result ; fi
184 activity="generate pspp syntax"
185 cat > num-in.pspp <<EOF
188 SET MXWARNS=10000000.
189 DATA LIST FILE='num-in.data' /
196 PRINT OUTFILE='num-in.out'/all (6f10.4).
199 if [ $? -ne 0 ] ; then no_result ; fi
202 activity="run program"
203 $SUPERVISOR $PSPP -o pspp.csv num-in.pspp
204 if [ $? -ne 0 ] ; then no_result ; fi
207 activity="gunzip expected results"
208 gzip -cd < $top_srcdir/tests/formats/num-in.expected.gz > num-in.expected
209 if [ $? -ne 0 ] ; then no_result ; fi
212 activity="compare output"
213 diff -u num-in.expected num-in.out
214 if [ $? -ne 0 ] ; then fail ; fi