File: from_base-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 (126 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download | duplicates (3)
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
#!perl

use strict;
use warnings;

use Test::More tests => 176;

my $class;

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

my @data;

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

    my @in = split /:/;
    my $out = pop @in;

    # As class method.

    {
        my $x;
        my $test = qq|\$x = $class -> from_base("$in[0]", $in[1]|;
        $test .= qq|, "$in[2]"| if @in == 3;
        $test .= qq|);|;

        eval $test;
        #die $@ if $@;           # this should never happen
        die "\nThe following test died when eval()'ed. This indicates a ",
          "broken test\n\n    $test\n\nThe error message was\n\n    $@\n"
          if $@;

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

            is(ref($x), $class, "output arg is a $class");
            is($x, $out, '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");|;
            $test .= qq| \$x -> from_base("$in[0]", $in[1]|;
            $test .= qq|, "$in[2]"| if @in == 3;
            $test .= qq|);|;

            eval $test;
            #die $@ if $@;       # this should never happen
            die "\nThe following test died when eval()'ed. This indicates a ",
              "broken test\n\n    $test\n\nThe error message was\n\n    $@\n"
              if $@;

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

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

__END__

# Base 2

11111010:2:250
11111010:2:01:250

# Base 8

372:8:250
372:8:01234567:250

# Base 10 (in the last case, use a truncted collation sequence that does not
# include unused characters)

250:10:250
250:10:0123456789:250
250:10:012345:250

# Base 16

fa:16:250
FA:16:250
fa:16:0123456789abcdef:250

# Base 3

100021:3:250
100021:3:012:250

/|-:3:-/|:15

# Base 4

3322:4:250
3322:4:0123:250

# Base 5

2000:5:250
2000:5:01234:250
caaa:5:abcde:250

# when base is less than or equal to 36, case is ignored

6Y:36:250
6y:36:250

6S:37:250
7H:37:276

121:3:16

XYZ:36:44027

Why:62:125734