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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#!perl
use strict;
use warnings;
use Test::More tests => 220;
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);
my $test = qq|\$x = Math::BigInt -> new("$x_str");|
. qq| \$str = \$x -> bdstr();|;
note "\n$test\n\n";
eval $test;
is($str, $expected, qq|input value is "$x_str"|);
is($x, $x_str, "input object is unmodified");
}
__DATA__
NaN:NaN
inf:inf
-inf:-inf
0:0
# positive numbers
1:1
10:10
100:100
1000:1000
10000:10000
100000:100000
1000000:1000000
10000000:10000000
100000000:100000000
1000000000:1000000000
10000000000:10000000000
100000000000:100000000000
1000000000000:1000000000000
12:12
120:120
1200:1200
12000:12000
120000:120000
1200000:1200000
12000000:12000000
120000000:120000000
1200000000:1200000000
12000000000:12000000000
120000000000:120000000000
1200000000000:1200000000000
123:123
1230:1230
12300:12300
123000:123000
1230000:1230000
12300000:12300000
123000000:123000000
1230000000:1230000000
12300000000:12300000000
123000000000:123000000000
1230000000000:1230000000000
1234:1234
12340:12340
123400:123400
1234000:1234000
12340000:12340000
123400000:123400000
1234000000:1234000000
12340000000:12340000000
123400000000:123400000000
1234000000000:1234000000000
3:3
31:31
314:314
3141:3141
31415:31415
314159:314159
3141592:3141592
# negative numbers
-1:-1
-10:-10
-100:-100
-1000:-1000
-10000:-10000
-100000:-100000
-1000000:-1000000
-10000000:-10000000
-100000000:-100000000
-1000000000:-1000000000
-10000000000:-10000000000
-100000000000:-100000000000
-1000000000000:-1000000000000
-12:-12
-120:-120
-1200:-1200
-12000:-12000
-120000:-120000
-1200000:-1200000
-12000000:-12000000
-120000000:-120000000
-1200000000:-1200000000
-12000000000:-12000000000
-120000000000:-120000000000
-1200000000000:-1200000000000
-123:-123
-1230:-1230
-12300:-12300
-123000:-123000
-1230000:-1230000
-12300000:-12300000
-123000000:-123000000
-1230000000:-1230000000
-12300000000:-12300000000
-123000000000:-123000000000
-1230000000000:-1230000000000
-1234:-1234
-12340:-12340
-123400:-123400
-1234000:-1234000
-12340000:-12340000
-123400000:-123400000
-1234000000:-1234000000
-12340000000:-12340000000
-123400000000:-123400000000
-1234000000000:-1234000000000
-3:-3
-31:-31
-314:-314
-3141:-3141
-31415:-31415
-314159:-314159
-3141592:-3141592
|