File: bfstr-mbi.t

package info (click to toggle)
libmath-bigint-perl 1.999838-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,424 kB
  • sloc: perl: 10,236; pascal: 5,387; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (2)
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