diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-03-11 13:58:10 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-03-11 13:58:10 +0000 |
commit | 11883c88c2a3bf14fd6833153409e184d556438f (patch) | |
tree | 55ff80d630f030a8f45d6d40e8ec3c68a0f37ee3 | |
parent | ade1ceae51b239152f8abd667cb1ad2441b86bdf (diff) | |
download | perl-11883c88c2a3bf14fd6833153409e184d556438f.tar.gz |
Convert t/op/64bitint.t to test.pl
-rw-r--r-- | t/op/64bitint.t | 378 |
1 files changed, 149 insertions, 229 deletions
diff --git a/t/op/64bitint.t b/t/op/64bitint.t index 399030a341..e4296f2306 100644 --- a/t/op/64bitint.t +++ b/t/op/64bitint.t @@ -1,13 +1,11 @@ -#./perl +#!./perl BEGIN { - eval { my $q = pack "q", 0 }; - if ($@) { - print "1..0 # Skip: no 64-bit types\n"; - exit(0); - } - chdir 't' if -d 't'; - @INC = '../lib'; + chdir 't' if -d 't'; + @INC = '../lib'; + require './test.pl'; + eval { my $q = pack "q", 0 }; + skip_all('no 64-bit types') if $@; } # This could use many more tests. @@ -17,8 +15,6 @@ BEGIN { use warnings; no warnings qw(overflow portable); -print "1..67\n"; - # as 6 * 6 = 36, the last digit of 6**n will always be six. Hence the last # digit of 16**n will always be six. Hence 16**n - 1 will always end in 5. # Assumption is that UVs will always be a multiple of 4 bits long. @@ -41,186 +37,182 @@ my $x; my $y; $x = unpack "q", pack "q", $q; -print "not " unless $x == $q && $x > $f; -print "ok 1\n"; +cmp_ok($x, '==', $q); +cmp_ok($x, '>', $f); $x = sprintf("%lld", 12345678901); -print "not " unless $x eq $q && $x > $f; -print "ok 2\n"; - +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%lld", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 3\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%Ld", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 4\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%qd", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 5\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%llx", $q); -print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; -print "ok 6\n"; +cmp_ok(hex $x, '==', 0x2dfdc1c35); +cmp_ok(hex $x, '>', $f); $x = sprintf("%Lx", $q); -print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; -print "ok 7\n"; +cmp_ok(hex $x, '==', 0x2dfdc1c35); +cmp_ok(hex $x, '>', $f); $x = sprintf("%qx", $q); -print "not " unless hex($x) == 0x2dfdc1c35 && hex($x) > $f; -print "ok 8\n"; - +cmp_ok(hex $x, '==', 0x2dfdc1c35); +cmp_ok(hex $x, '>', $f); $x = sprintf("%llo", $q); -print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; -print "ok 9\n"; +cmp_ok(oct "0$x", '==', 0133767016065); +cmp_ok(oct $x, '>', $f); $x = sprintf("%Lo", $q); -print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; -print "ok 10\n"; +cmp_ok(oct "0$x", '==', 0133767016065); +cmp_ok(oct $x, '>', $f); $x = sprintf("%qo", $q); -print "not " unless oct("0$x") == 0133767016065 && oct($x) > $f; -print "ok 11\n"; - +cmp_ok(oct "0$x", '==', 0133767016065); +cmp_ok(oct $x, '>', $f); $x = sprintf("%llb", $q); -print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && - oct("0b$x") > $f; -print "ok 12\n"; +cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101); +cmp_ok(oct "0b$x", '>', $f); $x = sprintf("%Lb", $q); -print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && - oct("0b$x") > $f; -print "ok 13\n"; +cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101); +cmp_ok(oct "0b$x", '>', $f); $x = sprintf("%qb", $q); -print "not " unless oct("0b$x") == 0b1011011111110111000001110000110101 && - oct("0b$x") > $f; -print "ok 14\n"; +cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101); +cmp_ok(oct "0b$x", '>', $f); $x = sprintf("%llu", $q); -print "not " unless $x eq $q && $x > $f; -print "ok 15\n"; +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%Lu", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 16\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%qu", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 17\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%D", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 18\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%U", $q); -print "not " unless $x == $q && $x eq $q && $x > $f; -print "ok 19\n"; +cmp_ok($x, '==', $q); +is($x, $q); +cmp_ok($x, '>', $f); $x = sprintf("%O", $q); -print "not " unless oct($x) == $q && oct($x) > $f; -print "ok 20\n"; +cmp_ok(oct $x, '==', $q); +cmp_ok(oct $x, '>', $f); $x = $q + $r; -print "not " unless $x == 35802467913 && $x > $f; -print "ok 21\n"; +cmp_ok($x, '==', 35802467913); +cmp_ok($x, '>', $f); $x = $q - $r; -print "not " unless $x == -11111110111 && -$x > $f; -print "ok 22\n"; +cmp_ok($x, '==', -11111110111); +cmp_ok(-$x, '>', $f); + +SKIP: { + # Unicos has imprecise doubles (14 decimal digits or so), + # especially if operating near the UV/IV limits the low-order bits + # become mangled even by simple arithmetic operations. + skip('too imprecise numbers on unicos') if $^O eq 'unicos'; -if ($^O ne 'unicos') { $x = $q * 1234567; - print "not " unless $x == 15241567763770867 && $x > $f; - print "ok 23\n"; + cmp_ok($x, '==', 15241567763770867); + cmp_ok($x, '>', $f); $x /= 1234567; - print "not " unless $x == $q && $x > $f; - print "ok 24\n"; + cmp_ok($x, '==', $q); + cmp_ok($x, '>', $f); $x = 98765432109 % 12345678901; - print "not " unless $x == 901; - print "ok 25\n"; - + cmp_ok($x, '==', 901); + # The following 12 tests adapted from op/inc. $a = 9223372036854775807; $c = $a++; - print "not " unless $a == 9223372036854775808; - print "ok 26\n"; + cmp_ok($a, '==', 9223372036854775808); $a = 9223372036854775807; $c = ++$a; - print "not " - unless $a == 9223372036854775808 && $c == $a; - print "ok 27\n"; + cmp_ok($a, '==', 9223372036854775808); + cmp_ok($c, '==', $a); $a = 9223372036854775807; $c = $a + 1; - print "not " - unless $a == 9223372036854775807 && $c == 9223372036854775808; - print "ok 28\n"; + cmp_ok($a, '==', 9223372036854775807); + cmp_ok($c, '==', 9223372036854775808); $a = -9223372036854775808; { no warnings 'imprecision'; $c = $a--; } - print "not " - unless $a == -9223372036854775809 && $c == -9223372036854775808; - print "ok 29\n"; + cmp_ok($a, '==', -9223372036854775809); + cmp_ok($c, '==', -9223372036854775808); $a = -9223372036854775808; { no warnings 'imprecision'; $c = --$a; } - print "not " - unless $a == -9223372036854775809 && $c == $a; - print "ok 30\n"; + cmp_ok($a, '==', -9223372036854775809); + cmp_ok($c, '==', $a); $a = -9223372036854775808; $c = $a - 1; - print "not " - unless $a == -9223372036854775808 && $c == -9223372036854775809; - print "ok 31\n"; - + cmp_ok($a, '==', -9223372036854775808); + cmp_ok($c, '==', -9223372036854775809); + $a = 9223372036854775808; $a = -$a; { no warnings 'imprecision'; $c = $a--; } - print "not " - unless $a == -9223372036854775809 && $c == -9223372036854775808; - print "ok 32\n"; - + cmp_ok($a, '==', -9223372036854775809); + cmp_ok($c, '==', -9223372036854775808); + $a = 9223372036854775808; $a = -$a; { no warnings 'imprecision'; $c = --$a; } - print "not " - unless $a == -9223372036854775809 && $c == $a; - print "ok 33\n"; - + cmp_ok($a, '==', -9223372036854775809); + cmp_ok($c, '==', $a); + $a = 9223372036854775808; $a = -$a; $c = $a - 1; - print "not " - unless $a == -9223372036854775808 && $c == -9223372036854775809; - print "ok 34\n"; + cmp_ok($a, '==', -9223372036854775808); + cmp_ok($c, '==', -9223372036854775809); $a = 9223372036854775808; $b = -$a; @@ -228,9 +220,8 @@ if ($^O ne 'unicos') { no warnings 'imprecision'; $c = $b--; } - print "not " - unless $b == -$a-1 && $c == -$a; - print "ok 35\n"; + cmp_ok($b, '==', -$a-1); + cmp_ok($c, '==', -$a); $a = 9223372036854775808; $b = -$a; @@ -238,95 +229,62 @@ if ($^O ne 'unicos') { no warnings 'imprecision'; $c = --$b; } - print "not " - unless $b == -$a-1 && $c == $b; - print "ok 36\n"; + cmp_ok($b, '==', -$a-1); + cmp_ok($c, '==', $b); $a = 9223372036854775808; $b = -$a; $b = $b - 1; - print "not " - unless $b == -(++$a); - print "ok 37\n"; - -} else { - # Unicos has imprecise doubles (14 decimal digits or so), - # especially if operating near the UV/IV limits the low-order bits - # become mangled even by simple arithmetic operations. - for (23..37) { - print "ok $_ # skipped: too imprecise numbers\n"; - } + cmp_ok($b, '==', -(++$a)); } $x = ''; -print "not " unless (vec($x, 1, 64) = $q) == $q; -print "ok 38\n"; - -print "not " unless vec($x, 1, 64) == $q && vec($x, 1, 64) > $f; -print "ok 39\n"; - -print "not " unless vec($x, 0, 64) == 0 && vec($x, 2, 64) == 0; -print "ok 40\n"; +cmp_ok((vec($x, 1, 64) = $q), '==', $q); +cmp_ok(vec($x, 1, 64), '==', $q); +cmp_ok(vec($x, 1, 64), '>', $f); -print "not " unless ~0 == 0xffffffffffffffff; -print "ok 41\n"; +cmp_ok(vec($x, 0, 64), '==', 0); +cmp_ok(vec($x, 2, 64), '==', 0); -print "not " unless (0xffffffff<<32) == 0xffffffff00000000; -print "ok 42\n"; +cmp_ok(~0, '==', 0xffffffffffffffff); -print "not " unless ((0xffffffff)<<32)>>32 == 0xffffffff; -print "ok 43\n"; +cmp_ok((0xffffffff<<32), '==', 0xffffffff00000000); -print "not " unless 1<<63 == 0x8000000000000000; -print "ok 44\n"; +cmp_ok(((0xffffffff)<<32)>>32, '==', 0xffffffff); -print "not " unless (sprintf "%#Vx", 1<<63) eq '0x8000000000000000'; -print "ok 45\n"; +cmp_ok(1<<63, '==', 0x8000000000000000); -print "not " unless (0x8000000000000000 | 1) == 0x8000000000000001; -print "ok 46\n"; +is((sprintf "%#Vx", 1<<63), '0x8000000000000000'); -print "not " - unless (0xf000000000000000 & 0x8000000000000000) == 0x8000000000000000; -print "ok 47\n"; +cmp_ok((0x8000000000000000 | 1), '==', 0x8000000000000001); -print "not " - unless (0xf000000000000000 ^ 0xfffffffffffffff0) == 0x0ffffffffffffff0; -print "ok 48\n"; +cmp_ok((0xf000000000000000 & 0x8000000000000000), '==', 0x8000000000000000); +cmp_ok((0xf000000000000000 ^ 0xfffffffffffffff0), '==', 0x0ffffffffffffff0); -print "not " - unless (sprintf "%b", ~0) eq - '1111111111111111111111111111111111111111111111111111111111111111'; -print "ok 49\n"; +is((sprintf "%b", ~0), + '1111111111111111111111111111111111111111111111111111111111111111'); -print "not " - unless (sprintf "%64b", ~0) eq - '1111111111111111111111111111111111111111111111111111111111111111'; -print "ok 50\n"; -print "not " unless (sprintf "%d", ~0>>1) eq '9223372036854775807'; -print "ok 51\n"; +is((sprintf "%64b", ~0), + '1111111111111111111111111111111111111111111111111111111111111111'); -print "not " unless (sprintf "%u", ~0) eq '18446744073709551615'; -print "ok 52\n"; +is((sprintf "%d", ~0>>1),'9223372036854775807'); +is((sprintf "%u", ~0),'18446744073709551615'); # If the 53..55 fail you have problems in the parser's string->int conversion, # see toke.c:scan_num(). $q = -9223372036854775808; -print "# $q ne\n# -9223372036854775808\nnot " unless "$q" eq "-9223372036854775808"; -print "ok 53\n"; +is("$q","-9223372036854775808"); $q = 9223372036854775807; -print "# $q ne\n# 9223372036854775807\nnot " unless "$q" eq "9223372036854775807"; -print "ok 54\n"; +is("$q","9223372036854775807"); $q = 18446744073709551615; -print "# $q ne\n# 18446744073709551615\nnot " unless "$q" eq "18446744073709551615"; -print "ok 55\n"; +is("$q","18446744073709551615"); # Test that sv_2nv then sv_2iv is the same as sv_2iv direct # fails if whatever Atol is defined as can't actually cope with >32 bits. @@ -337,99 +295,61 @@ my $string = "4294967297"; $num += 0; $string += 0; } -if ($num eq $string) { - print "ok 56\n"; -} else { - print "not ok 56 # \"$num\" ne \"$string\"\n"; -} +is($num, $string); # Test that sv_2nv then sv_2uv is the same as sv_2uv direct $num = 4294967297; $string = "4294967297"; $num &= 0; $string &= 0; -if ($num eq $string) { - print "ok 57\n"; -} else { - print "not ok 57 # \"$num\" ne \"$string\"\n"; -} +is($num, $string); $q = "18446744073709551616e0"; $q += 0; -print "# \"18446744073709551616e0\" += 0 gives $q\nnot " if "$q" eq "18446744073709551615"; -print "ok 58\n"; +isnt($q, "18446744073709551615"); # 0xFFFFFFFFFFFFFFFF == 1 * 3 * 5 * 17 * 257 * 641 * 65537 * 6700417' $q = 0xFFFFFFFFFFFFFFFF / 3; -if ($q == 0x5555555555555555 and ($q != 0x5555555555555556 - or !$maths_preserves_UVs)) { - print "ok 59\n"; -} else { - print "not ok 59 # 0xFFFFFFFFFFFFFFFF / 3 = $q\n"; - print "# Should not be floating point\n" if $q =~ tr/e.//; +cmp_ok($q, '==', 0x5555555555555555); +SKIP: { + skip("Maths does not preserve UVs", 2) unless $maths_preserves_UVs; + cmp_ok($q, '!=', 0x5555555555555556); + unlike($q, qr/[e.]/); } $q = 0xFFFFFFFFFFFFFFFF % 0x5555555555555555; -if ($q == 0) { - print "ok 60\n"; -} else { - print "not ok 60 # 0xFFFFFFFFFFFFFFFF % 0x5555555555555555 => $q\n"; -} +cmp_ok($q, '==', 0); $q = 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0; -if ($q == 0xF) { - print "ok 61\n"; -} else { - print "not ok 61 # 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0 => $q\n"; -} +cmp_ok($q, '==', 0xF); $q = 0x8000000000000000 % 9223372036854775807; -if ($q == 1) { - print "ok 62\n"; -} else { - print "not ok 62 # 0x8000000000000000 % 9223372036854775807 => $q\n"; -} +cmp_ok($q, '==', 1); $q = 0x8000000000000000 % -9223372036854775807; -if ($q == -9223372036854775806) { - print "ok 63\n"; -} else { - print "not ok 63 # 0x8000000000000000 % -9223372036854775807 => $q\n"; -} +cmp_ok($q, '==', -9223372036854775806); { - use integer; - $q = hex "0x123456789abcdef0"; - if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) { - print "ok 64\n"; - } else { - printf "not ok 64 # hex \"0x123456789abcdef0\" = $q (%X)\n", $q; - print "# Should not be floating point\n" if $q =~ tr/e.//; - } - - $q = oct "0x123456789abcdef0"; - if ($q == 0x123456789abcdef0 and $q != 0x123456789abcdef1) { - print "ok 65\n"; - } else { - printf "not ok 65 # oct \"0x123456789abcdef0\" = $q (%X)\n", $q; - print "# Should not be floating point\n" if $q =~ tr/e.//; - } - - $q = oct "765432176543217654321"; - if ($q == 0765432176543217654321 and $q != 0765432176543217654322) { - print "ok 66\n"; - } else { - printf "not ok 66 # oct \"765432176543217654321\" = $q (%o)\n", $q; - print "# Should not be floating point\n" if $q =~ tr/e.//; - } - - $q = oct "0b0101010101010101010101010101010101010101010101010101010101010101"; - if ($q == 0x5555555555555555 and $q != 0x5555555555555556) { - print "ok 67\n"; - } else { - printf "not ok 67 # oct \"0b0101010101010101010101010101010101010101010101010101010101010101\" = $q (%b)\n", $q; - print "# Should not be floating point\n" if $q =~ tr/e.//; - } + use integer; + $q = hex "0x123456789abcdef0"; + cmp_ok($q, '==', 0x123456789abcdef0); + cmp_ok($q, '!=', 0x123456789abcdef1); + unlike($q, qr/[e.]/, 'Should not be floating point'); + + $q = oct "0x123456789abcdef0"; + cmp_ok($q, '==', 0x123456789abcdef0); + cmp_ok($q, '!=', 0x123456789abcdef1); + unlike($q, qr/[e.]/, 'Should not be floating point'); + + $q = oct "765432176543217654321"; + cmp_ok($q, '==', 0765432176543217654321); + cmp_ok($q, '!=', 0765432176543217654322); + unlike($q, qr/[e.]/, 'Should not be floating point'); + + $q = oct "0b0101010101010101010101010101010101010101010101010101010101010101"; + cmp_ok($q, '==', 0x5555555555555555); + cmp_ok($q, '!=', 0x5555555555555556); + unlike($q, qr/[e.]/, 'Should not be floating point'); } -# eof +done_testing(); |