File: mbi-from-big-scalar.t

package info (click to toggle)
libmath-bigint-gmp-perl 1.7003-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,016 kB
  • sloc: pascal: 3,998; perl: 280; makefile: 9; sh: 1
file content (46 lines) | stat: -rw-r--r-- 1,279 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
# -*- mode; perl -*-

# See https://rt.cpan.org/Ticket/Display.html?id=103517

use strict;
use warnings;

use Test::More;

use Math::BigInt only => 'GMP';

# Don't run these tests unless we have proper 64-bit support.

my $use64    = ~0 > 4294967295;
my $broken64 = (18446744073709550592 == ~0);
if ($broken64) {
    plan(skip_all =>
         "Your 64-bit system is broken.  Upgrade from 5.6 for this test.");
}

plan tests => 4*2 + 2*1 + 1 + $use64;

my $maxs = ~0 >> 1;
for my $n ($maxs - 2, $maxs - 1, $maxs, $maxs + 1) {
    is( Math::BigInt->new($n), $n, "new $n" );
    is( Math::BigInt->new(-$n), -$n, "new -$n" );
}

for my $n (~0 - 1, ~0) {
    is( Math::BigInt->new($n), $n, "new $n" );
}

# bacmp makes a new variable.  This will test if it is screwing up the sign.
is( Math::BigInt->new(10)->bacmp(~0), -1, "10 should be less than maxint" );

if ($use64) {
  SKIP: {
        skip "The following test may hang or cause an exception if incorrect."
          . " Set AUTHOR_TESTING to a true value to run this test.", 1
            unless $ENV{AUTHOR_TESTING};

        is( Math::BigInt->new("14")->bmodpow(9506577562092332135,
                                             "29544731879021791655795710"),
            "19946192910281559497582964", "big modpow" );
    }
}