From e8fbc27bb8213e8bc971fbce5f4c90f2e391293a Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Mon, 14 Mar 2011 11:03:55 +0000 Subject: Convert the remainder of t/op/numconvert.t to test.pl, strict and warnings. --- t/op/numconvert.t | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 't/op/numconvert.t') diff --git a/t/op/numconvert.t b/t/op/numconvert.t index 758369e563..bfdb4880b2 100644 --- a/t/op/numconvert.t +++ b/t/op/numconvert.t @@ -41,7 +41,7 @@ BEGIN { require './test.pl'; } -use strict 'vars'; +use strict; my $max_chain = $ENV{PERL_TEST_NUMCONVERTS} || 2; @@ -69,7 +69,7 @@ my $num = 0; $num += 10**$_ - 4**$_ for 1.. $max_chain; $num *= $st_t; $num += $::additional_tests; -print "1..$num\n"; # In fact 15 times more subsubtests... +plan(tests => $num); # In fact 15 times more subsubtests... my $max_uv = ~0; my $max_iv = int($max_uv/2); @@ -88,7 +88,7 @@ my @list = (1, $yet_smaller_than_iv, $smaller_than_iv, $max_iv, $max_iv + 1, unshift @list, (reverse map -$_, @list), 0; # 15 elts @list = map "$_", @list; # Normalize -print "# @list\n"; +note("@list"); # need to special case ++ for max_uv, as ++ "magic" on a string gives # another string, whereas ++ magic on a string used as a number gives @@ -111,9 +111,6 @@ my @opnames = split //, "-+UINPuinp"; # @list = map { 2->($_), 3->($_), 4->($_), 5->($_), } @list; # Prepare input -#print "@list\n"; -#print "'@ops'\n"; - my $test = 1; my $nok; for my $num_chain (1..$max_chain) { @@ -123,7 +120,6 @@ for my $num_chain (1..$max_chain) { #@ops = ([]) unless $num_chain; #@ops = ([6, 4]); - # print "'@ops'\n"; for my $op (@ops) { for my $first (2..5) { for my $last (2..5) { @@ -175,14 +171,14 @@ for my $num_chain (1..$max_chain) { if ($curop == 5) { $inpt = "$inpt"; # P 5 } elsif ($curop == 6) { - $max_uv & $inpt; # u 6 + my $dummy = $max_uv & $inpt; # u 6 } else { - use integer; $inpt + $zero; + use integer; my $dummy = $inpt + $zero; } } elsif ($curop == 8) { - $inpt + $zero; # n 8 + my $dummy = $inpt + $zero; # n 8 } else { - $inpt . ""; # p 9 + my $dummy = $inpt . ""; # p 9 } } @@ -198,13 +194,14 @@ for my $num_chain (1..$max_chain) { push @ans, $inpt; } if ($ans[0] ne $ans[1]) { - print "# '$ans[0]' ne '$ans[1]',\t$num\t=> @opnames[$first,@{$curops[0]},$last] vs @opnames[$first,@{$curops[1]},$last]\n"; + my $diag = "'$ans[0]' ne '$ans[1]',\t$num\t=> @opnames[$first,@{$curops[0]},$last] vs @opnames[$first,@{$curops[1]},$last]"; + my $excuse; # XXX ought to check that "+" was in the list of opnames if ((($ans[0] eq $max_uv_pp) and ($ans[1] eq $max_uv_p1)) or (($ans[1] eq $max_uv_pp) and ($ans[0] eq $max_uv_p1))) { # string ++ versus numeric ++. Tolerate this little # bit of insanity - print "# ok, as string ++ of max_uv is \"$max_uv_pp\", numeric is $max_uv_p1\n" + $excuse = "ok, as string ++ of max_uv is \"$max_uv_pp\", numeric is $max_uv_p1"; } elsif ($opnames[$last] eq 'I' and $ans[1] eq "-1" and $ans[0] eq $max_uv_p1_as_iv) { # Max UV plus 1 is NV. This NV may stringify in E notation. @@ -218,12 +215,12 @@ for my $num_chain (1..$max_chain) { # But each step of conversion is correct. So it's not an error. # (Only shows up for 64 bit UVs and NVs with 64 bit mantissas, # and on Crays (64 bit integers, 48 bit mantissas) IIRC) - print "# ok, \"$max_uv_p1\" correctly converts to IV \"$max_uv_p1_as_iv\"\n"; + $excuse = "ok, \"$max_uv_p1\" correctly converts to IV \"$max_uv_p1_as_iv\""; } elsif ($opnames[$last] eq 'U' and $ans[1] eq ~0 and $ans[0] eq $max_uv_p1_as_uv) { # as aboce - print "# ok, \"$max_uv_p1\" correctly converts to UV \"$max_uv_p1_as_uv\"\n"; - } elsif (grep {/^N$/} @opnames[@{$curops[0]}] + $excuse = "ok, \"$max_uv_p1\" correctly converts to UV \"$max_uv_p1_as_uv\""; + } elsif (grep {defined $_ && /^N$/} @opnames[@{$curops[0]}] and $ans[0] == $ans[1] and $ans[0] <= ~0 # First must be in E notation (ie not just digits) and # second must still be an integer. @@ -236,19 +233,18 @@ for my $num_chain (1..$max_chain) { # I can't remember why there isn't symmetry in this # exception, ie why only the first ops are tested for 'N' and $ans[0] != /^-?\d+$/ and $ans[1] !~ /^-?\d+$/) { - print "# ok, numerically equal - notation changed due to adding zero\n"; + $excuse = "ok, numerically equal - notation changed due to adding zero"; } else { $nok++, + diag($diag); + } + if ($excuse) { + note($diag); + note($excuse); } } } - if ($nok) { - print "not ok $test\n"; - } else { - print "ok $test\n"; - } - #print $txt if $nok; - $test++; + ok($nok == 0); } } } @@ -257,11 +253,10 @@ for my $num_chain (1..$max_chain) { # Tests that use test.pl start here. BEGIN { $::additional_tests = 4 } -curr_test($test); - ok(-0.0 eq "0", 'negative zero stringifies as 0'); ok(!-0.0, "neg zero is boolean false"); -my $nz = -0.0; "$nz"; +my $nz = -0.0; +{ my $dummy = "$nz"; } ok(!$nz, 'previously stringified -0.0 is boolean false'); $nz = -0.0; is sprintf("%+.f", - -$nz), sprintf("%+.f", - -$nz), -- cgit v1.2.1