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 Perl program"
42 cat > num-in.pl <<'EOF'
51 for my $number (0, 1, .5, .015625, 123) {
52 my ($base_exp) = floor ($number ? log10 ($number) : 0);
53 for my $offset (-3...3) {
54 my ($exponent) = $base_exp + $offset;
55 my ($fraction) = $number / 10**$offset;
57 permute_zeros ($fraction, $exponent);
62 my ($fraction, $exponent) = @_;
64 my ($frac_rep) = sprintf ("%f", $fraction);
65 my ($leading_zeros) = length (($frac_rep =~ /^(0*)/)[0]);
66 my ($trailing_zeros) = length (($frac_rep =~ /(\.?0*)$/)[0]);
67 for my $i (0...$leading_zeros) {
68 for my $j (0...$trailing_zeros) {
69 my ($trimmed) = substr ($frac_rep, $i,
70 length ($frac_rep) - $i - $j);
71 next if $trimmed eq '.' || $trimmed eq '';
73 permute_commas ($trimmed, $exponent);
79 my ($frac_rep, $exponent) = @_;
80 permute_dot_comma ($frac_rep, $exponent);
81 my ($pos) = int (my_rand (length ($frac_rep) + 1));
82 $frac_rep = substr ($frac_rep, 0, $pos) . "," . substr ($frac_rep, $pos);
83 permute_dot_comma ($frac_rep, $exponent);
86 sub permute_dot_comma {
87 my ($frac_rep, $exponent) = @_;
88 permute_exponent_syntax ($frac_rep, $exponent);
89 if ($frac_rep =~ /[,.]/) {
90 $frac_rep =~ tr/.,/,./;
91 permute_exponent_syntax ($frac_rep, $exponent);
95 sub permute_exponent_syntax {
96 my ($frac_rep, $exponent) = @_;
99 @exp_reps = pick ('', 'e0', 'e-0', 'e+0', '-0', '+0');
100 } elsif ($exponent > 0) {
101 @exp_reps = pick ("e$exponent", "e+$exponent", "+$exponent");
103 my ($abs_exp) = -$exponent;
104 @exp_reps = pick ("e-$abs_exp", , "e-$abs_exp", "-$abs_exp");
106 permute_sign_and_affix ($frac_rep, $_) foreach @exp_reps;
109 sub permute_sign_and_affix {
110 my ($frac_rep, $exp_rep) = @_;
111 for my $prefix (pick ('', '$'),
112 pick ('-', '-$', '$-', '$-$'),
113 pick ('+', '+$', '$+', '$+$')) {
114 for my $suffix ('', '%') {
115 permute_spaces ("$prefix$frac_rep$exp_rep$suffix");
122 $s =~ s/([-+\$e%])/ $1 /g;
123 my (@fields) = split (' ', $s);
124 print join ('', @fields), "\n";
127 my ($pos) = int (my_rand ($#fields)) + 1;
128 print join ('', @fields[0...$pos - 1]);
130 print join ('', @fields[$pos...$#fields]);
136 return $_[int (my_rand ($#_ + 1))];
141 $next = ($next * 1103515245 + 12345) % (2**32);
142 return int ($next / 65536) % $modulo;
146 activity="generate data"
147 $PERL num-in.pl > num-in.data
148 if [ $? -ne 0 ] ; then no_result ; fi
151 activity="generate pspp syntax"
152 cat > num-in.pspp <<EOF
155 SET MXWARNS=10000000.
156 DATA LIST FILE='num-in.data' /
163 PRINT OUTFILE='num-in.out'/all (6f10.4).
166 if [ $? -ne 0 ] ; then no_result ; fi
169 activity="run program"
170 $SUPERVISOR $PSPP --testing-mode num-in.pspp
171 if [ $? -ne 0 ] ; then no_result ; fi
174 activity="gunzip expected results"
175 gzip -cd < $top_srcdir/tests/formats/num-in.expected.gz > num-in.expected
176 if [ $? -ne 0 ] ; then no_result ; fi
179 activity="compare output"
180 diff -u num-in.expected num-in.out
181 if [ $? -ne 0 ] ; then fail ; fi