dslinux/user/perl/lib/bignum/t bigint.t bignum.t bigrat.t biinfnan.t bn_lite.t bninfnan.t br_lite.t brinfnan.t infnan.inc option_a.t option_l.t option_p.t ratopt_a.t

cayenne dslinux_cayenne at user.in-berlin.de
Tue Dec 5 05:27:22 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/lib/bignum/t
In directory antilope:/tmp/cvs-serv7729/lib/bignum/t

Added Files:
	bigint.t bignum.t bigrat.t biinfnan.t bn_lite.t bninfnan.t 
	br_lite.t brinfnan.t infnan.inc option_a.t option_l.t 
	option_p.t ratopt_a.t 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: infnan.inc ---

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');


--- NEW FILE: bninfnan.t ---
#!/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";


--- NEW FILE: bignum.t ---
#!/usr/bin/perl -w

###############################################################################

use Test;
use strict;

BEGIN
  {
  $| = 1;
  chdir 't' if -d 't';
  unshift @INC, '../lib';
  plan tests => 20;
  }

use bignum;

###############################################################################
# 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');

###############################################################################
###############################################################################
# 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');
  }

--- NEW FILE: bigrat.t ---
#!/usr/bin/perl -w

###############################################################################

use Test;
use strict;

BEGIN
  {
  $| = 1;
  chdir 't' if -d 't';
  unshift @INC, '../lib';
  plan tests => 25;
  }

use bigrat;

###############################################################################
# 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');

###############################################################################
###############################################################################
# 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');
  }

--- NEW FILE: option_a.t ---
#!/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");
  }


--- NEW FILE: brinfnan.t ---
#!/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";


--- NEW FILE: bigint.t ---
#!/usr/bin/perl -w

###############################################################################

use Test;
use strict;

BEGIN
  {
  $| = 1;
  chdir 't' if -d 't';
  unshift @INC, '../lib';
  plan tests => 32;
  }

use bigint;

###############################################################################
# _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::_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');

###############################################################################
###############################################################################
# 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');
  }

--- NEW FILE: bn_lite.t ---
#!/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";
  }
  


--- NEW FILE: option_l.t ---
#!/usr/bin/perl -w

use Test::More;
use strict;

BEGIN
  {
  $| = 1;
  chdir 't' if -d 't';
  unshift @INC, '../lib';
  plan tests => 12;
  }

use bignum;

my $rc = eval ('bignum->import( "l" => "foo" );');
is ($@,'');						# shouldn't die
$rc = eval ('bignum->import( "lib" => "foo" );');
is ($@,'');						# ditto

$rc = eval ('bignum->import( "foo" => "bar" );');
like ($@, qr/^Unknown option foo/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
  }


--- NEW FILE: option_p.t ---
#!/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");
  }


--- NEW FILE: biinfnan.t ---
#!/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";


--- NEW FILE: ratopt_a.t ---
#!/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");
  }


--- NEW FILE: br_lite.t ---
#!/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";
  }
  





More information about the dslinux-commit mailing list