summaryrefslogtreecommitdiff
path: root/dist/bignum/t
diff options
context:
space:
mode:
authorFlorian Ragwitz <rafl@debian.org>2010-09-03 01:12:17 +0200
committerFlorian Ragwitz <rafl@debian.org>2010-09-03 01:20:47 +0200
commitc064d6c6600a09556bae5adafca518fb4e6da98a (patch)
treeffc648099a8cc0483c27e9592b37655008e4c6cd /dist/bignum/t
parent9dc8ab6efae84d4eaf80f7e1c91f2d2d89ba516b (diff)
downloadperl-c064d6c6600a09556bae5adafca518fb4e6da98a.tar.gz
blead is upstream for bignum
Diffstat (limited to 'dist/bignum/t')
-rw-r--r--dist/bignum/t/big_e_pi.t23
-rw-r--r--dist/bignum/t/bigexp.t26
-rw-r--r--dist/bignum/t/bigint.t123
-rw-r--r--dist/bignum/t/bignum.t94
-rw-r--r--dist/bignum/t/bigrat.t98
-rw-r--r--dist/bignum/t/bii_e_pi.t24
-rw-r--r--dist/bignum/t/biinfnan.t22
-rw-r--r--dist/bignum/t/bir_e_pi.t25
-rw-r--r--dist/bignum/t/bn_lite.t30
-rw-r--r--dist/bignum/t/bninfnan.t39
-rw-r--r--dist/bignum/t/br_lite.t30
-rw-r--r--dist/bignum/t/brinfnan.t22
-rw-r--r--dist/bignum/t/in_effect.t42
-rw-r--r--dist/bignum/t/infnan.inc35
-rw-r--r--dist/bignum/t/option_a.t31
-rw-r--r--dist/bignum/t/option_l.t54
-rw-r--r--dist/bignum/t/option_p.t29
-rw-r--r--dist/bignum/t/ratopt_a.t34
-rw-r--r--dist/bignum/t/scope_f.t41
-rw-r--r--dist/bignum/t/scope_i.t42
-rw-r--r--dist/bignum/t/scope_r.t41
21 files changed, 905 insertions, 0 deletions
diff --git a/dist/bignum/t/big_e_pi.t b/dist/bignum/t/big_e_pi.t
new file mode 100644
index 0000000000..819e22528a
--- /dev/null
+++ b/dist/bignum/t/big_e_pi.t
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bignum qw/e PI bexp bpi/;
+
+is (e, "2.718281828459045235360287471352662497757", 'e');
+is (PI, "3.141592653589793238462643383279502884197", 'PI');
+
+is (bexp(1,10), "2.718281828", 'e');
+is (bpi(10), "3.141592654", 'PI');
diff --git a/dist/bignum/t/bigexp.t b/dist/bignum/t/bigexp.t
new file mode 100644
index 0000000000..2fc631fff1
--- /dev/null
+++ b/dist/bignum/t/bigexp.t
@@ -0,0 +1,26 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for bug #18025: bignum/bigrat can lead to a number that is both 1 and 0
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bignum;
+
+my $lnev = -7 / (10**17);
+my $ev=exp($lnev);
+
+is( sprintf('%0.5f',$ev) , '1.00000', '($ev) is approx. 1' );
+is( sprintf('%0.5f',1-$ev) , '0.00000', '(1-$ev) is approx. 0' );
+is( sprintf('%0.5f',1-"$ev") , '0.00000', '(1-"$ev") is approx. 0' );
+
+cmp_ok( $ev, '!=', 0, '$ev should not equal 0');
diff --git a/dist/bignum/t/bigint.t b/dist/bignum/t/bigint.t
new file mode 100644
index 0000000000..baf76a3005
--- /dev/null
+++ b/dist/bignum/t/bigint.t
@@ -0,0 +1,123 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 51;
+ }
+
+use bigint qw/hex oct/;
+
+###############################################################################
+# _constant tests
+
+foreach (qw/
+ 123:123
+ 123.4:123
+ 1.4:1
+ 0.1:0
+ -0.1:0
+ -1.1:-1
+ -123.4:-123
+ -123:-123
+ 123e2:123e2
+ 123e-1:12
+ 123e-4:0
+ 123e-3:0
+ 123.345e-1:12
+ 123.456e+2:12345
+ 1234.567e+3:1234567
+ 1234.567e+4:1234567E1
+ 1234.567e+6:1234567E3
+ /)
+ {
+ my ($x,$y) = split /:/;
+ print "# Try $x\n";
+ ok (bigint::_float_constant("$x"),"$y");
+ }
+
+foreach (qw/
+ 0100:64
+ 0200:128
+ 0x100:256
+ 0b1001:9
+ /)
+ {
+ my ($x,$y) = split /:/;
+ print "# Try $x\n";
+ ok (bigint::_binary_constant("$x"),"$y");
+ }
+
+###############################################################################
+# general tests
+
+my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
+
+# todo: ok (2 + 2.5,4.5); # should still work
+# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
+
+$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
+
+ok (12->bfac(),479001600);
+ok (9/4,2);
+
+ok (4.5+4.5,8); # truncate
+ok (ref(4.5+4.5) =~ /^Math::BigInt/);
+
+
+###############################################################################
+# accurarcy and precision
+
+ok_undef (bigint->accuracy());
+ok (bigint->accuracy(12),12);
+ok (bigint->accuracy(),12);
+
+ok_undef (bigint->precision());
+ok (bigint->precision(12),12);
+ok (bigint->precision(),12);
+
+ok (bigint->round_mode(),'even');
+ok (bigint->round_mode('odd'),'odd');
+ok (bigint->round_mode(),'odd');
+
+###############################################################################
+# hex() and oct()
+
+my $c = 'Math::BigInt';
+
+ok (ref(hex(1)), $c);
+ok (ref(hex(0x1)), $c);
+ok (ref(hex("af")), $c);
+ok (hex("af"), Math::BigInt->new(0xaf));
+ok (ref(hex("0x1")), $c);
+
+ok (ref(oct("0x1")), $c);
+ok (ref(oct("01")), $c);
+ok (ref(oct("0b01")), $c);
+ok (ref(oct("1")), $c);
+ok (ref(oct(" 1")), $c);
+ok (ref(oct(" 0x1")), $c);
+
+ok (ref(oct(0x1)), $c);
+ok (ref(oct(01)), $c);
+ok (ref(oct(0b01)), $c);
+ok (ref(oct(1)), $c);
+
+###############################################################################
+###############################################################################
+# Perl 5.005 does not like ok ($x,undef)
+
+sub ok_undef
+ {
+ my $x = shift;
+
+ ok (1,1) and return if !defined $x;
+ ok ($x,'undef');
+ }
diff --git a/dist/bignum/t/bignum.t b/dist/bignum/t/bignum.t
new file mode 100644
index 0000000000..fe299a2e24
--- /dev/null
+++ b/dist/bignum/t/bignum.t
@@ -0,0 +1,94 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 35;
+ }
+
+use bignum qw/oct hex/;
+
+###############################################################################
+# general tests
+
+my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
+
+ok (2 + 2.5,4.5);
+$x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
+ok (2 * 2.1,4.2);
+$x = 2 + 2.1; ok (ref($x),'Math::BigFloat');
+
+$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
+
+# see if Math::BigInt constant and upgrading works
+ok (Math::BigInt::bsqrt('12'),'3.464101615137754587054892683011744733886');
+ok (sqrt(12),'3.464101615137754587054892683011744733886');
+
+ok (2/3,"0.6666666666666666666666666666666666666667");
+
+#ok (2 ** 0.5, 'NaN'); # should be sqrt(2);
+
+ok (12->bfac(),479001600);
+
+# see if Math::BigFloat constant works
+
+# 0123456789 0123456789 <- default 40
+# 0123456789 0123456789
+ok (1/3, '0.3333333333333333333333333333333333333333');
+
+###############################################################################
+# accurarcy and precision
+
+ok_undef (bignum->accuracy());
+ok (bignum->accuracy(12),12);
+ok (bignum->accuracy(),12);
+
+ok_undef (bignum->precision());
+ok (bignum->precision(12),12);
+ok (bignum->precision(),12);
+
+ok (bignum->round_mode(),'even');
+ok (bignum->round_mode('odd'),'odd');
+ok (bignum->round_mode(),'odd');
+
+###############################################################################
+# hex() and oct()
+
+my $c = 'Math::BigInt';
+
+ok (ref(hex(1)), $c);
+ok (ref(hex(0x1)), $c);
+ok (ref(hex("af")), $c);
+ok (hex("af"), Math::BigInt->new(0xaf));
+ok (ref(hex("0x1")), $c);
+
+ok (ref(oct("0x1")), $c);
+ok (ref(oct("01")), $c);
+ok (ref(oct("0b01")), $c);
+ok (ref(oct("1")), $c);
+ok (ref(oct(" 1")), $c);
+ok (ref(oct(" 0x1")), $c);
+
+ok (ref(oct(0x1)), $c);
+ok (ref(oct(01)), $c);
+ok (ref(oct(0b01)), $c);
+ok (ref(oct(1)), $c);
+
+###############################################################################
+###############################################################################
+# Perl 5.005 does not like ok ($x,undef)
+
+sub ok_undef
+ {
+ my $x = shift;
+
+ ok (1,1) and return if !defined $x;
+ ok ($x,'undef');
+ }
diff --git a/dist/bignum/t/bigrat.t b/dist/bignum/t/bigrat.t
new file mode 100644
index 0000000000..972b83cde2
--- /dev/null
+++ b/dist/bignum/t/bigrat.t
@@ -0,0 +1,98 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 40;
+ }
+
+use bigrat qw/oct hex/;
+
+###############################################################################
+# general tests
+
+my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
+
+# todo: ok (2 + 2.5,4.5); # should still work
+# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
+
+$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
+
+# see if Math::BigRat constant works
+ok (1/3, '1/3');
+ok (1/4+1/3,'7/12');
+ok (5/7+3/7,'8/7');
+
+ok (3/7+1,'10/7');
+ok (3/7+1.1,'107/70');
+ok (3/7+3/7,'6/7');
+
+ok (3/7-1,'-4/7');
+ok (3/7-1.1,'-47/70');
+ok (3/7-2/7,'1/7');
+
+# fails ?
+# ok (1+3/7,'10/7');
+
+ok (1.1+3/7,'107/70');
+ok (3/7*5/7,'15/49');
+ok (3/7 / (5/7),'3/5');
+ok (3/7 / 1,'3/7');
+ok (3/7 / 1.5,'2/7');
+
+###############################################################################
+# accurarcy and precision
+
+ok_undef (bigrat->accuracy());
+ok (bigrat->accuracy(12),12);
+ok (bigrat->accuracy(),12);
+
+ok_undef (bigrat->precision());
+ok (bigrat->precision(12),12);
+ok (bigrat->precision(),12);
+
+ok (bigrat->round_mode(),'even');
+ok (bigrat->round_mode('odd'),'odd');
+ok (bigrat->round_mode(),'odd');
+
+###############################################################################
+# hex() and oct()
+
+my $c = 'Math::BigInt';
+
+ok (ref(hex(1)), $c);
+ok (ref(hex(0x1)), $c);
+ok (ref(hex("af")), $c);
+ok (hex("af"), Math::BigInt->new(0xaf));
+ok (ref(hex("0x1")), $c);
+
+ok (ref(oct("0x1")), $c);
+ok (ref(oct("01")), $c);
+ok (ref(oct("0b01")), $c);
+ok (ref(oct("1")), $c);
+ok (ref(oct(" 1")), $c);
+ok (ref(oct(" 0x1")), $c);
+
+ok (ref(oct(0x1)), $c);
+ok (ref(oct(01)), $c);
+ok (ref(oct(0b01)), $c);
+ok (ref(oct(1)), $c);
+
+###############################################################################
+###############################################################################
+# Perl 5.005 does not like ok ($x,undef)
+
+sub ok_undef
+ {
+ my $x = shift;
+
+ ok (1,1) and return if !defined $x;
+ ok ($x,'undef');
+ }
diff --git a/dist/bignum/t/bii_e_pi.t b/dist/bignum/t/bii_e_pi.t
new file mode 100644
index 0000000000..76ee07ae29
--- /dev/null
+++ b/dist/bignum/t/bii_e_pi.t
@@ -0,0 +1,24 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 5;
+ }
+
+use bigint qw/e PI bpi bexp/;
+
+is (e, "2", 'e');
+is (PI, "3", 'PI');
+
+is (bexp(1,10), "2", 'e');
+is (bexp(3,10), "20", 'e');
+is (bpi(10), "3", 'PI');
diff --git a/dist/bignum/t/biinfnan.t b/dist/bignum/t/biinfnan.t
new file mode 100644
index 0000000000..f136c1e66e
--- /dev/null
+++ b/dist/bignum/t/biinfnan.t
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ unshift @INC, '../lib/bignum/t' if $ENV{PERL_CORE};
+ plan tests => 26;
+ }
+
+use bigint;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/dist/bignum/t/bir_e_pi.t b/dist/bignum/t/bir_e_pi.t
new file mode 100644
index 0000000000..88342b05bd
--- /dev/null
+++ b/dist/bignum/t/bir_e_pi.t
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# test for e() and PI() exports
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bigrat qw/e PI bexp bpi/;
+
+is (e, "2.718281828459045235360287471352662497757", 'e');
+is (PI, "3.141592653589793238462643383279502884197", 'PI');
+
+# these tests should actually produce big rationals, but this is not yet
+# implemented:
+is (bexp(1,10), "2.718281828", 'e');
+is (bpi(10), "3.141592654", 'PI');
diff --git a/dist/bignum/t/bn_lite.t b/dist/bignum/t/bn_lite.t
new file mode 100644
index 0000000000..21247c1ee7
--- /dev/null
+++ b/dist/bignum/t/bn_lite.t
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 1;
+ }
+
+eval 'require Math::BigInt::Lite;';
+if ($@ eq '')
+ {
+ # can use Lite, so let bignum try it
+ require bignum; bignum->import();
+ # can't get to work a ref(1+1) here, presumable because :constant phase
+ # already done
+ ok ($bignum::_lite,1);
+ }
+else
+ {
+ print "ok 1 # skipped, no Math::BigInt::Lite\n";
+ }
+
+
diff --git a/dist/bignum/t/bninfnan.t b/dist/bignum/t/bninfnan.t
new file mode 100644
index 0000000000..fbadb068b9
--- /dev/null
+++ b/dist/bignum/t/bninfnan.t
@@ -0,0 +1,39 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ my $location = $0; $location =~ s/bninfnan.t//i;
+ if ($ENV{PERL_CORE})
+ {
+ #@INC = qw(../lib ../lib/bignum/t); # testing with the core distribution
+ }
+ else
+ {
+ unshift @INC, '../lib'; # for testing manually
+ }
+ if (-d 't')
+ {
+ chdir 't';
+ require File::Spec;
+ unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
+ }
+ else
+ {
+ unshift @INC, $location;
+ }
+ print "# INC = @INC\n";
+ plan tests => 26;
+ }
+
+use bignum;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/dist/bignum/t/br_lite.t b/dist/bignum/t/br_lite.t
new file mode 100644
index 0000000000..2bf77d4037
--- /dev/null
+++ b/dist/bignum/t/br_lite.t
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 1;
+ }
+
+eval 'require Math::BigInt::Lite;';
+if ($@ eq '')
+ {
+ # can use Lite, so let bignum try it
+ require bigrat; bigrat->import();
+ # can't get to work a ref(1+1) here, presumable because :constant phase
+ # already done
+ ok ($bigrat::_lite,1);
+ }
+else
+ {
+ print "ok 1 # skipped, no Math::BigInt::Lite\n";
+ }
+
+
diff --git a/dist/bignum/t/brinfnan.t b/dist/bignum/t/brinfnan.t
new file mode 100644
index 0000000000..286adbc0ca
--- /dev/null
+++ b/dist/bignum/t/brinfnan.t
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ unshift @INC, '../lib/bignum/t' if $ENV{PERL_CORE};
+ plan tests => 26;
+ }
+
+use bigrat;
+
+my ($x);
+
+require "infnan.inc";
+
diff --git a/dist/bignum/t/in_effect.t b/dist/bignum/t/in_effect.t
new file mode 100644
index 0000000000..b163f12b8f
--- /dev/null
+++ b/dist/bignum/t/in_effect.t
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test in_effect()
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 9;
+ }
+
+use bigint;
+use bignum;
+use bigrat;
+
+can_ok ('bigint', qw/in_effect/);
+can_ok ('bignum', qw/in_effect/);
+can_ok ('bigrat', qw/in_effect/);
+
+SKIP: {
+ skip ('Need at least Perl v5.9.4', 3) if $] < "5.009005";
+
+ is (bigint::in_effect(), 1, 'bigint in effect');
+ is (bignum::in_effect(), 1, 'bignum in effect');
+ is (bigrat::in_effect(), 1, 'bigrat in effect');
+ }
+
+{
+ no bigint;
+ no bignum;
+ no bigrat;
+
+ is (bigint::in_effect(), undef, 'bigint not in effect');
+ is (bignum::in_effect(), undef, 'bignum not in effect');
+ is (bigrat::in_effect(), undef, 'bigrat not in effect');
+}
+
diff --git a/dist/bignum/t/infnan.inc b/dist/bignum/t/infnan.inc
new file mode 100644
index 0000000000..771b94e748
--- /dev/null
+++ b/dist/bignum/t/infnan.inc
@@ -0,0 +1,35 @@
+
+use strict;
+
+my ($x);
+
+###############################################################################
+# inf tests
+
+$x = 1+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = 1*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+
+# these don't work without exporting inf()
+$x = inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = inf+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+$x = inf*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'inf');
+
+###############################################################################
+# NaN tests
+
+$x = 1+NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = 1*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
+# these don't work without exporting NaN()
+$x = NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN+NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
+###############################################################################
+# mixed tests
+
+# these don't work without exporting NaN() or inf()
+$x = NaN+inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = NaN*inf; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+$x = inf*NaN; ok (ref($x) =~ /^Math::BigInt/); ok ($x->bstr(),'NaN');
+
diff --git a/dist/bignum/t/option_a.t b/dist/bignum/t/option_a.t
new file mode 100644
index 0000000000..2086f9a8d8
--- /dev/null
+++ b/dist/bignum/t/option_a.t
@@ -0,0 +1,31 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+use bignum a => '12';
+
+my @C = qw/Math::BigInt Math::BigFloat/;
+
+foreach my $c (@C)
+ {
+ is ($c->accuracy(),12, "$c accuracy = 12");
+ }
+
+bignum->import( accuracy => '23');
+
+foreach my $c (@C)
+ {
+ is ($c->accuracy(), 23, "$c accuracy = 23");
+ }
+
diff --git a/dist/bignum/t/option_l.t b/dist/bignum/t/option_l.t
new file mode 100644
index 0000000000..cfa8033f22
--- /dev/null
+++ b/dist/bignum/t/option_l.t
@@ -0,0 +1,54 @@
+#!/usr/bin/perl -w
+
+# test the "l", "lib", "try" and "only" options:
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 19;
+ }
+
+use bignum;
+
+my @W;
+{
+# catch warnings:
+require Carp;
+no warnings 'redefine';
+*Carp::carp = sub { push @W, $_[0]; };
+}
+
+my $rc = eval ('bignum->import( "l" => "foo" );');
+is ($@,''); # shouldn't die
+is (scalar @W, 1, 'one warning');
+like ($W[0], qr/fallback to Math::/, 'got fallback');
+
+$rc = eval ('bignum->import( "lib" => "foo" );');
+is ($@,''); # ditto
+is (scalar @W, 2, 'two warnings');
+like ($W[1], qr/fallback to Math::/, 'got fallback');
+
+$rc = eval ('bignum->import( "try" => "foo" );');
+is ($@,''); # shouldn't die
+$rc = eval ('bignum->import( "try" => "foo" );');
+is ($@,''); # ditto
+
+$rc = eval ('bignum->import( "foo" => "bar" );');
+like ($@, qr/^Unknown option foo/i, 'died'); # should die
+
+$rc = eval ('bignum->import( "only" => "bar" );');
+like ($@, qr/fallback disallowed/i, 'died'); # should die
+
+# test that options are only lowercase (don't see a reason why allow UPPER)
+
+foreach (qw/L LIB Lib T Trace TRACE V Version VERSION/)
+ {
+ $rc = eval ('bignum->import( "$_" => "bar" );');
+ like ($@, qr/^Unknown option $_/i, 'died'); # should die
+ }
+
diff --git a/dist/bignum/t/option_p.t b/dist/bignum/t/option_p.t
new file mode 100644
index 0000000000..b84883be4b
--- /dev/null
+++ b/dist/bignum/t/option_p.t
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 4;
+ }
+
+my @C = qw/Math::BigInt Math::BigFloat/;
+
+use bignum p => '12';
+
+foreach my $c (@C)
+ {
+ is ($c->precision(),12, "$c precision = 12");
+ }
+
+bignum->import( p => '42' );
+
+foreach my $c (@C)
+ {
+ is ($c->precision(),42, "$c precision = 42");
+ }
+
diff --git a/dist/bignum/t/ratopt_a.t b/dist/bignum/t/ratopt_a.t
new file mode 100644
index 0000000000..f004afe428
--- /dev/null
+++ b/dist/bignum/t/ratopt_a.t
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 7;
+ }
+
+my @C = qw/Math::BigInt Math::BigFloat Math::BigRat/;
+
+# bigrat (bug until v0.15)
+use bigrat a => 2;
+
+foreach my $c (@C)
+ {
+ is ($c->accuracy(), 2, "$c accuracy = 2");
+ }
+
+eval { bigrat->import( accuracy => '42') };
+
+is ($@, '', 'no error');
+
+foreach my $c (@C)
+ {
+ is ($c->accuracy(), 42, "$c accuracy = 42");
+ }
+
diff --git a/dist/bignum/t/scope_f.t b/dist/bignum/t/scope_f.t
new file mode 100644
index 0000000000..dd748e11c8
--- /dev/null
+++ b/dist/bignum/t/scope_f.t
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test "no bignum;" and overloading of hex()/oct() for newer Perls
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 10;
+ }
+
+# no :hex and :oct means these do not get overloaded for older Perls:
+use bignum;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+SKIP: {
+ skip ('Need at least Perl v5.9.4', 2) if $] < 5.009004;
+
+ is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded');
+ is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded');
+ }
+
+{
+ no bignum;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+
+ isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded');
+ isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded');
+}
+
diff --git a/dist/bignum/t/scope_i.t b/dist/bignum/t/scope_i.t
new file mode 100644
index 0000000000..4e2f1e6e7f
--- /dev/null
+++ b/dist/bignum/t/scope_i.t
@@ -0,0 +1,42 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test "no bigint;" and overloading of hex()/oct() for newer Perls
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 10;
+ }
+
+# no :hex and :oct means these do not get overloaded for older Perls:
+use bigint;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+SKIP: {
+ skip ('Need at least Perl v5.9.4', 2) if $] < "5.009004"; # quote due to "use bigint;"
+
+ is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded');
+ is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded');
+ }
+
+{
+ no bigint;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+
+ isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded');
+ isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded');
+
+}
+
diff --git a/dist/bignum/t/scope_r.t b/dist/bignum/t/scope_r.t
new file mode 100644
index 0000000000..784fe0e6b0
--- /dev/null
+++ b/dist/bignum/t/scope_r.t
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -w
+
+###############################################################################
+# Test "no bigrat;" and overloading of hex()/oct() for newer Perls
+
+use Test::More;
+use strict;
+
+BEGIN
+ {
+ $| = 1;
+ chdir 't' if -d 't';
+ unshift @INC, '../lib';
+ plan tests => 10;
+ }
+
+# no :hex and :oct means these do not get overloaded for older Perls:
+use bigrat;
+
+isnt (ref(1), '', 'is in effect');
+isnt (ref(2.0), '', 'is in effect');
+isnt (ref(0x20), '', 'is in effect');
+
+SKIP: {
+ skip ('Need at least Perl v5.9.4', 2) if $] < 5.009004;
+
+ is (ref(hex(9)), 'Math::BigInt', 'hex is overloaded');
+ is (ref(oct(07)), 'Math::BigInt', 'oct is overloaded');
+ }
+
+{
+ no bigrat;
+
+ is (ref(1), '', 'is not in effect');
+ is (ref(2.0), '', 'is not in effect');
+ is (ref(0x20), '', 'is not in effect');
+
+ isnt (ref(hex(9)), 'Math::BigInt', 'hex is not overloaded');
+ isnt (ref(oct(07)), 'Math::BigInt', 'oct is not overloaded');
+}
+