X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Fdata%2Fdata-out.at;h=9a41a3b5fd4cdc1c5dc204d01b6fe0d5ad3fb3f4;hb=8626dba4b37d9b07d10888daf8cef3a26e5b114c;hp=eb40bc460941591b73aef49dd604ca04d44749fe;hpb=018f395e7f37c988d812bdf408c2c84e55ed8678;p=pspp-builds.git diff --git a/tests/data/data-out.at b/tests/data/data-out.at index eb40bc46..9a41a3b5 100644 --- a/tests/data/data-out.at +++ b/tests/data/data-out.at @@ -1,5 +1,223 @@ AT_BANNER([data output (data-out)]) +AT_SETUP([numeric format output]) +AT_DATA([num-out.pl], +[[use strict; +use warnings 'all'; + +my @values = qw(0 2 9.5 27 271 999.95 2718 9999.995 27182 271828 +2718281 2**39 2**333 2**-21 -2 -9.5 -27 -271 -999.95 -2718 -9999.995 +-27182 -271828 -2718281 -2**39 -2**333 -2**-21 -0 3.125 31.25 314.125 +3141.5 31415.875 314159.25 3141592.625 31415926.5 271828182.25 +3214567890.5 31415926535.875 -3.125 -31.375 -314.125 -3141.5 +-31415.875 -314159.25 -3141592.625 -31415926.5 -271828182.25 +-3214567890.5 -31415926535.875); + +print "SET CCA=',,,'.\n"; +print "SET CCB='-,[[[,]]],-'.\n"; +print "SET CCC='((,[,],))'.\n"; +print "SET CCD=',XXX,,-'.\n"; +print "SET CCE=',,YYY,-'.\n"; +print "INPUT PROGRAM.\n"; +print "STRING EXPR(A16).\n"; +print map ("COMPUTE NUM=$_.\nCOMPUTE EXPR='$_'.\nEND CASE.\n", @values); +print "END FILE.\n"; +print "END INPUT PROGRAM.\n"; + +print "PRINT OUTFILE='output.txt'/EXPR.\n"; +for my $format qw (F COMMA DOT DOLLAR PCT E CCA CCB CCC CCD CCE N Z) { + for my $d (0...16) { + my ($min_w); + if ($format ne 'E') { + $min_w = $d + 1; + $min_w++ if $format eq 'DOLLAR' || $format eq 'PCT'; + $min_w = 2 if $min_w == 1 && ($format =~ /^CC/); + } else { + $min_w = $d + 7; + } + for my $w ($min_w...40) { + my ($f) = "$format$w.$d"; + print "PRINT OUTFILE='output.txt'/'$f: \"' NUM($f) '\"'.\n"; + } + } + print "PRINT SPACE OUTFILE='output.txt'.\n"; +} +print "EXECUTE.\n"; +]]) +AT_CHECK([$PERL num-out.pl > num-out.sps]) +AT_CHECK([pspp -O format=csv num-out.sps]) +AT_CHECK([inexactify$EXEEXT < output.txt > output.inexact]) +AT_CHECK([gzip -cd < $top_srcdir/tests/data/num-out.expected.cmp.gz > expout.cmp]) +AT_DATA([num-out-decmp.pl], +[[use strict; +use warnings 'all'; + +my (@line); +while (<>) { + if (my ($n) = /^\*(\d+)$/) { + for (1...$n) { + $line[1]++; + $line[3] = " $line[3]"; + print ' ', join ('', @line), "\n"; + } + } elsif (my ($suffix) = /^\$(.*)$/) { + for my $c (split ('', $suffix)) { + $line[1]++; + $line[4] .= $c; + print ' ', join ('', @line), "\n"; + } + } elsif (my ($prefix) = /^\^(.*)$/) { + for my $c (split ('', $prefix)) { + $line[1]++; + $line[4] = "$c$line[4]"; + print ' ', join ('', @line), "\n"; + } + } else { + @line = /^([A-Z]+)(\d+)([^"]+")( *)([^%"]*)(%?")$/; + print " $_"; + } +} +]]) +AT_CHECK([$PERL num-out-decmp.pl < expout.cmp > expout.exact]) +AT_CHECK([[inexactify < expout.exact > expout.inexact]]) +AT_DATA([num-out-compare.pl], +[[#! /usr/bin/perl -w + +use strict; +use warnings 'all'; +use Getopt::Long; + +my $exact = 0; +my $spss = 0; +my $verbose = 0; +Getopt::Long::Configure ("bundling"); +GetOptions ("e|exact!" => \$exact, + "s|spss!" => \$spss, + "v|verbose+" => \$verbose, + "h|help" => sub { usage (0) }) + or usage (1); + +sub usage { + print "$0: compare expected and actual numeric formatting output\n"; + print "usage: $0 [OPTION...] EXPECTED ACTUAL\n"; + print "where EXPECTED is the file containing expected output\n"; + print "and ACTUAL is the file containing actual output.\n"; + print "Options:\n"; + print " -e, --exact: Require numbers to be exactly equal.\n"; + print " (By default, small differences are permitted.)\n"; + print " -s, --spss: Ignore most SPSS formatting bugs in EXPECTED.\n"; + print " (A few differences are not compensated)\n"; + print " -v, --verbose: Use once to summarize errors and differences.\n"; + print " Use twice for details of differences.\n"; + exit (@_); +} + +open (EXPECTED, '<', $ARGV[0]) or die "$ARGV[0]: open: $!\n"; +open (ACTUAL, '<', $ARGV[1]) or die "$ARGV[1]: open: $!\n"; +my ($expr); +my ($bad_round) = 0; +my ($approximate) = 0; +my ($spss_wtf1) = 0; +my ($spss_wtf2) = 0; +my ($lost_sign) = 0; +my ($errors) = 0; +while (defined (my $a = ) && defined (my $b = )) { + chomp $a; + chomp $b; + if ($a eq $b) { + if ($a !~ /^\s*$/ && $a !~ /:/) { + $expr = $a; + $expr =~ s/\s*$//; + $expr =~ s/^\s*//; + } + } else { + my ($fmt, $a_out) = $a =~ /^ (.*): "(.*)"$/ or die; + my ($b_fmt, $b_out) = $b =~ /^ (.*): "(.*)"$/ or die; + die if $fmt ne $b_fmt; + die if $a_out eq $b_out; + + if (!$exact) { + if (increment ($a_out) eq $b_out || increment ($b_out) eq $a_out) { + $approximate++; + next; + } + } + if ($spss) { + if ($a_out =~ /0.*0/ && $a_out !~ /[1-9]/) { + $bad_round++; + next; + } elsif ($a_out =~ /\*/ && $a_out !~ /^\*+$/) { + $spss_wtf1++; + next; + } elsif ($expr =~ /^-/ + && $a_out =~ /^\*+$/ + && $b_out =~ /-\d(\.\d*#*)?E[-+]\d\d\d/ + && $fmt =~ /^E/) { + $spss_wtf2++; + next; + } elsif ($expr =~ /^-/ + && (($a_out !~ /-/ && $a_out =~ /[1-9]/ && $b_out =~ /-/) + || ($a_out =~ /^[0-9]+$/ && $b_out =~ /^\*+$/))) { + $lost_sign++; + next; + } + } + print "$.: $expr in $fmt: expected \"$a_out\", got \"$b_out\"\n" + if $verbose > 1; + $errors++; + } +} +while () { + print "Extra lines in $ARGV[0]\n"; + $errors++; + last; +} +while () { + print "Extra lines in $ARGV[1]\n"; + $errors++; + last; +} +if ($verbose) { + print "$errors errors\n"; + if (!$exact) { + print "$approximate approximate matches\n"; + } + if ($spss) { + print "$bad_round bad rounds\n"; + print "$spss_wtf1 SPSS WTF 1\n"; + print "$spss_wtf2 SPSS WTF 2\n"; + print "$lost_sign lost signs\n"; + } +} +exit ($errors > 0); + +# Returns the argument value incremented by one unit in its final +# decimal place. +sub increment { + local ($_) = @_; + my ($last_digit, $i); + for ($i = 0; $i < length $_; $i++) { + my ($c) = substr ($_, $i, 1); + last if ($c eq 'E'); + $last_digit = $i if $c =~ /[0-9]/; + } + return $_ if !defined $last_digit; + for ($i = $last_digit; $i >= 0; $i--) { + my ($c) = substr ($_, $i, 1); + if ($c eq '9') { + substr ($_, $i, 1) = '0'; + } elsif ($c =~ /[0-8]/) { + substr ($_, $i, 1) = chr (ord ($c) + 1); + last; + } + } + $_ = "1$_" if $i < 0; + return $_; +} +]]) +AT_CHECK([$PERL num-out-compare.pl $PSPP_NUM_OUT_COMPARE_FLAGS expout.inexact output.inexact]) +AT_CLEANUP + AT_SETUP([binary and hexadecimal output]) AT_DATA([binhex-out.sps], [dnl SET ERRORS=NONE.