1N/A#!/usr/bin/perl -w
1N/A
1N/A###############################################################################
1N/A
1N/Ause Test;
1N/Ause strict;
1N/A
1N/ABEGIN
1N/A {
1N/A $| = 1;
1N/A chdir 't' if -d 't';
1N/A unshift @INC, '../lib';
1N/A plan tests => 32;
1N/A }
1N/A
1N/Ause bigint;
1N/A
1N/A###############################################################################
1N/A# _constant tests
1N/A
1N/Aforeach (qw/
1N/A 123:123
1N/A 123.4:123
1N/A 1.4:1
1N/A 0.1:0
1N/A -0.1:0
1N/A -1.1:-1
1N/A -123.4:-123
1N/A -123:-123
1N/A 123e2:123e2
1N/A 123e-1:12
1N/A 123e-4:0
1N/A 123e-3:0
1N/A 123.345e-1:12
1N/A 123.456e+2:12345
1N/A 1234.567e+3:1234567
1N/A 1234.567e+4:1234567E1
1N/A 1234.567e+6:1234567E3
1N/A /)
1N/A {
1N/A my ($x,$y) = split /:/;
1N/A print "# Try $x\n";
1N/A ok (bigint::_constant("$x"),"$y");
1N/A }
1N/A
1N/A###############################################################################
1N/A# general tests
1N/A
1N/Amy $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
1N/A
1N/A# todo: ok (2 + 2.5,4.5); # should still work
1N/A# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
1N/A
1N/A$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
1N/A
1N/Aok (12->bfac(),479001600);
1N/Aok (9/4,2);
1N/A
1N/Aok (4.5+4.5,8); # truncate
1N/Aok (ref(4.5+4.5) =~ /^Math::BigInt/);
1N/A
1N/A
1N/A###############################################################################
1N/A# accurarcy and precision
1N/A
1N/Aok_undef (bigint->accuracy());
1N/Aok (bigint->accuracy(12),12);
1N/Aok (bigint->accuracy(),12);
1N/A
1N/Aok_undef (bigint->precision());
1N/Aok (bigint->precision(12),12);
1N/Aok (bigint->precision(),12);
1N/A
1N/Aok (bigint->round_mode(),'even');
1N/Aok (bigint->round_mode('odd'),'odd');
1N/Aok (bigint->round_mode(),'odd');
1N/A
1N/A###############################################################################
1N/A###############################################################################
1N/A# Perl 5.005 does not like ok ($x,undef)
1N/A
1N/Asub ok_undef
1N/A {
1N/A my $x = shift;
1N/A
1N/A ok (1,1) and return if !defined $x;
1N/A ok ($x,'undef');
1N/A }