1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# -*- mode: perl; -*-
use strict;
use warnings;
use Test::More tests => 2 * 50;
use Math::BigInt;
while (<DATA>) {
s/#.*$//; # remove comments
s/\s+$//; # remove trailing whitespace
next unless length; # skip empty lines
my ($x_str, $expected) = split /:/;
my ($x, $str);
for my $accu ("undef", "20") {
my $test = qq|Math::BigInt -> accuracy($accu);|
. qq| \$x = Math::BigInt -> new("$x_str");|
. qq| \$str = \$x -> bfstr();|;
note "\n$test\n\n";
eval $test;
die $@ if $@; # should never happen
is($str, $expected, qq|output is "$expected"|);
if ($x_str eq 'NaN') {
ok($x -> is_nan(), "input object is unmodified");
} else {
cmp_ok($x, "==", $x_str, "input object is unmodified");
}
}
}
__DATA__
NaN:NaN
inf:inf
-inf:-inf
0:0
-0:0
# positive numbers
1:1
12:12
123:123
1234:1234
12343:12343
123437:123437
1234375:1234375
12343750:12343750
123437500:123437500
1234375000:1234375000
# negative numbers
-1:-1
-12:-12
-123:-123
-1234:-1234
-12343:-12343
-123437:-123437
-1234375:-1234375
-12343750:-12343750
-123437500:-123437500
-1234375000:-1234375000
|