1# -*- mode: perl; -*-
2
3use strict;
4use warnings;
5
6use Test::More tests => 4280            # tests in require'd file
7                         + 20;          # tests in this file
8
9use Math::BigInt only => 'Pari';
10
11our ($CLASS, $LIB);
12$CLASS = "Math::BigInt";
13$LIB   = Math::BigInt -> config('lib');         # backend library
14
15my $x;
16
17#############################################################################
18# bgcd() as function, class method and instance method.
19
20my $gcd0 = Math::BigInt::bgcd(-12, 18, 27);
21isa_ok($gcd0, "Math::BigInt", "bgcd() as function");
22is($gcd0, 3, "bgcd() as function");
23
24my $gcd1 = Math::BigInt->bgcd(-12, 18, 27);
25isa_ok($gcd1, "Math::BigInt", "bgcd() as class method");
26is($gcd1, 3, "bgcd() as class method");
27
28$x = Math::BigInt -> new(-12);
29my $gcd2 = $x -> bgcd(18, 27);
30isa_ok($gcd2, "Math::BigInt", "bgcd() as instance method");
31is($gcd2, 3, "bgcd() as instance method");
32is($x, -12, "bgcd() does not modify invocand");
33
34#############################################################################
35# blcm() as function, class method and instance method.
36
37my $lcm0 = Math::BigInt::blcm(-12, 18, 27);
38isa_ok($lcm0, "Math::BigInt", "blcm() as function");
39is($lcm0, 108, "blcm() as function");
40
41my $lcm1 = Math::BigInt->blcm(-12, 18, 27);
42isa_ok($lcm1, "Math::BigInt", "blcm() as class method");
43is($lcm1, 108, "blcm() as class method");
44
45$x = Math::BigInt -> new(-12);
46my $lcm2 = $x -> blcm(18, 27);
47isa_ok($lcm2, "Math::BigInt", "blcm() as instance method");
48is($lcm2, 108, "blcm() as instance method");
49is($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');
55is($x, "51966",
56   qq|Math::BigInt->from_hex("0xcafe")|);
57
58$x = Math::BigInt->from_hex('0xcafebabedead');
59is($x, "223195403574957",
60   qq|Math::BigInt->from_hex("0xcafebabedead")|);
61
62$x = Math::BigInt->from_bin('0b1001');
63is($x, "9",
64   qq|Math::BigInt->from_bin("0b1001")|);
65
66$x = Math::BigInt->from_bin('0b1001100110011001100110011001');
67is($x, "161061273",
68   qq|Math::BigInt->from_bin("0b1001100110011001100110011001");|);
69
70$x = Math::BigInt->from_oct('0775');
71is($x, "509",
72   qq|Math::BigInt->from_oct("0775");|);
73
74$x = Math::BigInt->from_oct('07777777777777711111111222222222');
75is($x, "9903520314281112085086151826",
76   qq|Math::BigInt->from_oct("07777777777777711111111222222222");|);
77
78#############################################################################
79# all the other tests
80
81require './t/bigintpm.inc';       # all tests here for sharing
82