File: from_hex-mbi.t

package info (click to toggle)
perl 5.32.1-4%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 113,408 kB
  • sloc: ansic: 641,443; perl: 491,650; sh: 70,967; pascal: 8,354; cpp: 4,103; xml: 2,428; makefile: 2,237; yacc: 1,173; lisp: 1
file content (128 lines) | stat: -rw-r--r-- 2,307 bytes parent folder | download | duplicates (5)
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
#!perl

use strict;
use warnings;

use Test::More tests => 1373;

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_hex("$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_hex("$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__

0x0:0
0x1:1
0x2:2
0x3:3
0x4:4
0x5:5
0x6:6
0x7:7
0x8:8
0x9:9
0xa:10
0xb:11
0xc:12
0xd:13
0xe:14
0xf:15
0x10:16
0x11:17

0xfe:254
0xff:255
0x100:256
0x101:257

0xfffe:65534
0xffff:65535
0x10000:65536
0x10001:65537

0xfffffe:16777214
0xffffff:16777215
0x1000000:16777216
0x1000001:16777217

0xfffffffe:4294967294
0xffffffff:4294967295
0x100000000:4294967296
0x100000001:4294967297

0xfffffffffe:1099511627774
0xffffffffff:1099511627775
0x10000000000:1099511627776
0x10000000001:1099511627777

0xfffffffffffe:281474976710654
0xffffffffffff:281474976710655
0x1000000000000:281474976710656
0x1000000000001:281474976710657

0xfffffffffffffe:72057594037927934
0xffffffffffffff:72057594037927935
0x100000000000000:72057594037927936
0x100000000000001:72057594037927937

NaN:NaN
+inf:NaN
-inf:NaN