This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Math-BigInt to CPAN version 1.999811
[perl5.git] / cpan / Math-BigInt / t / bigintpm.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3942            # tests in require'd file
7                          + 20;          # tests in this file
8
9 use Math::BigInt only => 'Calc';
10
11 our ($CLASS, $CALC);
12 $CLASS = "Math::BigInt";
13 $CALC  = Math::BigInt -> config('lib');         # backend library
14
15 my $x;
16
17 #############################################################################
18 # bgcd() as function, class method and instance method.
19
20 my $gcd0 = Math::BigInt::bgcd(-12, 18, 27);
21 isa_ok($gcd0, "Math::BigInt", "bgcd() as function");
22 is($gcd0, 3, "bgcd() as function");
23
24 my $gcd1 = Math::BigInt->bgcd(-12, 18, 27);
25 isa_ok($gcd1, "Math::BigInt", "bgcd() as class method");
26 is($gcd1, 3, "bgcd() as class method");
27
28 $x = Math::BigInt -> new(-12);
29 my $gcd2 = $x -> bgcd(18, 27);
30 isa_ok($gcd2, "Math::BigInt", "bgcd() as instance method");
31 is($gcd2, 3, "bgcd() as instance method");
32 is($x, -12, "bgcd() does not modify invocand");
33
34 #############################################################################
35 # blcm() as function, class method and instance method.
36
37 my $lcm0 = Math::BigInt::blcm(-12, 18, 27);
38 isa_ok($lcm0, "Math::BigInt", "blcm() as function");
39 is($lcm0, 108, "blcm() as function");
40
41 my $lcm1 = Math::BigInt->blcm(-12, 18, 27);
42 isa_ok($lcm1, "Math::BigInt", "blcm() as class method");
43 is($lcm1, 108, "blcm() as class method");
44
45 $x = Math::BigInt -> new(-12);
46 my $lcm2 = $x -> blcm(18, 27);
47 isa_ok($lcm2, "Math::BigInt", "blcm() as instance method");
48 is($lcm2, 108, "blcm() as instance method");
49 is($x, -12, "blcm() does not modify invocand");
50
51 #############################################################################
52 # from_hex(), from_bin() and from_oct() tests
53
54 $x = Math::BigInt->from_hex('0xcafe');
55 is($x, "51966",
56    qq|Math::BigInt->from_hex("0xcafe")|);
57
58 $x = Math::BigInt->from_hex('0xcafebabedead');
59 is($x, "223195403574957",
60    qq|Math::BigInt->from_hex("0xcafebabedead")|);
61
62 $x = Math::BigInt->from_bin('0b1001');
63 is($x, "9",
64    qq|Math::BigInt->from_bin("0b1001")|);
65
66 $x = Math::BigInt->from_bin('0b1001100110011001100110011001');
67 is($x, "161061273",
68    qq|Math::BigInt->from_bin("0b1001100110011001100110011001");|);
69
70 $x = Math::BigInt->from_oct('0775');
71 is($x, "509",
72    qq|Math::BigInt->from_oct("0775");|);
73
74 $x = Math::BigInt->from_oct('07777777777777711111111222222222');
75 is($x, "9903520314281112085086151826",
76    qq|Math::BigInt->from_oct("07777777777777711111111222222222");|);
77
78 #############################################################################
79 # all the other tests
80
81 require 't/bigintpm.inc';       # all tests here for sharing