summaryrefslogtreecommitdiff
path: root/cpan/Math-BigInt/t/from_oct-mbi.t
blob: 5107fd1fb0822d8e84c1cb454e7678e7cfc6c432 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!perl

use strict;
use warnings;

use Test::More tests => 2745;

my $class;

BEGIN { $class = 'Math::BigInt'; }
BEGIN { use_ok($class); }

my @data;
my $space = "\t\r\n ";

while (<DATA>) {
    s/#.*$//;           # remove comments
    s/\s+$//;           # remove trailing whitespace
    next unless length; # skip empty lines

    my ($in0, $out0) = split /:/;

    push @data, [ $in0, $out0 ],
                [ $in0 . $space, $out0 ],
                [ $space . $in0, $out0 ],
                [ $space . $in0 . $space, $out0 ];
}

for my $entry (@data) {
    my ($in0, $out0) = @$entry;

    # As class method.

    {
        my $x;
        my $test = qq|\$x = $class -> from_oct("$in0");|;

        eval $test;
        die $@ if $@;           # this should never happen

        subtest $test, sub {
            plan tests => 2,

            is(ref($x), $class, "output arg is a $class");
            is($x, $out0, 'output arg has the right value');
        };
    }

    # As instance method.

    {
        for my $str ("-1", "0", "1", "-inf", "+inf", "NaN") {
            my $x;
            my $test = qq|\$x = $class -> new("$str");|
                     . qq| \$x -> from_oct("$in0");|;

            eval $test;
            die $@ if $@;       # this should never happen

            subtest $test, sub {
                plan tests => 2,

                is(ref($x), $class, "output arg is a $class");
                is($x, $out0, 'output arg has the right value');
            };
        }
    }
}

__END__

0:0
1:1
2:2
3:3
4:4
5:5
6:6
7:7
10:8
11:9
12:10
13:11
14:12
15:13
16:14
17:15
20:16
21:17

376:254
377:255
400:256
401:257

177776:65534
177777:65535
200000:65536
200001:65537

77777776:16777214
77777777:16777215
100000000:16777216
100000001:16777217

37777777776:4294967294
37777777777:4294967295
40000000000:4294967296
40000000001:4294967297

17777777777776:1099511627774
17777777777777:1099511627775
20000000000000:1099511627776
20000000000001:1099511627777

7777777777777776:281474976710654
7777777777777777:281474976710655
10000000000000000:281474976710656
10000000000000001:281474976710657

3777777777777777776:72057594037927934
3777777777777777777:72057594037927935
4000000000000000000:72057594037927936
4000000000000000001:72057594037927937

0o0:0
0o1:1
0o2:2
0o3:3
0o4:4
0o5:5
0o6:6
0o7:7
0o10:8
0o11:9
0o12:10
0o13:11
0o14:12
0o15:13
0o16:14
0o17:15
0o20:16
0o21:17

0o376:254
0o377:255
0o400:256
0o401:257

0o177776:65534
0o177777:65535
0o200000:65536
0o200001:65537

0o77777776:16777214
0o77777777:16777215
0o100000000:16777216
0o100000001:16777217

0o37777777776:4294967294
0o37777777777:4294967295
0o40000000000:4294967296
0o40000000001:4294967297

0o17777777777776:1099511627774
0o17777777777777:1099511627775
0o20000000000000:1099511627776
0o20000000000001:1099511627777

0o7777777777777776:281474976710654
0o7777777777777777:281474976710655
0o10000000000000000:281474976710656
0o10000000000000001:281474976710657

0o3777777777777777776:72057594037927934
0o3777777777777777777:72057594037927935
0o4000000000000000000:72057594037927936
0o4000000000000000001:72057594037927937

0O10:8
o10:8
O10:8

NaN:NaN
+inf:NaN
-inf:NaN