diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-09-10 14:33:47 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-09-10 14:33:47 +0100 |
commit | 3167abe51b640d3c3589b1f66145bedb05d9405f (patch) | |
tree | 6eca738c3d75d6d7cadd0ff0a179023ba63fc0ec | |
parent | 4aa37fafef47f0609c457610076d77d6e96c8803 (diff) | |
download | perl-3167abe51b640d3c3589b1f66145bedb05d9405f.tar.gz |
Convert Math::BigInt tests from Test to Test::More.
35 files changed, 945 insertions, 1155 deletions
diff --git a/dist/Math-BigInt/t/bare_mbf.t b/dist/Math-BigInt/t/bare_mbf.t index 96e041a4c7..7fb1ff0006 100644 --- a/dist/Math-BigInt/t/bare_mbf.t +++ b/dist/Math-BigInt/t/bare_mbf.t @@ -1,13 +1,9 @@ #!/usr/bin/perl -w -use Test; use strict; +use Test::More tests => 2316; -BEGIN - { - unshift @INC, 't'; - plan tests => 2316; - } +BEGIN { unshift @INC, 't'; } use Math::BigFloat lib => 'BareCalc'; diff --git a/dist/Math-BigInt/t/bare_mbi.t b/dist/Math-BigInt/t/bare_mbi.t index 849e5989b8..38b82afab3 100644 --- a/dist/Math-BigInt/t/bare_mbi.t +++ b/dist/Math-BigInt/t/bare_mbi.t @@ -1,13 +1,9 @@ #!/usr/bin/perl -w -use Test; use strict; +use Test::More tests => 3279; -BEGIN - { - unshift @INC, 't'; - plan tests => 3279; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt lib => 'BareCalc'; diff --git a/dist/Math-BigInt/t/bare_mif.t b/dist/Math-BigInt/t/bare_mif.t index 43407124c9..2c80f7fedd 100644 --- a/dist/Math-BigInt/t/bare_mif.t +++ b/dist/Math-BigInt/t/bare_mif.t @@ -4,14 +4,10 @@ # of classes under BareCalc use strict; -use Test; - -BEGIN - { - unshift @INC, 't'; - plan tests => 684 +use Test::More tests => 684 + 1; # our own tests - } + +BEGIN { unshift @INC, 't'; } print "# ",Math::BigInt->config()->{lib},"\n"; @@ -23,6 +19,6 @@ use vars qw/$mbi $mbf/; $mbi = 'Math::BigInt'; $mbf = 'Math::BigFloat'; -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); +is (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); require 't/mbimbf.inc'; diff --git a/dist/Math-BigInt/t/bigfltpm.inc b/dist/Math-BigInt/t/bigfltpm.inc index 309b86e25c..e8801a51bf 100644 --- a/dist/Math-BigInt/t/bigfltpm.inc +++ b/dist/Math-BigInt/t/bigfltpm.inc @@ -1,6 +1,6 @@ #include this file into another test for subclass testing... -ok ($class->config()->{lib},$CL); +is ($class->config()->{lib},$CL); use strict; @@ -164,29 +164,29 @@ while (<DATA>) my $pat = $1; if ($ans1 =~ /$pat/) { - ok (1,1); + is (1,1); } else { - print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0); + print "# '$try' expected: /$pat/ got: '$ans1'\n" if !is (1,0); } } else { if ($ans eq "") { - ok_undef ($ans1); + is ($ans1, undef); } else { - print "# Tried: '$try'\n" if !ok ($ans1, $ans); + print "# Tried: '$try'\n" if !is ($ans1, $ans); if (ref($ans1) eq "$class") { # float numbers are normalized (for now), so mantissa shouldn't have # trailing zeros #print $ans1->_trailing_zeros(),"\n"; print "# Has trailing zeros after '$try'\n" - if !ok ($CL->_zeros( $ans1->{_m}), 0); + if !is ($CL->_zeros( $ans1->{_m}), 0); } } } # end pattern or string @@ -196,7 +196,7 @@ while (<DATA>) # check whether $class->new( Math::BigInt->new()) destroys it # ($y == 12 in this case) $x = Math::BigInt->new(1200); $y = $class->new($x); -ok ($y,1200); ok ($x,1200); +is ($y,1200); is ($x,1200); ############################################################################### # Really huge, big, ultra-mega-biggy-monster exponents @@ -210,43 +210,43 @@ ok ($y,1200); ok ($x,1200); my $monster = '1e1234567890123456789012345678901234567890'; # new and exponent -ok ($class->new($monster)->bsstr(), +is ($class->new($monster)->bsstr(), '1e+1234567890123456789012345678901234567890'); -ok ($class->new($monster)->exponent(), +is ($class->new($monster)->exponent(), '1234567890123456789012345678901234567890'); # cmp -ok ($class->new($monster) > 0,1); +is ($class->new($monster) > 0,1); # sub/mul -ok ($class->new($monster)->bsub( $monster),0); -ok ($class->new($monster)->bmul(2)->bsstr(), +is ($class->new($monster)->bsub( $monster),0); +is ($class->new($monster)->bmul(2)->bsstr(), '2e+1234567890123456789012345678901234567890'); # mantissa $monster = '1234567890123456789012345678901234567890e2'; -ok ($class->new($monster)->mantissa(), +is ($class->new($monster)->mantissa(), '123456789012345678901234567890123456789'); ############################################################################### # zero,inf,one,nan -$x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); +$x = $class->new(2); $x->fzero(); is ($x->{_a}, undef); is ($x->{_p}, undef); +$x = $class->new(2); $x->finf(); is ($x->{_a}, undef); is ($x->{_p}, undef); +$x = $class->new(2); $x->fone(); is ($x->{_a}, undef); is ($x->{_p}, undef); +$x = $class->new(2); $x->fnan(); is ($x->{_a}, undef); is ($x->{_p}, undef); ############################################################################### # bone/binf etc as plain calls (Lite failed them) -ok ($class->fzero(),0); -ok ($class->fone(),1); -ok ($class->fone('+'),1); -ok ($class->fone('-'),-1); -ok ($class->fnan(),'NaN'); -ok ($class->finf(),'inf'); -ok ($class->finf('+'),'inf'); -ok ($class->finf('-'),'-inf'); -ok ($class->finf('-inf'),'-inf'); +is ($class->fzero(),0); +is ($class->fone(),1); +is ($class->fone('+'),1); +is ($class->fone('-'),-1); +is ($class->fnan(),'NaN'); +is ($class->finf(),'inf'); +is ($class->finf('+'),'inf'); +is ($class->finf('-'),'-inf'); +is ($class->finf('-inf'),'-inf'); $class->accuracy(undef); $class->precision(undef); # reset @@ -255,27 +255,27 @@ $class->accuracy(undef); $class->precision(undef); # reset $x = $class->new('0.008'); $y = $class->new(2); $x->bdiv(3,$y); -ok ($x,'0.0027'); +is ($x,'0.0027'); ############################################################################### # fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt() # correctly modifies $x -$x = $class->new(12); $class->precision(-2); $x->fsqrt(); ok ($x,'3.46'); +$x = $class->new(12); $class->precision(-2); $x->fsqrt(); is ($x,'3.46'); $class->precision(undef); -$x = $class->new(12); $class->precision(0); $x->fsqrt(); ok ($x,'3'); +$x = $class->new(12); $class->precision(0); $x->fsqrt(); is ($x,'3'); -$class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464'); +$class->precision(-3); $x = $class->new(12); $x->fsqrt(); is ($x,'3.464'); { no strict 'refs'; # A and P set => NaN ${${class}.'::accuracy'} = 4; $x = $class->new(12); - $x->fsqrt(3); ok ($x,'NaN'); + $x->fsqrt(3); is ($x,'NaN'); # supplied arg overrides set global - $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); ok ($x,'3.46'); + $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); is ($x,'3.46'); $class->accuracy(undef); $class->precision(undef); # reset for further tests } @@ -287,47 +287,47 @@ $class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464'); $try = '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);'; $ans = eval $try; - ok ($ans,"$class 4 5"); + is ($ans,"$class 4 5"); } ############################################################################# # is_one('-') (broken until v1.64) -ok ($class->new(-1)->is_one(),0); -ok ($class->new(-1)->is_one('-'),1); +is ($class->new(-1)->is_one(),0); +is ($class->new(-1)->is_one('-'),1); ############################################################################# # bug 1/0.5 leaving 2e-0 instead of 2e0 -ok ($class->new(1)->fdiv('0.5')->bsstr(),'2e+0'); +is ($class->new(1)->fdiv('0.5')->bsstr(),'2e+0'); ############################################################################### # [perl #30609] bug with $x -= $x not being 0, but 2*$x -$x = $class->new(3); $x -= $x; ok ($x, 0); -$x = $class->new(-3); $x -= $x; ok ($x, 0); -$x = $class->new(3); $x += $x; ok ($x, 6); -$x = $class->new(-3); $x += $x; ok ($x, -6); +$x = $class->new(3); $x -= $x; is ($x, 0); +$x = $class->new(-3); $x -= $x; is ($x, 0); +$x = $class->new(3); $x += $x; is ($x, 6); +$x = $class->new(-3); $x += $x; is ($x, -6); -$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1); +$x = $class->new('NaN'); $x -= $x; is ($x->is_nan(), 1); +$x = $class->new('inf'); $x -= $x; is ($x->is_nan(), 1); +$x = $class->new('-inf'); $x -= $x; is ($x->is_nan(), 1); -$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1); -$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1); +$x = $class->new('NaN'); $x += $x; is ($x->is_nan(), 1); +$x = $class->new('inf'); $x += $x; is ($x->is_inf(), 1); +$x = $class->new('-inf'); $x += $x; is ($x->is_inf('-'), 1); -$x = $class->new('3.14'); $x -= $x; ok ($x, 0); -$x = $class->new('-3.14'); $x -= $x; ok ($x, 0); -$x = $class->new('3.14'); $x += $x; ok ($x, '6.28'); -$x = $class->new('-3.14'); $x += $x; ok ($x, '-6.28'); +$x = $class->new('3.14'); $x -= $x; is ($x, 0); +$x = $class->new('-3.14'); $x -= $x; is ($x, 0); +$x = $class->new('3.14'); $x += $x; is ($x, '6.28'); +$x = $class->new('-3.14'); $x += $x; is ($x, '-6.28'); -$x = $class->new('3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('-3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('-3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('3.14'); $x %= $x; ok ($x, '0'); -$x = $class->new('-3.14'); $x %= $x; ok ($x, '0'); +$x = $class->new('3.14'); $x *= $x; is ($x, '9.8596'); +$x = $class->new('-3.14'); $x *= $x; is ($x, '9.8596'); +$x = $class->new('3.14'); $x /= $x; is ($x, '1'); +$x = $class->new('-3.14'); $x /= $x; is ($x, '1'); +$x = $class->new('3.14'); $x %= $x; is ($x, '0'); +$x = $class->new('-3.14'); $x %= $x; is ($x, '0'); ############################################################################### # the following two were reported by "kenny" via hotmail.com: @@ -336,50 +336,39 @@ $x = $class->new('-3.14'); $x %= $x; ok ($x, '0'); #Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. $x = $class->new(0); $y = $class->new('0.1'); -ok ($x ** $y, 0, 'no warnings and zero result'); +is ($x ** $y, 0, 'no warnings and zero result'); #perl -MMath::BigFloat -lwe 'print Math::BigFloat->new(".222222222222222222222222222222222222222222")->bceil()' #Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. $x = $class->new(".222222222222222222222222222222222222222222"); -ok ($x->bceil(), 1, 'no warnings and one as result'); +is ($x->bceil(), 1, 'no warnings and one as result'); ############################################################################### # test **=, <<=, >>= # ((2^148)-1)/17 $x = $class->new(2); $x **= 148; $x++; $x->bdiv(17, 60)->bfloor(); $x->accuracy(undef); -ok ($x,"20988936657440586486151264256610222593863921"); -ok ($x->length(),length "20988936657440586486151264256610222593863921"); +is ($x,"20988936657440586486151264256610222593863921"); +is ($x->length(),length "20988936657440586486151264256610222593863921"); $x = $class->new('2'); my $y = $class->new('18'); -ok ($x <<= $y, 2 << 18); -ok ($x, 2 << 18); -ok ($x >>= $y, 2); -ok ($x, 2); +is ($x <<= $y, 2 << 18); +is ($x, 2 << 18); +is ($x >>= $y, 2); +is ($x, 2); $x = $class->new('2'); $y = $class->new('18.2'); $x <<= $y; # 2 * (2 ** 18.2); -ok ($x->copy()->bfround(-9), '602248.763144685'); -ok ($x >>= $y, 2); # 2 * (2 ** 18.2) / (2 ** 18.2) => 2 -ok ($x, 2); +is ($x->copy()->bfround(-9), '602248.763144685'); +is ($x >>= $y, 2); # 2 * (2 ** 18.2) / (2 ** 18.2) => 2 +is ($x, 2); 1; # all done -############################################################################### -# 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'); - } - __DATA__ &bgcd inf:12:NaN diff --git a/dist/Math-BigInt/t/bigfltpm.t b/dist/Math-BigInt/t/bigfltpm.t index 43807635e1..fa6f878cc3 100644 --- a/dist/Math-BigInt/t/bigfltpm.t +++ b/dist/Math-BigInt/t/bigfltpm.t @@ -1,13 +1,9 @@ #!/usr/bin/perl -w -use Test; use strict; +use Test::More tests => 2316 + + 5; # own tests -BEGIN - { - plan tests => 2316 - + 5; # own tests - } use Math::BigInt lib => 'Calc'; use Math::BigFloat; @@ -16,18 +12,18 @@ use vars qw ($class $try $x $y $f @args $ans $ans1 $ans1_str $setup $CL); $class = "Math::BigFloat"; $CL = "Math::BigInt::Calc"; -ok ($class->config()->{class},$class); -ok ($class->config()->{with}, $CL); +is ($class->config()->{class},$class); +is ($class->config()->{with}, $CL); # bug #17447: Can't call method Math::BigFloat->bsub, not a valid method my $c = Math::BigFloat->new( '123.3' ); -ok ($c->fsub(123) eq '0.3', 1); # calling fsub on a BigFloat works +is ($c->fsub(123), '0.3'); # calling fsub on a BigFloat works # Bug until BigInt v1.86, the scale wasn't treated as a scalar: $c = Math::BigFloat->new('0.008'); my $d = Math::BigFloat->new(3); my $e = $c->bdiv(Math::BigFloat->new(3),$d); -ok ($e,'0.00267'); # '0.008 / 3 => 0.0027'); -ok (ref($e->{_e}->[0]), ''); # 'Not a BigInt'); +is ($e,'0.00267'); # '0.008 / 3 => 0.0027'); +is (ref($e->{_e}->[0]), ''); # 'Not a BigInt'); require 't/bigfltpm.inc'; # all tests here for sharing diff --git a/dist/Math-BigInt/t/bigintc.t b/dist/Math-BigInt/t/bigintc.t index 763cb79ec4..a1274f2a59 100644 --- a/dist/Math-BigInt/t/bigintc.t +++ b/dist/Math-BigInt/t/bigintc.t @@ -1,12 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test; - -BEGIN - { - plan tests => 375; - } +use Test::More tests => 375; use Math::BigInt::Calc; @@ -25,249 +20,249 @@ my $C = 'Math::BigInt::Calc'; # pass classname to sub's # _new and _str my $x = $C->_new("123"); my $y = $C->_new("321"); -ok (ref($x),'ARRAY'); ok ($C->_str($x),123); ok ($C->_str($y),321); +is (ref($x),'ARRAY'); is ($C->_str($x),123); is ($C->_str($y),321); ############################################################################### # _add, _sub, _mul, _div -ok ($C->_str($C->_add($x,$y)),444); -ok ($C->_str($C->_sub($x,$y)),123); -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($C->_div($x,$y)),123); +is ($C->_str($C->_add($x,$y)),444); +is ($C->_str($C->_sub($x,$y)),123); +is ($C->_str($C->_mul($x,$y)),39483); +is ($C->_str($C->_div($x,$y)),123); ############################################################################### # check that mul/div doesn't change $y # and returns the same reference, not something new -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($x),39483); ok ($C->_str($y),321); +is ($C->_str($C->_mul($x,$y)),39483); +is ($C->_str($x),39483); is ($C->_str($y),321); -ok ($C->_str($C->_div($x,$y)),123); -ok ($C->_str($x),123); ok ($C->_str($y),321); +is ($C->_str($C->_div($x,$y)),123); +is ($C->_str($x),123); is ($C->_str($y),321); $x = $C->_new("39483"); my ($x1,$r1) = $C->_div($x,$y); -ok ("$x1","$x"); +is ("$x1","$x"); $C->_inc($x1); -ok ("$x1","$x"); -ok ($C->_str($r1),'0'); +is ("$x1","$x"); +is ($C->_str($r1),'0'); $x = $C->_new("39483"); # reset ############################################################################### my $z = $C->_new("2"); -ok ($C->_str($C->_add($x,$z)),39485); +is ($C->_str($C->_add($x,$z)),39485); my ($re,$rr) = $C->_div($x,$y); -ok ($C->_str($re),123); ok ($C->_str($rr),2); +is ($C->_str($re),123); is ($C->_str($rr),2); # is_zero, _is_one, _one, _zero -ok ($C->_is_zero($x)||0,0); -ok ($C->_is_one($x)||0,0); +is ($C->_is_zero($x)||0,0); +is ($C->_is_one($x)||0,0); -ok ($C->_str($C->_zero()),"0"); -ok ($C->_str($C->_one()),"1"); +is ($C->_str($C->_zero()),"0"); +is ($C->_str($C->_one()),"1"); # _two() and _ten() -ok ($C->_str($C->_two()),"2"); -ok ($C->_str($C->_ten()),"10"); -ok ($C->_is_ten($C->_two()),0); -ok ($C->_is_two($C->_two()),1); -ok ($C->_is_ten($C->_ten()),1); -ok ($C->_is_two($C->_ten()),0); +is ($C->_str($C->_two()),"2"); +is ($C->_str($C->_ten()),"10"); +is ($C->_is_ten($C->_two()),0); +is ($C->_is_two($C->_two()),1); +is ($C->_is_ten($C->_ten()),1); +is ($C->_is_two($C->_ten()),0); -ok ($C->_is_one($C->_one()),1); -ok ($C->_is_one($C->_two()),0); -ok ($C->_is_one($C->_ten()),0); +is ($C->_is_one($C->_one()),1); +is ($C->_is_one($C->_two()),0); +is ($C->_is_one($C->_ten()),0); -ok ($C->_is_one($C->_zero()) || 0,0); +is ($C->_is_one($C->_zero()) || 0,0); -ok ($C->_is_zero($C->_zero()),1); +is ($C->_is_zero($C->_zero()),1); -ok ($C->_is_zero($C->_one()) || 0,0); +is ($C->_is_zero($C->_one()) || 0,0); # is_odd, is_even -ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero())||0,0); -ok ($C->_is_even($C->_one()) || 0,0); ok ($C->_is_even($C->_zero()),1); +is ($C->_is_odd($C->_one()),1); is ($C->_is_odd($C->_zero())||0,0); +is ($C->_is_even($C->_one()) || 0,0); is ($C->_is_even($C->_zero()),1); # _len for my $method (qw/_alen _len/) { - $x = $C->_new("1"); ok ($C->$method($x),1); - $x = $C->_new("12"); ok ($C->$method($x),2); - $x = $C->_new("123"); ok ($C->$method($x),3); - $x = $C->_new("1234"); ok ($C->$method($x),4); - $x = $C->_new("12345"); ok ($C->$method($x),5); - $x = $C->_new("123456"); ok ($C->$method($x),6); - $x = $C->_new("1234567"); ok ($C->$method($x),7); - $x = $C->_new("12345678"); ok ($C->$method($x),8); - $x = $C->_new("123456789"); ok ($C->$method($x),9); - - $x = $C->_new("8"); ok ($C->$method($x),1); - $x = $C->_new("21"); ok ($C->$method($x),2); - $x = $C->_new("321"); ok ($C->$method($x),3); - $x = $C->_new("4321"); ok ($C->$method($x),4); - $x = $C->_new("54321"); ok ($C->$method($x),5); - $x = $C->_new("654321"); ok ($C->$method($x),6); - $x = $C->_new("7654321"); ok ($C->$method($x),7); - $x = $C->_new("87654321"); ok ($C->$method($x),8); - $x = $C->_new("987654321"); ok ($C->$method($x),9); - - $x = $C->_new("0"); ok ($C->$method($x),1); - $x = $C->_new("20"); ok ($C->$method($x),2); - $x = $C->_new("320"); ok ($C->$method($x),3); - $x = $C->_new("4320"); ok ($C->$method($x),4); - $x = $C->_new("54320"); ok ($C->$method($x),5); - $x = $C->_new("654320"); ok ($C->$method($x),6); - $x = $C->_new("7654320"); ok ($C->$method($x),7); - $x = $C->_new("87654320"); ok ($C->$method($x),8); - $x = $C->_new("987654320"); ok ($C->$method($x),9); + $x = $C->_new("1"); is ($C->$method($x),1); + $x = $C->_new("12"); is ($C->$method($x),2); + $x = $C->_new("123"); is ($C->$method($x),3); + $x = $C->_new("1234"); is ($C->$method($x),4); + $x = $C->_new("12345"); is ($C->$method($x),5); + $x = $C->_new("123456"); is ($C->$method($x),6); + $x = $C->_new("1234567"); is ($C->$method($x),7); + $x = $C->_new("12345678"); is ($C->$method($x),8); + $x = $C->_new("123456789"); is ($C->$method($x),9); + + $x = $C->_new("8"); is ($C->$method($x),1); + $x = $C->_new("21"); is ($C->$method($x),2); + $x = $C->_new("321"); is ($C->$method($x),3); + $x = $C->_new("4321"); is ($C->$method($x),4); + $x = $C->_new("54321"); is ($C->$method($x),5); + $x = $C->_new("654321"); is ($C->$method($x),6); + $x = $C->_new("7654321"); is ($C->$method($x),7); + $x = $C->_new("87654321"); is ($C->$method($x),8); + $x = $C->_new("987654321"); is ($C->$method($x),9); + + $x = $C->_new("0"); is ($C->$method($x),1); + $x = $C->_new("20"); is ($C->$method($x),2); + $x = $C->_new("320"); is ($C->$method($x),3); + $x = $C->_new("4320"); is ($C->$method($x),4); + $x = $C->_new("54320"); is ($C->$method($x),5); + $x = $C->_new("654320"); is ($C->$method($x),6); + $x = $C->_new("7654320"); is ($C->$method($x),7); + $x = $C->_new("87654320"); is ($C->$method($x),8); + $x = $C->_new("987654320"); is ($C->$method($x),9); for (my $i = 1; $i < 9; $i++) { my $a = "$i" . '0' x ($i-1); $x = $C->_new($a); - print "# Tried len '$a'\n" unless ok ($C->_len($x),$i); + print "# Tried len '$a'\n" unless is ($C->_len($x),$i); } } # _digit $x = $C->_new("123456789"); -ok ($C->_digit($x,0),9); -ok ($C->_digit($x,1),8); -ok ($C->_digit($x,2),7); -ok ($C->_digit($x,-1),1); -ok ($C->_digit($x,-2),2); -ok ($C->_digit($x,-3),3); +is ($C->_digit($x,0),9); +is ($C->_digit($x,1),8); +is ($C->_digit($x,2),7); +is ($C->_digit($x,-1),1); +is ($C->_digit($x,-2),2); +is ($C->_digit($x,-3),3); # _copy foreach (qw/ 1 12 123 1234 12345 123456 1234567 12345678 123456789/) { $x = $C->_new("$_"); - ok ($C->_str($C->_copy($x)),"$_"); - ok ($C->_str($x),"$_"); # did _copy destroy original x? + is ($C->_str($C->_copy($x)),"$_"); + is ($C->_str($x),"$_"); # did _copy destroy original x? } # _zeros -$x = $C->_new("1256000000"); ok ($C->_zeros($x),6); -$x = $C->_new("152"); ok ($C->_zeros($x),0); -$x = $C->_new("123000"); ok ($C->_zeros($x),3); -$x = $C->_new("0"); ok ($C->_zeros($x),0); +$x = $C->_new("1256000000"); is ($C->_zeros($x),6); +$x = $C->_new("152"); is ($C->_zeros($x),0); +$x = $C->_new("123000"); is ($C->_zeros($x),3); +$x = $C->_new("0"); is ($C->_zeros($x),0); # _lsft, _rsft $x = $C->_new("10"); $y = $C->_new("3"); -ok ($C->_str($C->_lsft($x,$y,10)),10000); +is ($C->_str($C->_lsft($x,$y,10)),10000); $x = $C->_new("20"); $y = $C->_new("3"); -ok ($C->_str($C->_lsft($x,$y,10)),20000); +is ($C->_str($C->_lsft($x,$y,10)),20000); $x = $C->_new("128"); $y = $C->_new("4"); -ok ($C->_str($C->_lsft($x,$y,2)), 128 << 4); +is ($C->_str($C->_lsft($x,$y,2)), 128 << 4); $x = $C->_new("1000"); $y = $C->_new("3"); -ok ($C->_str($C->_rsft($x,$y,10)),1); +is ($C->_str($C->_rsft($x,$y,10)),1); $x = $C->_new("20000"); $y = $C->_new("3"); -ok ($C->_str($C->_rsft($x,$y,10)),20); +is ($C->_str($C->_rsft($x,$y,10)),20); $x = $C->_new("256"); $y = $C->_new("4"); -ok ($C->_str($C->_rsft($x,$y,2)),256 >> 4); +is ($C->_str($C->_rsft($x,$y,2)),256 >> 4); $x = $C->_new("6411906467305339182857313397200584952398"); $y = $C->_new("45"); -ok ($C->_str($C->_rsft($x,$y,10)),0); +is ($C->_str($C->_rsft($x,$y,10)),0); # _acmp $x = $C->_new("123456789"); $y = $C->_new("987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); +is ($C->_acmp($x,$y),-1); +is ($C->_acmp($y,$x),1); +is ($C->_acmp($x,$x),0); +is ($C->_acmp($y,$y),0); $x = $C->_new("12"); $y = $C->_new("12"); -ok ($C->_acmp($x,$y),0); +is ($C->_acmp($x,$y),0); $x = $C->_new("21"); -ok ($C->_acmp($x,$y),1); -ok ($C->_acmp($y,$x),-1); +is ($C->_acmp($x,$y),1); +is ($C->_acmp($y,$x),-1); $x = $C->_new("123456789"); $y = $C->_new("1987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),+1); +is ($C->_acmp($x,$y),-1); +is ($C->_acmp($y,$x),+1); $x = $C->_new("1234567890123456789"); $y = $C->_new("987654321012345678"); -ok ($C->_acmp($x,$y),1); -ok ($C->_acmp($y,$x),-1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); +is ($C->_acmp($x,$y),1); +is ($C->_acmp($y,$x),-1); +is ($C->_acmp($x,$x),0); +is ($C->_acmp($y,$y),0); $x = $C->_new("1234"); $y = $C->_new("987654321012345678"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); +is ($C->_acmp($x,$y),-1); +is ($C->_acmp($y,$x),1); +is ($C->_acmp($x,$x),0); +is ($C->_acmp($y,$y),0); # _modinv $x = $C->_new("8"); $y = $C->_new("5033"); my ($xmod,$sign) = $C->_modinv($x,$y); -ok ($C->_str($xmod),'629'); # -629 % 5033 == 4404 -ok ($sign, '-'); +is ($C->_str($xmod),'629'); # -629 % 5033 == 4404 +is ($sign, '-'); # _div $x = $C->_new("3333"); $y = $C->_new("1111"); -ok ($C->_str(scalar $C->_div($x,$y)),3); +is ($C->_str(scalar $C->_div($x,$y)),3); $x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); -ok ($C->_str($x),30); ok ($C->_str($y),3); +is ($C->_str($x),30); is ($C->_str($y),3); $x = $C->_new("123"); $y = $C->_new("1111"); -($x,$y) = $C->_div($x,$y); ok ($C->_str($x),0); ok ($C->_str($y),123); +($x,$y) = $C->_div($x,$y); is ($C->_str($x),0); is ($C->_str($y),123); # _num foreach (qw/1 12 123 1234 12345 1234567 12345678 123456789 1234567890/) { $x = $C->_new("$_"); - ok (ref($x)||'','ARRAY'); ok ($C->_str($x),"$_"); - $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,$_); + is (ref($x),'ARRAY'); is ($C->_str($x),"$_"); + $x = $C->_num($x); is (ref($x),''); is ($x,$_); } # _sqrt -$x = $C->_new("144"); ok ($C->_str($C->_sqrt($x)),'12'); -$x = $C->_new("144000000000000"); ok ($C->_str($C->_sqrt($x)),'12000000'); +$x = $C->_new("144"); is ($C->_str($C->_sqrt($x)),'12'); +$x = $C->_new("144000000000000"); is ($C->_str($C->_sqrt($x)),'12000000'); # _root $x = $C->_new("81"); my $n = $C->_new("3"); # 4*4*4 = 64, 5*5*5 = 125 -ok ($C->_str($C->_root($x,$n)),'4'); # 4.xx => 4.0 +is ($C->_str($C->_root($x,$n)),'4'); # 4.xx => 4.0 $x = $C->_new("81"); $n = $C->_new("4"); # 3*3*3*3 == 81 -ok ($C->_str($C->_root($x,$n)),'3'); +is ($C->_str($C->_root($x,$n)),'3'); # _pow (and _root) $x = $C->_new("0"); $n = $C->_new("3"); # 0 ** y => 0 -ok ($C->_str($C->_pow($x,$n)), 0); +is ($C->_str($C->_pow($x,$n)), 0); $x = $C->_new("3"); $n = $C->_new("0"); # x ** 0 => 1 -ok ($C->_str($C->_pow($x,$n)), 1); +is ($C->_str($C->_pow($x,$n)), 1); $x = $C->_new("1"); $n = $C->_new("3"); # 1 ** y => 1 -ok ($C->_str($C->_pow($x,$n)), 1); +is ($C->_str($C->_pow($x,$n)), 1); $x = $C->_new("5"); $n = $C->_new("1"); # x ** 1 => x -ok ($C->_str($C->_pow($x,$n)), 5); +is ($C->_str($C->_pow($x,$n)), 5); $x = $C->_new("81"); $n = $C->_new("3"); # 81 ** 3 == 531441 -ok ($C->_str($C->_pow($x,$n)),81 ** 3); +is ($C->_str($C->_pow($x,$n)),81 ** 3); -ok ($C->_str($C->_root($x,$n)),81); +is ($C->_str($C->_root($x,$n)),81); $x = $C->_new("81"); -ok ($C->_str($C->_pow($x,$n)),81 ** 3); -ok ($C->_str($C->_pow($x,$n)),'150094635296999121'); # 531441 ** 3 == +is ($C->_str($C->_pow($x,$n)),81 ** 3); +is ($C->_str($C->_pow($x,$n)),'150094635296999121'); # 531441 ** 3 == -ok ($C->_str($C->_root($x,$n)),'531441'); -ok ($C->_str($C->_root($x,$n)),'81'); +is ($C->_str($C->_root($x,$n)),'531441'); +is ($C->_str($C->_root($x,$n)),'81'); $x = $C->_new("81"); $n = $C->_new("14"); -ok ($C->_str($C->_pow($x,$n)),'523347633027360537213511521'); -ok ($C->_str($C->_root($x,$n)),'81'); +is ($C->_str($C->_pow($x,$n)),'523347633027360537213511521'); +is ($C->_str($C->_root($x,$n)),'81'); $x = $C->_new("523347633027360537213511520"); -ok ($C->_str($C->_root($x,$n)),'80'); +is ($C->_str($C->_root($x,$n)),'80'); $x = $C->_new("523347633027360537213511522"); -ok ($C->_str($C->_root($x,$n)),'81'); +is ($C->_str($C->_root($x,$n)),'81'); my $res = [ qw/9 31 99 316 999 3162 9999 31622 99999/ ]; @@ -278,7 +273,7 @@ for my $i (2 .. 9) $n = $C->_new("2"); my $rc = '9' x ($i-1). '8' . '0' x ($i-1) . '1'; print "# _pow( ", '9' x $i, ", 2) \n" unless - ok ($C->_str($C->_pow($x,$n)),$rc); + is ($C->_str($C->_pow($x,$n)),$rc); # if $i > $BASE_LEN, the test takes a really long time: if ($i <= $BASE_LEN) @@ -287,36 +282,36 @@ for my $i (2 .. 9) $n = '9' x $i; $n = $C->_new($n); print "# _root( ", '9' x $i, ", ", 9 x $i, ") \n"; print "# _root( ", '9' x $i, ", ", 9 x $i, ") \n" unless - ok ($C->_str($C->_root($x,$n)),'1'); + is ($C->_str($C->_root($x,$n)),'1'); $x = '9' x $i; $x = $C->_new($x); $n = $C->_new("2"); print "# BASE_LEN $BASE_LEN _root( ", '9' x $i, ", ", 9 x $i, ") \n" unless - ok ($C->_str($C->_root($x,$n)), $res->[$i-2]); + is ($C->_str($C->_root($x,$n)), $res->[$i-2]); } else { - ok ("skipped $i", "skipped $i"); - ok ("skipped $i", "skipped $i"); + is ("skipped $i", "skipped $i"); + is ("skipped $i", "skipped $i"); } } ############################################################################## # _fac -$x = $C->_new("0"); ok ($C->_str($C->_fac($x)),'1'); -$x = $C->_new("1"); ok ($C->_str($C->_fac($x)),'1'); -$x = $C->_new("2"); ok ($C->_str($C->_fac($x)),'2'); -$x = $C->_new("3"); ok ($C->_str($C->_fac($x)),'6'); -$x = $C->_new("4"); ok ($C->_str($C->_fac($x)),'24'); -$x = $C->_new("5"); ok ($C->_str($C->_fac($x)),'120'); -$x = $C->_new("10"); ok ($C->_str($C->_fac($x)),'3628800'); -$x = $C->_new("11"); ok ($C->_str($C->_fac($x)),'39916800'); -$x = $C->_new("12"); ok ($C->_str($C->_fac($x)),'479001600'); -$x = $C->_new("13"); ok ($C->_str($C->_fac($x)),'6227020800'); +$x = $C->_new("0"); is ($C->_str($C->_fac($x)),'1'); +$x = $C->_new("1"); is ($C->_str($C->_fac($x)),'1'); +$x = $C->_new("2"); is ($C->_str($C->_fac($x)),'2'); +$x = $C->_new("3"); is ($C->_str($C->_fac($x)),'6'); +$x = $C->_new("4"); is ($C->_str($C->_fac($x)),'24'); +$x = $C->_new("5"); is ($C->_str($C->_fac($x)),'120'); +$x = $C->_new("10"); is ($C->_str($C->_fac($x)),'3628800'); +$x = $C->_new("11"); is ($C->_str($C->_fac($x)),'39916800'); +$x = $C->_new("12"); is ($C->_str($C->_fac($x)),'479001600'); +$x = $C->_new("13"); is ($C->_str($C->_fac($x)),'6227020800'); # test that _fac modifes $x in place for small arguments -$x = $C->_new("3"); $C->_fac($x); ok ($C->_str($x),'6'); -$x = $C->_new("13"); $C->_fac($x); ok ($C->_str($x),'6227020800'); +$x = $C->_new("3"); $C->_fac($x); is ($C->_str($x),'6'); +$x = $C->_new("13"); $C->_fac($x); is ($C->_str($x),'6227020800'); ############################################################################## # _inc and _dec @@ -324,26 +319,26 @@ foreach (qw/1 11 121 1231 12341 1234561 12345671 123456781 1234567891/) { $x = $C->_new("$_"); $C->_inc($x); print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x),substr($_,0,length($_)-1) . '2'); - $C->_dec($x); ok ($C->_str($x),$_); + unless is ($C->_str($x),substr($_,0,length($_)-1) . '2'); + $C->_dec($x); is ($C->_str($x),$_); } foreach (qw/19 119 1219 12319 1234519 12345619 123456719 1234567819/) { $x = $C->_new("$_"); $C->_inc($x); print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x),substr($_,0,length($_)-2) . '20'); - $C->_dec($x); ok ($C->_str($x),$_); + unless is ($C->_str($x),substr($_,0,length($_)-2) . '20'); + $C->_dec($x); is ($C->_str($x),$_); } foreach (qw/999 9999 99999 9999999 99999999 999999999 9999999999 99999999999/) { $x = $C->_new("$_"); $C->_inc($x); print "# \$x = ",$C->_str($x),"\n" - unless ok ($C->_str($x), '1' . '0' x (length($_))); - $C->_dec($x); ok ($C->_str($x),$_); + unless is ($C->_str($x), '1' . '0' x (length($_))); + $C->_dec($x); is ($C->_str($x),$_); } -$x = $C->_new("1000"); $C->_inc($x); ok ($C->_str($x),'1001'); -$C->_dec($x); ok ($C->_str($x),'1000'); +$x = $C->_new("1000"); $C->_inc($x); is ($C->_str($x),'1001'); +$C->_dec($x); is ($C->_str($x),'1000'); my $BL; { @@ -353,71 +348,71 @@ my $BL; $x = '1' . '0' x $BL; $z = '1' . '0' x ($BL-1); $z .= '1'; -$x = $C->_new($x); $C->_inc($x); ok ($C->_str($x),$z); +$x = $C->_new($x); $C->_inc($x); is ($C->_str($x),$z); $x = '1' . '0' x $BL; $z = '9' x $BL; -$x = $C->_new($x); $C->_dec($x); ok ($C->_str($x),$z); +$x = $C->_new($x); $C->_dec($x); is ($C->_str($x),$z); # should not happen: -# $x = $C->_new("-2"); $y = $C->_new("4"); ok ($C->_acmp($x,$y),-1); +# $x = $C->_new("-2"); $y = $C->_new("4"); is ($C->_acmp($x,$y),-1); ############################################################################### # _mod $x = $C->_new("1000"); $y = $C->_new("3"); -ok ($C->_str(scalar $C->_mod($x,$y)),1); +is ($C->_str(scalar $C->_mod($x,$y)),1); $x = $C->_new("1000"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_mod($x,$y)),0); +is ($C->_str(scalar $C->_mod($x,$y)),0); # _and, _or, _xor $x = $C->_new("5"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_xor($x,$y)),7); +is ($C->_str(scalar $C->_xor($x,$y)),7); $x = $C->_new("5"); $y = $C->_new("2"); -ok ($C->_str(scalar $C->_or($x,$y)),7); +is ($C->_str(scalar $C->_or($x,$y)),7); $x = $C->_new("5"); $y = $C->_new("3"); -ok ($C->_str(scalar $C->_and($x,$y)),1); +is ($C->_str(scalar $C->_and($x,$y)),1); # _from_hex, _from_bin, _from_oct -ok ($C->_str( $C->_from_hex("0xFf")),255); -ok ($C->_str( $C->_from_bin("0b10101011")),160+11); -ok ($C->_str( $C->_from_oct("0100")), 8*8); -ok ($C->_str( $C->_from_oct("01000")), 8*8*8); -ok ($C->_str( $C->_from_oct("010001")), 8*8*8*8+1); -ok ($C->_str( $C->_from_oct("010007")), 8*8*8*8+7); +is ($C->_str( $C->_from_hex("0xFf")),255); +is ($C->_str( $C->_from_bin("0b10101011")),160+11); +is ($C->_str( $C->_from_oct("0100")), 8*8); +is ($C->_str( $C->_from_oct("01000")), 8*8*8); +is ($C->_str( $C->_from_oct("010001")), 8*8*8*8+1); +is ($C->_str( $C->_from_oct("010007")), 8*8*8*8+7); # _as_hex, _as_bin, as_oct -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("128")))), 128); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("128")))), 128); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("128")))), 128); +is ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("128")))), 128); +is ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("128")))), 128); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("128")))), 128); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456")))), 123456); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456789")))), "123456789"); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("1234567890123")))), "1234567890123"); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456")))), 123456); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("123456789")))), "123456789"); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("1234567890123")))), "1234567890123"); my $long = '123456789012345678901234567890'; -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new($long)))), $long); -ok ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("0")))), 0); -ok ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("0")))), 0); -ok ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("0")))), 0); -ok ($C->_as_hex( $C->_new("0")), '0x0'); -ok ($C->_as_bin( $C->_new("0")), '0b0'); -ok ($C->_as_oct( $C->_new("0")), '00'); -ok ($C->_as_hex( $C->_new("12")), '0xc'); -ok ($C->_as_bin( $C->_new("12")), '0b1100'); -ok ($C->_as_oct( $C->_new("64")), '0100'); +is ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new($long)))), $long); +is ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new($long)))), $long); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new($long)))), $long); +is ($C->_str( $C->_from_hex( $C->_as_hex( $C->_new("0")))), 0); +is ($C->_str( $C->_from_bin( $C->_as_bin( $C->_new("0")))), 0); +is ($C->_str( $C->_from_oct( $C->_as_oct( $C->_new("0")))), 0); +is ($C->_as_hex( $C->_new("0")), '0x0'); +is ($C->_as_bin( $C->_new("0")), '0b0'); +is ($C->_as_oct( $C->_new("0")), '00'); +is ($C->_as_hex( $C->_new("12")), '0xc'); +is ($C->_as_bin( $C->_new("12")), '0b1100'); +is ($C->_as_oct( $C->_new("64")), '0100'); # _1ex -ok ($C->_str($C->_1ex(0)), "1"); -ok ($C->_str($C->_1ex(1)), "10"); -ok ($C->_str($C->_1ex(2)), "100"); -ok ($C->_str($C->_1ex(12)), "1000000000000"); -ok ($C->_str($C->_1ex(16)), "10000000000000000"); +is ($C->_str($C->_1ex(0)), "1"); +is ($C->_str($C->_1ex(1)), "10"); +is ($C->_str($C->_1ex(2)), "100"); +is ($C->_str($C->_1ex(12)), "1000000000000"); +is ($C->_str($C->_1ex(16)), "10000000000000000"); # _check $x = $C->_new("123456789"); -ok ($C->_check($x),0); -ok ($C->_check(123),'123 is not a reference'); +is ($C->_check($x),0); +is ($C->_check(123),'123 is not a reference'); ############################################################################### # __strip_zeros @@ -425,32 +420,31 @@ ok ($C->_check(123),'123 is not a reference'); { no strict 'refs'; # correct empty arrays - $x = &{$C."::__strip_zeros"}([]); ok (@$x,1); ok ($x->[0],0); + $x = &{$C."::__strip_zeros"}([]); is (@$x,1); is ($x->[0],0); # don't strip single elements - $x = &{$C."::__strip_zeros"}([0]); ok (@$x,1); ok ($x->[0],0); - $x = &{$C."::__strip_zeros"}([1]); ok (@$x,1); ok ($x->[0],1); + $x = &{$C."::__strip_zeros"}([0]); is (@$x,1); is ($x->[0],0); + $x = &{$C."::__strip_zeros"}([1]); is (@$x,1); is ($x->[0],1); # don't strip non-zero elements $x = &{$C."::__strip_zeros"}([0,1]); - ok (@$x,2); ok ($x->[0],0); ok ($x->[1],1); + is (@$x,2); is ($x->[0],0); is ($x->[1],1); $x = &{$C."::__strip_zeros"}([0,1,2]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); + is (@$x,3); is ($x->[0],0); is ($x->[1],1); is ($x->[2],2); # but strip leading zeros $x = &{$C."::__strip_zeros"}([0,1,2,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); + is (@$x,3); is ($x->[0],0); is ($x->[1],1); is ($x->[2],2); $x = &{$C."::__strip_zeros"}([0,1,2,0,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); + is (@$x,3); is ($x->[0],0); is ($x->[1],1); is ($x->[2],2); $x = &{$C."::__strip_zeros"}([0,1,2,0,0,0]); - ok (@$x,3); ok ($x->[0],0); ok ($x->[1],1); ok ($x->[2],2); + is (@$x,3); is ($x->[0],0); is ($x->[1],1); is ($x->[2],2); # collapse multiple zeros $x = &{$C."::__strip_zeros"}([0,0,0,0]); - ok (@$x,1); ok ($x->[0],0); + is (@$x,1); is ($x->[0],0); } # done 1; - diff --git a/dist/Math-BigInt/t/bigintpm.inc b/dist/Math-BigInt/t/bigintpm.inc index 317e5ed8ab..3e80bd38cf 100644 --- a/dist/Math-BigInt/t/bigintpm.inc +++ b/dist/Math-BigInt/t/bigintpm.inc @@ -36,7 +36,7 @@ sub _swap ############################################################################## package main; -my $CALC = $class->config()->{lib}; ok ($CALC,$CL); +my $CALC = $class->config()->{lib}; is ($CALC,$CL); my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class); @@ -198,13 +198,13 @@ while (<DATA>) } if ($ans eq "") { - ok_undef ($ans1); + is ($ans1, undef); } else { # print "try: $try ans: $ans1 $ans\n"; - print "# Tried: '$try'\n" if !ok ($ans1, $ans); - ok (ref($ans),$expected_class) if $expected_class ne $class; + print "# Tried: '$try'\n" if !is ($ans1, $ans); + is (ref($ans),$expected_class) if $expected_class ne $class; } # check internal state of number objects is_valid($ans1,$f) if ref $ans1; @@ -217,18 +217,18 @@ for (my $i = 1; $i < 10; $i++) { push @a, $i; } -ok "@a", "1 2 3 4 5 6 7 8 9"; +is("@a", "1 2 3 4 5 6 7 8 9"); # test whether self-multiplication works correctly (result is 2**64) $try = "\$x = $class->new('4294967296');"; $try .= '$a = $x->bmul($x);'; $ans1 = eval $try; -print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64); +print "# Tried: '$try'\n" if !is ($ans1, $class->new(2) ** 64); # test self-pow $try = "\$x = $class->new(10);"; $try .= '$a = $x->bpow($x);'; $ans1 = eval $try; -print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10); +print "# Tried: '$try'\n" if !is ($ans1, $class->new(10) ** 10); ############################################################################### # test whether op destroys args or not (should better not) @@ -236,61 +236,61 @@ print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10); $x = $class->new(3); $y = $class->new(4); $z = $x & $y; -ok ($x,3); -ok ($y,4); -ok ($z,0); +is ($x,3); +is ($y,4); +is ($z,0); $z = $x | $y; -ok ($x,3); -ok ($y,4); -ok ($z,7); +is ($x,3); +is ($y,4); +is ($z,7); $x = $class->new(1); $y = $class->new(2); $z = $x | $y; -ok ($x,1); -ok ($y,2); -ok ($z,3); +is ($x,1); +is ($y,2); +is ($z,3); $x = $class->new(5); $y = $class->new(4); $z = $x ^ $y; -ok ($x,5); -ok ($y,4); -ok ($z,1); +is ($x,5); +is ($y,4); +is ($z,1); $x = $class->new(-5); $y = -$x; -ok ($x, -5); +is ($x, -5); $x = $class->new(-5); $y = abs($x); -ok ($x, -5); +is ($x, -5); $x = $class->new(8); $y = $class->new(-1); $z = $class->new(5033); my $u = $x->copy()->bmodpow($y,$z); -ok ($u,4404); -ok ($y,-1); -ok ($z,5033); - -$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5); -$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5); - -$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3); -$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3); -$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3); - -$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3); -$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3); -$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3); - -$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3); -$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3); -$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3); +is ($u,4404); +is ($y,-1); +is ($z,5033); + +$x = $class->new(-5); $y = -$x; is ($x,-5); is ($y,5); +$x = $class->new(-5); $y = $x->copy()->bneg(); is ($x,-5); is ($y,5); + +$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); is ($x,-15); is ($y,3); +$x = $class->new(-5); $y = $class->new(3); $x->badd($y); is ($x,-2); is ($y,3); +$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); is ($x,-8); is ($y,3); +$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); is ($x,-5); is ($y,3); +$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); is ($x,1); is ($y,3); + +$x = $class->new(5); $y = $class->new(3); $x->bmul($y); is ($x,15); is ($y,3); +$x = $class->new(5); $y = $class->new(3); $x->badd($y); is ($x,8); is ($y,3); +$x = $class->new(5); $y = $class->new(3); $x->bsub($y); is ($x,2); is ($y,3); +$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); is ($x,5); is ($y,3); +$x = $class->new(5); $y = $class->new(3); $x->bmod($y); is ($x,2); is ($y,3); + +$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); is ($x,-15); is ($y,-3); +$x = $class->new(5); $y = $class->new(-3); $x->badd($y); is ($x,2); is ($y,-3); +$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); is ($x,8); is ($y,-3); +$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); is ($x,-5); is ($y,-3); +$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); is ($x,-1); is ($y,-3); ############################################################################### # check whether overloading cmp works @@ -298,7 +298,7 @@ $try = "\$x = $class->new(0);"; $try .= "\$y = 10;"; $try .= "'false' if \$x ne \$y;"; $ans = eval $try; -print "# For '$try'\n" if (!ok "$ans" , "false" ); +print "# For '$try'\n" if (!is ("$ans" , "false") ); # we cant test for working cmpt with other objects here, we would need a dummy # object with stringify overload for this. see Math::String tests as example @@ -356,113 +356,113 @@ print "# For '$try'\n" if (!ok "$ans" , "ok" ); ############################################################################### # bool -$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') } -$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') } +$x = $class->new(1); if ($x) { is (1,1); } else { is ($x,'to be true') } +$x = $class->new(0); if (!$x) { is (1,1); } else { is ($x,'to be false') } ############################################################################### # objectify() @args = Math::BigInt::objectify(2,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); +is (scalar @args,3); # $class, 4, 5 +like ($args[0], qr/^Math::BigInt/); +is ($args[1],4); +is ($args[2],5); @args = Math::BigInt::objectify(0,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); +is (scalar @args,3); # $class, 4, 5 +like ($args[0], qr/^Math::BigInt/); +is ($args[1],4); +is ($args[2],5); @args = Math::BigInt::objectify(2,4,5); -ok (scalar @args,3); # $class, 4, 5 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); -ok ($args[2],5); +is (scalar @args,3); # $class, 4, 5 +like ($args[0], qr/^Math::BigInt/); +is ($args[1],4); +is ($args[2],5); @args = Math::BigInt::objectify(2,4,5,6,7); -ok (scalar @args,5); # $class, 4, 5, 6, 7 -ok ($args[0] =~ /^Math::BigInt/); -ok ($args[1],4); ok (ref($args[1]),$args[0]); -ok ($args[2],5); ok (ref($args[2]),$args[0]); -ok ($args[3],6); ok (ref($args[3]),''); -ok ($args[4],7); ok (ref($args[4]),''); +is (scalar @args,5); # $class, 4, 5, 6, 7 +like ($args[0], qr/^Math::BigInt/); +is ($args[1],4); is (ref($args[1]),$args[0]); +is ($args[2],5); is (ref($args[2]),$args[0]); +is ($args[3],6); is (ref($args[3]),''); +is ($args[4],7); is (ref($args[4]),''); @args = Math::BigInt::objectify(2,$class,4,5,6,7); -ok (scalar @args,5); # $class, 4, 5, 6, 7 -ok ($args[0],$class); -ok ($args[1],4); ok (ref($args[1]),$args[0]); -ok ($args[2],5); ok (ref($args[2]),$args[0]); -ok ($args[3],6); ok (ref($args[3]),''); -ok ($args[4],7); ok (ref($args[4]),''); +is (scalar @args,5); # $class, 4, 5, 6, 7 +is ($args[0],$class); +is ($args[1],4); is (ref($args[1]),$args[0]); +is ($args[2],5); is (ref($args[2]),$args[0]); +is ($args[3],6); is (ref($args[3]),''); +is ($args[4],7); is (ref($args[4]),''); ############################################################################### # test whether an opp calls objectify properly or not (or at least does what # it should do given non-objects, w/ or w/o objectify()) -ok ($class->new(123)->badd(123),246); -ok ($class->badd(123,321),444); -ok ($class->badd(123,$class->new(321)),444); +is ($class->new(123)->badd(123),246); +is ($class->badd(123,321),444); +is ($class->badd(123,$class->new(321)),444); -ok ($class->new(123)->bsub(122),1); -ok ($class->bsub(321,123),198); -ok ($class->bsub(321,$class->new(123)),198); +is ($class->new(123)->bsub(122),1); +is ($class->bsub(321,123),198); +is ($class->bsub(321,$class->new(123)),198); -ok ($class->new(123)->bmul(123),15129); -ok ($class->bmul(123,123),15129); -ok ($class->bmul(123,$class->new(123)),15129); +is ($class->new(123)->bmul(123),15129); +is ($class->bmul(123,123),15129); +is ($class->bmul(123,$class->new(123)),15129); -ok ($class->new(15129)->bdiv(123),123); -ok ($class->bdiv(15129,123),123); -ok ($class->bdiv(15129,$class->new(123)),123); +is ($class->new(15129)->bdiv(123),123); +is ($class->bdiv(15129,123),123); +is ($class->bdiv(15129,$class->new(123)),123); -ok ($class->new(15131)->bmod(123),2); -ok ($class->bmod(15131,123),2); -ok ($class->bmod(15131,$class->new(123)),2); +is ($class->new(15131)->bmod(123),2); +is ($class->bmod(15131,123),2); +is ($class->bmod(15131,$class->new(123)),2); -ok ($class->new(2)->bpow(16),65536); -ok ($class->bpow(2,16),65536); -ok ($class->bpow(2,$class->new(16)),65536); +is ($class->new(2)->bpow(16),65536); +is ($class->bpow(2,16),65536); +is ($class->bpow(2,$class->new(16)),65536); -ok ($class->new(2**15)->brsft(1),2**14); -ok ($class->brsft(2**15,1),2**14); -ok ($class->brsft(2**15,$class->new(1)),2**14); +is ($class->new(2**15)->brsft(1),2**14); +is ($class->brsft(2**15,1),2**14); +is ($class->brsft(2**15,$class->new(1)),2**14); -ok ($class->new(2**13)->blsft(1),2**14); -ok ($class->blsft(2**13,1),2**14); -ok ($class->blsft(2**13,$class->new(1)),2**14); +is ($class->new(2**13)->blsft(1),2**14); +is ($class->blsft(2**13,1),2**14); +is ($class->blsft(2**13,$class->new(1)),2**14); ############################################################################### # test for floating-point input (other tests in bnorm() below) $z = 1050000000000000; # may be int on systems with 64bit? -$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15 +$x = $class->new($z); is ($x->bsstr(),'105e+13'); # not 1.05e+15 $z = 1e+129; # definitely a float (may fail on UTS) # don't compare to $z, since some Perl versions stringify $z into something # like '1.e+129' or something equally ugly -$x = $class->new($z); ok ($x->bsstr(),'1e+129'); +$x = $class->new($z); is ($x->bsstr(),'1e+129'); ############################################################################### # test for whitespace inlcuding newlines to be handled correctly -# ok ($Math::BigInt::strict,1); # the default +# is ($Math::BigInt::strict,1); # the default foreach my $c ( qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/) { my $m = $class->new($c); - ok ($class->new("$c"),$m); - ok ($class->new(" $c"),$m); - ok ($class->new("$c "),$m); - ok ($class->new(" $c "),$m); - ok ($class->new("\n$c"),$m); - ok ($class->new("$c\n"),$m); - ok ($class->new("\n$c\n"),$m); - ok ($class->new(" \n$c\n"),$m); - ok ($class->new(" \n$c \n"),$m); - ok ($class->new(" \n$c\n "),$m); - ok ($class->new(" \n$c\n1"),'NaN'); - ok ($class->new("1 \n$c\n1"),'NaN'); + is ($class->new("$c"),$m); + is ($class->new(" $c"),$m); + is ($class->new("$c "),$m); + is ($class->new(" $c "),$m); + is ($class->new("\n$c"),$m); + is ($class->new("$c\n"),$m); + is ($class->new("\n$c\n"),$m); + is ($class->new(" \n$c\n"),$m); + is ($class->new(" \n$c \n"),$m); + is ($class->new(" \n$c\n "),$m); + is ($class->new(" \n$c\n1"),'NaN'); + is ($class->new("1 \n$c\n1"),'NaN'); } ############################################################################### @@ -471,28 +471,28 @@ foreach my $c ( # ((2^148)-1)/17 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17; -ok ($x,"20988936657440586486151264256610222593863921"); -ok ($x->length(),length "20988936657440586486151264256610222593863921"); +is ($x,"20988936657440586486151264256610222593863921"); +is ($x->length(),length "20988936657440586486151264256610222593863921"); # MM7 = 2^127-1 $x = $class->new(2); $x **= 127; $x--; -ok ($x,"170141183460469231731687303715884105727"); +is ($x,"170141183460469231731687303715884105727"); $x = $class->new('215960156869840440586892398248'); ($x,$y) = $x->length(); -ok ($x,30); ok ($y,0); +is ($x,30); is ($y,0); $x = $class->new('1_000_000_000_000'); ($x,$y) = $x->length(); -ok ($x,13); ok ($y,0); +is ($x,13); is ($y,0); # test <<=, >>= $x = $class->new('2'); my $y = $class->new('18'); -ok ($x <<= $y, 2 << 18); -ok ($x, 2 << 18); -ok ($x >>= $y, 2); -ok ($x, 2); +is ($x <<= $y, 2 << 18); +is ($x, 2 << 18); +is ($x >>= $y, 2); +is ($x, 2); # I am afraid the following is not yet possible due to slowness # Also, testing for 2 meg output is a bit hard ;) @@ -501,27 +501,27 @@ ok ($x, 2); # 593573509*2^332162+1 has exactly 1,000,000 digits # takes about 24 mins on 300 Mhz, so cannot be done yet ;) #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++; -#ok ($x->length(),1_000_000); +#is ($x->length(),1_000_000); ############################################################################### # inheritance and overriding of _swap $x = Math::Foo->new(5); $x = $x - 8; # 8 - 5 instead of 5-8 -ok ($x,3); -ok (ref($x),'Math::Foo'); +is ($x,3); +is (ref($x),'Math::Foo'); $x = Math::Foo->new(5); $x = 8 - $x; # 5 - 8 instead of 8 - 5 -ok ($x,-3); -ok (ref($x),'Math::Foo'); +is ($x,-3); +is (ref($x),'Math::Foo'); ############################################################################### # Test whether +inf eq inf # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things # like 1e100000 crash on some platforms. So simple test for the string 'inf' -$x = $class->new('+inf'); ok ($x,'inf'); +$x = $class->new('+inf'); is ($x,'inf'); ############################################################################### ############################################################################### @@ -539,44 +539,44 @@ my $MAX = $BASE; $BASE++; $x = $class->new($MAX); is_valid($x); # f.i. 9999 -$x += 1; ok ($x,$BASE); is_valid($x); # 10000 -$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again +$x += 1; is ($x,$BASE); is_valid($x); # 10000 +$x -= 1; is ($x,$MAX); is_valid($x); # 9999 again ############################################################################### # check numify -$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1); -$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1)); +$x = $class->new($BASE-1); is ($x->numify(),$BASE-1); +$x = $class->new(-($BASE-1)); is ($x->numify(),-($BASE-1)); # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...) -$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0); -$x = $class->new(-$BASE); ok ($x->numify(),-$BASE); +$x = $class->new($BASE); is ($x->numify()+0,$BASE+0); +$x = $class->new(-$BASE); is ($x->numify(),-$BASE); $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); -ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); +is ($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); ############################################################################### # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++; -if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); } +if ($x > $BASE) { is (1,1) } else { is ("$x < $BASE","$x > $BASE"); } $x = $class->new($BASE+3); $x++; -if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); } +if ($x > $BASE) { is (1,1) } else { is ("$x > $BASE","$x < $BASE"); } # test for +0 instead of int(): -$x = $class->new($MAX); ok ($x->length(), length($MAX)); +$x = $class->new($MAX); is ($x->length(), length($MAX)); ############################################################################### # test bug that $class->digit($string) did not work -ok ($class->digit(123,2),1); +is ($class->digit(123,2),1); ############################################################################### # bug in sub where number with at least 6 trailing zeros after any op failed $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z; -ok ($z, 100000); -ok ($x, 23456); +is ($z, 100000); +is ($x, 23456); ############################################################################### # bug in shortcut in mul() @@ -595,7 +595,7 @@ ok ($x, 23456); $y .= $i; $d = $i.$d; } $y .= $bl x (3*$bl-1) . $d . '0' x $bl; - ok ($x,$y); + is ($x,$y); ############################################################################# @@ -604,7 +604,7 @@ ok ($x, 23456); $x = '9' x $bl; $x = $class->new($x); # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001 - ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1'); + is ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1'); } ############################################################################### @@ -612,56 +612,56 @@ ok ($x, 23456); $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); -ok ($y,'0'); is_valid($y); # $y not '-0' +is ($y,'0'); is_valid($y); # $y not '-0' ############################################################################### # bug in $x->bmod($y) # if $x < 0 and $y > 0 -$x = $class->new('-629'); ok ($x->bmod(5033),4404); +$x = $class->new('-629'); is ($x->bmod(5033),4404); ############################################################################### # bone/binf etc as plain calls (Lite failed them) -ok ($class->bzero(),0); -ok ($class->bone(),1); -ok ($class->bone('+'),1); -ok ($class->bone('-'),-1); -ok ($class->bnan(),'NaN'); -ok ($class->binf(),'inf'); -ok ($class->binf('+'),'inf'); -ok ($class->binf('-'),'-inf'); -ok ($class->binf('-inf'),'-inf'); +is ($class->bzero(),0); +is ($class->bone(),1); +is ($class->bone('+'),1); +is ($class->bone('-'),-1); +is ($class->bnan(),'NaN'); +is ($class->binf(),'inf'); +is ($class->binf('+'),'inf'); +is ($class->binf('-'),'-inf'); +is ($class->binf('-inf'),'-inf'); ############################################################################### # is_one('-') -ok ($class->new(1)->is_one('-'),0); -ok ($class->new(-1)->is_one('-'),1); -ok ($class->new(1)->is_one(),1); -ok ($class->new(-1)->is_one(),0); +is ($class->new(1)->is_one('-'),0); +is ($class->new(-1)->is_one('-'),1); +is ($class->new(1)->is_one(),1); +is ($class->new(-1)->is_one(),0); ############################################################################### # [perl #30609] bug with $x -= $x not being 0, but 2*$x -$x = $class->new(3); $x -= $x; ok ($x, 0); -$x = $class->new(-3); $x -= $x; ok ($x, 0); -$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1); - -$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1); -$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1); -$x = $class->new(3); $x += $x; ok ($x, 6); -$x = $class->new(-3); $x += $x; ok ($x, -6); - -$x = $class->new(3); $x *= $x; ok ($x, 9); -$x = $class->new(-3); $x *= $x; ok ($x, 9); -$x = $class->new(3); $x /= $x; ok ($x, 1); -$x = $class->new(-3); $x /= $x; ok ($x, 1); -$x = $class->new(3); $x %= $x; ok ($x, 0); -$x = $class->new(-3); $x %= $x; ok ($x, 0); +$x = $class->new(3); $x -= $x; is ($x, 0); +$x = $class->new(-3); $x -= $x; is ($x, 0); +$x = $class->new('NaN'); $x -= $x; is ($x->is_nan(), 1); +$x = $class->new('inf'); $x -= $x; is ($x->is_nan(), 1); +$x = $class->new('-inf'); $x -= $x; is ($x->is_nan(), 1); + +$x = $class->new('NaN'); $x += $x; is ($x->is_nan(), 1); +$x = $class->new('inf'); $x += $x; is ($x->is_inf(), 1); +$x = $class->new('-inf'); $x += $x; is ($x->is_inf('-'), 1); +$x = $class->new(3); $x += $x; is ($x, 6); +$x = $class->new(-3); $x += $x; is ($x, -6); + +$x = $class->new(3); $x *= $x; is ($x, 9); +$x = $class->new(-3); $x *= $x; is ($x, 9); +$x = $class->new(3); $x /= $x; is ($x, 1); +$x = $class->new(-3); $x /= $x; is ($x, 1); +$x = $class->new(3); $x %= $x; is ($x, 0); +$x = $class->new(-3); $x %= $x; is ($x, 0); ############################################################################### # all tests done @@ -669,18 +669,6 @@ $x = $class->new(-3); $x %= $x; ok ($x, 0); 1; ############################################################################### -############################################################################### -# 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'); - } - -############################################################################### # sub to check validity of a BigInt internally, to ensure that no op leaves a # number object in an invalid state (f.i. "-0") @@ -705,9 +693,9 @@ sub is_valid } # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); + is (1,1), return if ($e eq '0'); - ok (1,$e." after op '$f'"); + is (1,$e." after op '$f'"); } __DATA__ diff --git a/dist/Math-BigInt/t/bigintpm.t b/dist/Math-BigInt/t/bigintpm.t index 1ec62e35af..6e381e5529 100644 --- a/dist/Math-BigInt/t/bigintpm.t +++ b/dist/Math-BigInt/t/bigintpm.t @@ -1,12 +1,7 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - plan tests => 3279 + 6; - } +use Test::More tests => 3279 + 6; use Math::BigInt lib => 'Calc'; @@ -18,22 +13,22 @@ $CL = "Math::BigInt::Calc"; # from_hex(), from_bin() and from_oct() tests my $x = Math::BigInt->from_hex('0xcafe'); -ok ($x, "51966", 'from_hex() works'); +is ($x, "51966", 'from_hex() works'); $x = Math::BigInt->from_hex('0xcafebabedead'); -ok ($x, "223195403574957", 'from_hex() works with long numbers'); +is ($x, "223195403574957", 'from_hex() works with long numbers'); $x = Math::BigInt->from_bin('0b1001'); -ok ($x, "9", 'from_bin() works'); +is ($x, "9", 'from_bin() works'); $x = Math::BigInt->from_bin('0b1001100110011001100110011001'); -ok ($x, "161061273", 'from_bin() works with big numbers'); +is ($x, "161061273", 'from_bin() works with big numbers'); $x = Math::BigInt->from_oct('0775'); -ok ($x, "509", 'from_oct() works'); +is ($x, "509", 'from_oct() works'); $x = Math::BigInt->from_oct('07777777777777711111111222222222'); -ok ($x, "9903520314281112085086151826", 'from_oct() works with big numbers'); +is ($x, "9903520314281112085086151826", 'from_oct() works with big numbers'); ############################################################################# # all the other tests diff --git a/dist/Math-BigInt/t/bigints.t b/dist/Math-BigInt/t/bigints.t index aab776c396..a61696877b 100644 --- a/dist/Math-BigInt/t/bigints.t +++ b/dist/Math-BigInt/t/bigints.t @@ -1,13 +1,9 @@ #!/usr/bin/perl -w use strict; -use Test; +use Test::More tests => 51; -BEGIN - { - unshift @INC, 't'; - plan tests => 51; - } +BEGIN { unshift @INC, 't'; } # testing of Math::BigInt:Scalar (used by the testsuite), # primarily for interface/api and not for the math functionality @@ -18,87 +14,86 @@ my $C = 'Math::BigInt::Scalar'; # pass classname to sub's # _new and _str my $x = $C->_new("123"); my $y = $C->_new("321"); -ok (ref($x),'SCALAR'); ok ($C->_str($x),123); ok ($C->_str($y),321); +is (ref($x),'SCALAR'); is ($C->_str($x),123); is ($C->_str($y),321); # _add, _sub, _mul, _div -ok ($C->_str($C->_add($x,$y)),444); -ok ($C->_str($C->_sub($x,$y)),123); -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($C->_div($x,$y)),123); +is ($C->_str($C->_add($x,$y)),444); +is ($C->_str($C->_sub($x,$y)),123); +is ($C->_str($C->_mul($x,$y)),39483); +is ($C->_str($C->_div($x,$y)),123); -ok ($C->_str($C->_mul($x,$y)),39483); -ok ($C->_str($x),39483); -ok ($C->_str($y),321); +is ($C->_str($C->_mul($x,$y)),39483); +is ($C->_str($x),39483); +is ($C->_str($y),321); my $z = $C->_new("2"); -ok ($C->_str($C->_add($x,$z)),39485); +is ($C->_str($C->_add($x,$z)),39485); my ($re,$rr) = $C->_div($x,$y); -ok ($C->_str($re),123); ok ($C->_str($rr),2); +is ($C->_str($re),123); is ($C->_str($rr),2); # is_zero, _is_one, _one, _zero -ok ($C->_is_zero($x),0); -ok ($C->_is_one($x),0); +is ($C->_is_zero($x),0); +is ($C->_is_one($x),0); -ok ($C->_is_one($C->_one()),1); ok ($C->_is_one($C->_zero()),0); -ok ($C->_is_zero($C->_zero()),1); ok ($C->_is_zero($C->_one()),0); +is ($C->_is_one($C->_one()),1); is ($C->_is_one($C->_zero()),0); +is ($C->_is_zero($C->_zero()),1); is ($C->_is_zero($C->_one()),0); # is_odd, is_even -ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero()),0); -ok ($C->_is_even($C->_one()),0); ok ($C->_is_even($C->_zero()),1); +is ($C->_is_odd($C->_one()),1); is ($C->_is_odd($C->_zero()),0); +is ($C->_is_even($C->_one()),0); is ($C->_is_even($C->_zero()),1); # _digit $x = $C->_new("123456789"); -ok ($C->_digit($x,0),9); -ok ($C->_digit($x,1),8); -ok ($C->_digit($x,2),7); -ok ($C->_digit($x,-1),1); -ok ($C->_digit($x,-2),2); -ok ($C->_digit($x,-3),3); +is ($C->_digit($x,0),9); +is ($C->_digit($x,1),8); +is ($C->_digit($x,2),7); +is ($C->_digit($x,-1),1); +is ($C->_digit($x,-2),2); +is ($C->_digit($x,-3),3); # _copy $x = $C->_new("12356"); -ok ($C->_str($C->_copy($x)),12356); +is ($C->_str($C->_copy($x)),12356); # _acmp $x = $C->_new("123456789"); $y = $C->_new("987654321"); -ok ($C->_acmp($x,$y),-1); -ok ($C->_acmp($y,$x),1); -ok ($C->_acmp($x,$x),0); -ok ($C->_acmp($y,$y),0); +is ($C->_acmp($x,$y),-1); +is ($C->_acmp($y,$x),1); +is ($C->_acmp($x,$x),0); +is ($C->_acmp($y,$y),0); # _div $x = $C->_new("3333"); $y = $C->_new("1111"); -ok ($C->_str( scalar $C->_div($x,$y)),3); +is ($C->_str( scalar $C->_div($x,$y)),3); $x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y); -ok ($C->_str($x),30); ok ($C->_str($y),3); +is ($C->_str($x),30); is ($C->_str($y),3); $x = $C->_new("123"); $y = $C->_new("1111"); -($x,$y) = $C->_div($x,$y); ok ($C->_str($x),0); ok ($C->_str($y),123); +($x,$y) = $C->_div($x,$y); is ($C->_str($x),0); is ($C->_str($y),123); # _num -$x = $C->_new("12345"); $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,12345); +$x = $C->_new("12345"); $x = $C->_num($x); is (ref($x)||'',''); is ($x,12345); # _len -$x = $C->_new("12345"); $x = $C->_len($x); ok (ref($x)||'',''); ok ($x,5); +$x = $C->_new("12345"); $x = $C->_len($x); is (ref($x)||'',''); is ($x,5); # _and, _or, _xor -$x = $C->_new("3"); $y = $C->_new("4"); ok ($C->_str( $C->_or($x,$y)),7); -$x = $C->_new("1"); $y = $C->_new("4"); ok ($C->_str( $C->_xor($x,$y)),5); -$x = $C->_new("7"); $y = $C->_new("3"); ok ($C->_str( $C->_and($x,$y)),3); +$x = $C->_new("3"); $y = $C->_new("4"); is ($C->_str( $C->_or($x,$y)),7); +$x = $C->_new("1"); $y = $C->_new("4"); is ($C->_str( $C->_xor($x,$y)),5); +$x = $C->_new("7"); $y = $C->_new("3"); is ($C->_str( $C->_and($x,$y)),3); # _pow -$x = $C->_new("2"); $y = $C->_new("4"); ok ($C->_str( $C->_pow($x,$y)),16); -$x = $C->_new("2"); $y = $C->_new("5"); ok ($C->_str( $C->_pow($x,$y)),32); -$x = $C->_new("3"); $y = $C->_new("3"); ok ($C->_str( $C->_pow($x,$y)),27); +$x = $C->_new("2"); $y = $C->_new("4"); is ($C->_str( $C->_pow($x,$y)),16); +$x = $C->_new("2"); $y = $C->_new("5"); is ($C->_str( $C->_pow($x,$y)),32); +$x = $C->_new("3"); $y = $C->_new("3"); is ($C->_str( $C->_pow($x,$y)),27); # _check $x = $C->_new("123456789"); -ok ($C->_check($x),0); -ok ($C->_check(123),'123 is not a reference'); +is ($C->_check($x),0); +is ($C->_check(123),'123 is not a reference'); # done 1; - diff --git a/dist/Math-BigInt/t/calling.t b/dist/Math-BigInt/t/calling.t index e6987aa62d..5fa25315af 100644 --- a/dist/Math-BigInt/t/calling.t +++ b/dist/Math-BigInt/t/calling.t @@ -3,14 +3,9 @@ # test calling conventions, and :constant overloading use strict; -use Test; +use Test::More tests => 160; -BEGIN - { - unshift @INC, 't'; - my $tests = 160; - plan tests => $tests; - } +BEGIN { unshift @INC, 't'; } package Math::BigInt::Test; @@ -60,7 +55,7 @@ while (<DATA>) $try = '' if $args[0] eq ''; # undef, no argument $try = "$class\->$func($try);"; $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, $ans); + print "# Tried: '$try'\n" if !is ($rc, $ans); } } @@ -73,28 +68,28 @@ $class = 'Math::BigInt'; #$try = "use $class ($version.'1');"; #$try .= ' $x = $class->new(123); $x = "$x";'; #eval $try; -#ok_undef ( $x ); # should result in error! +#is ( $x, undef ); # should result in error! # test whether fallback to calc works $try = "use $class ($version,'try','foo, bar , ');"; $try .= "$class\->config()->{lib};"; $ans = eval $try; -ok ( $ans =~ /^Math::BigInt::(Fast)?Calc\z/, 1); +like ( $ans, qr/^Math::BigInt::(Fast)?Calc\z/); # test whether constant works or not, also test for qw($version) # bgcd() is present in subclass, too $try = "use Math::BigInt ($version,'bgcd',':constant');"; $try .= ' $x = 2**150; bgcd($x); $x = "$x";'; $ans = eval $try; -ok ( $ans, "1427247692705959881058285969449495136382746624"); +is ( $ans, "1427247692705959881058285969449495136382746624"); # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc) $try = "use $class ($version,'lib','Scalar');"; $try .= ' $x = 2**10; $x = "$x";'; -$ans = eval $try; ok ( $ans, "1024"); +$ans = eval $try; is ( $ans, "1024"); $try = "use $class ($version,'lib','$class\::Scalar');"; $try .= ' $x = 2**10; $x = "$x";'; -$ans = eval $try; ok ( $ans, "1024"); +$ans = eval $try; is ( $ans, "1024"); # all done diff --git a/dist/Math-BigInt/t/const_mbf.t b/dist/Math-BigInt/t/const_mbf.t index a03d00bdf2..84f7a8cf99 100644 --- a/dist/Math-BigInt/t/const_mbf.t +++ b/dist/Math-BigInt/t/const_mbf.t @@ -3,17 +3,12 @@ # test BigFloat constants alone (w/o BigInt loading) use strict; -use Test; - -BEGIN - { - plan tests => 2; - } +use Test::More tests => 2; use Math::BigFloat ':constant'; -ok (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); +is (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); -# BigInt was not loadede with ':constant', so only floats are handled -ok (ref(2 ** 2),''); +# BigInt was not loaded with ':constant', so only floats are handled +is (ref(2 ** 2),''); diff --git a/dist/Math-BigInt/t/constant.t b/dist/Math-BigInt/t/constant.t index 094e3005dc..ad8afeed2d 100644 --- a/dist/Math-BigInt/t/constant.t +++ b/dist/Math-BigInt/t/constant.t @@ -1,41 +1,35 @@ #!/usr/bin/perl -w use strict; -use Test; - -BEGIN - { - plan tests => 7; - } +use Test::More tests => 7; use Math::BigInt ':constant'; -ok (2 ** 255,'57896044618658097711785492504343953926634992332820282019728792003956564819968'); +is (2 ** 255,'57896044618658097711785492504343953926634992332820282019728792003956564819968'); { no warnings 'portable'; # protect against "non-portable" warnings # hexadecimal constants -ok (0x123456789012345678901234567890, +is (0x123456789012345678901234567890, Math::BigInt->new('0x123456789012345678901234567890')); # binary constants -ok (0b01010100011001010110110001110011010010010110000101101101, +is (0b01010100011001010110110001110011010010010110000101101101, Math::BigInt->new( '0b01010100011001010110110001110011010010010110000101101101')); } use Math::BigFloat ':constant'; -ok (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); +is (1.0 / 3.0, '0.3333333333333333333333333333333333333333'); # stress-test Math::BigFloat->import() Math::BigFloat->import( qw/:constant/ ); -ok (1,1); +is (1,1); Math::BigFloat->import( qw/:constant upgrade Math::BigRat/ ); -ok (1,1); +is (1,1); Math::BigFloat->import( qw/upgrade Math::BigRat :constant/ ); -ok (1,1); +is (1,1); # all tests done - diff --git a/dist/Math-BigInt/t/downgrade.t b/dist/Math-BigInt/t/downgrade.t index 371d87c4fa..f6b011e5a0 100644 --- a/dist/Math-BigInt/t/downgrade.t +++ b/dist/Math-BigInt/t/downgrade.t @@ -1,12 +1,7 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - plan tests => 15; - } +use Test::More tests => 15; use Math::BigInt upgrade => 'Math::BigFloat'; use Math::BigFloat downgrade => 'Math::BigInt', upgrade => 'Math::BigInt'; @@ -18,33 +13,33 @@ $CL = "Math::BigInt::Calc"; $ECL = "Math::BigFloat"; # simplistic test for now -ok (Math::BigFloat->downgrade(),'Math::BigInt'); -ok (Math::BigFloat->upgrade(),'Math::BigInt'); +is (Math::BigFloat->downgrade(),'Math::BigInt'); +is (Math::BigFloat->upgrade(),'Math::BigInt'); # these downgrade -ok (ref(Math::BigFloat->new('inf')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-inf')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('NaN')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('0')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('1')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('10')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-10')),'Math::BigInt'); -ok (ref(Math::BigFloat->new('-10.0E1')),'Math::BigInt'); +is (ref(Math::BigFloat->new('inf')),'Math::BigInt'); +is (ref(Math::BigFloat->new('-inf')),'Math::BigInt'); +is (ref(Math::BigFloat->new('NaN')),'Math::BigInt'); +is (ref(Math::BigFloat->new('0')),'Math::BigInt'); +is (ref(Math::BigFloat->new('1')),'Math::BigInt'); +is (ref(Math::BigFloat->new('10')),'Math::BigInt'); +is (ref(Math::BigFloat->new('-10')),'Math::BigInt'); +is (ref(Math::BigFloat->new('-10.0E1')),'Math::BigInt'); # bug until v1.67: -ok (Math::BigFloat->new('0.2E0'), '0.2'); -ok (Math::BigFloat->new('0.2E1'), '2'); +is (Math::BigFloat->new('0.2E0'), '0.2'); +is (Math::BigFloat->new('0.2E1'), '2'); # until v1.67 resulted in 200: -ok (Math::BigFloat->new('0.2E2'), '20'); +is (Math::BigFloat->new('0.2E2'), '20'); # disable, otherwise it screws calculations Math::BigFloat->upgrade(undef); -ok (Math::BigFloat->upgrade()||'',''); +is (Math::BigFloat->upgrade()||'',''); Math::BigFloat->div_scale(20); # make it a bit faster my $x = Math::BigFloat->new(2); # downgrades # the following test upgrade for bsqrt() and also makes new() NOT downgrade # for the bpow() side -ok (Math::BigFloat->bpow('2','0.5'),$x->bsqrt()); +is (Math::BigFloat->bpow('2','0.5'),$x->bsqrt()); #require 'upgrade.inc'; # all tests here for sharing diff --git a/dist/Math-BigInt/t/isa.t b/dist/Math-BigInt/t/isa.t index 9d7e824a16..0bdf66fda2 100644 --- a/dist/Math-BigInt/t/isa.t +++ b/dist/Math-BigInt/t/isa.t @@ -1,13 +1,9 @@ #!/usr/bin/perl -w -use Test; use strict; +use Test::More tests => 7; -BEGIN - { - unshift @INC, 't'; - plan tests => 7; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt::Subclass; use Math::BigFloat::Subclass; @@ -19,21 +15,20 @@ $class = "Math::BigInt::Subclass"; $CL = "Math::BigInt::Calc"; # Check that a subclass is still considered a BigInt -ok ($class->new(123)->isa('Math::BigInt'),1); +isa_ok ($class->new(123), 'Math::BigInt'); # ditto for plain Math::BigInt -ok (Math::BigInt->new(123)->isa('Math::BigInt'),1); +isa_ok (Math::BigInt->new(123), 'Math::BigInt'); # But Math::BigFloats aren't -ok (Math::BigFloat->new(123)->isa('Math::BigInt') || 0,0); +isnt (Math::BigFloat->new(123)->isa('Math::BigInt'), 1); # see what happens if we feed a Math::BigFloat into new() $x = Math::BigInt->new(Math::BigFloat->new(123)); -ok (ref($x),'Math::BigInt'); -ok ($x->isa('Math::BigInt'),1); +is (ref($x),'Math::BigInt'); +isa_ok ($x, 'Math::BigInt'); # ditto for subclass $x = Math::BigInt->new(Math::BigFloat->new(123)); -ok (ref($x),'Math::BigInt'); -ok ($x->isa('Math::BigInt'),1); - +is (ref($x),'Math::BigInt'); +isa_ok ($x, 'Math::BigInt'); diff --git a/dist/Math-BigInt/t/mbimbf.inc b/dist/Math-BigInt/t/mbimbf.inc index b057eee3ec..59965c4a98 100644 --- a/dist/Math-BigInt/t/mbimbf.inc +++ b/dist/Math-BigInt/t/mbimbf.inc @@ -12,45 +12,45 @@ my ($x,$y,$z,$u,$rc); { no strict 'refs'; - ok_undef (${"$mbi\::accuracy"}); - ok_undef (${"$mbi\::precision"}); - ok_undef ($mbi->accuracy()); - ok_undef ($mbi->precision()); - ok (${"$mbi\::div_scale"},40); - ok (${"$mbi\::round_mode"},'even'); - ok ($mbi->round_mode(),'even'); - - ok_undef (${"$mbf\::accuracy"}); - ok_undef (${"$mbf\::precision"}); - ok_undef ($mbf->precision()); - ok_undef ($mbf->precision()); - ok (${"$mbf\::div_scale"},40); - ok (${"$mbf\::round_mode"},'even'); - ok ($mbf->round_mode(),'even'); + is (${"$mbi\::accuracy"}, undef); + is (${"$mbi\::precision"}, undef); + is ($mbi->accuracy(), undef); + is ($mbi->precision(), undef); + is (${"$mbi\::div_scale"},40); + is (${"$mbi\::round_mode"},'even'); + is ($mbi->round_mode(),'even'); + + is (${"$mbf\::accuracy"}, undef); + is (${"$mbf\::precision"}, undef); + is ($mbf->precision(), undef); + is ($mbf->precision(), undef); + is (${"$mbf\::div_scale"},40); + is (${"$mbf\::round_mode"},'even'); + is ($mbf->round_mode(),'even'); } # accessors foreach my $class ($mbi,$mbf) { - ok_undef ($class->accuracy()); - ok_undef ($class->precision()); - ok ($class->round_mode(),'even'); - ok ($class->div_scale(),40); + is ($class->accuracy(), undef); + is ($class->precision(), undef); + is ($class->round_mode(),'even'); + is ($class->div_scale(),40); - ok ($class->div_scale(20),20); - $class->div_scale(40); ok ($class->div_scale(),40); + is ($class->div_scale(20),20); + $class->div_scale(40); is ($class->div_scale(),40); - ok ($class->round_mode('odd'),'odd'); - $class->round_mode('even'); ok ($class->round_mode(),'even'); + is ($class->round_mode('odd'),'odd'); + $class->round_mode('even'); is ($class->round_mode(),'even'); - ok ($class->accuracy(2),2); - $class->accuracy(3); ok ($class->accuracy(),3); - ok_undef ($class->accuracy(undef)); - - ok ($class->precision(2),2); - ok ($class->precision(-2),-2); - $class->precision(3); ok ($class->precision(),3); - ok_undef ($class->precision(undef)); + is ($class->accuracy(2),2); + $class->accuracy(3); is ($class->accuracy(),3); + is ($class->accuracy(undef), undef); + + is ($class->precision(2),2); + is ($class->precision(-2),-2); + $class->precision(3); is ($class->precision(),3); + is ($class->precision(undef), undef); } { @@ -58,38 +58,38 @@ foreach my $class ($mbi,$mbf) # accuracy foreach (qw/5 42 -1 0/) { - ok (${"$mbf\::accuracy"} = $_,$_); - ok (${"$mbi\::accuracy"} = $_,$_); + is (${"$mbf\::accuracy"} = $_,$_); + is (${"$mbi\::accuracy"} = $_,$_); } - ok_undef (${"$mbf\::accuracy"} = undef); - ok_undef (${"$mbi\::accuracy"} = undef); + is (${"$mbf\::accuracy"} = undef, undef); + is (${"$mbi\::accuracy"} = undef, undef); # precision foreach (qw/5 42 -1 0/) { - ok (${"$mbf\::precision"} = $_,$_); - ok (${"$mbi\::precision"} = $_,$_); + is (${"$mbf\::precision"} = $_,$_); + is (${"$mbi\::precision"} = $_,$_); } - ok_undef (${"$mbf\::precision"} = undef); - ok_undef (${"$mbi\::precision"} = undef); + is (${"$mbf\::precision"} = undef, undef); + is (${"$mbi\::precision"} = undef, undef); # fallback foreach (qw/5 42 1/) { - ok (${"$mbf\::div_scale"} = $_,$_); - ok (${"$mbi\::div_scale"} = $_,$_); + is (${"$mbf\::div_scale"} = $_,$_); + is (${"$mbi\::div_scale"} = $_,$_); } # illegal values are possible for fallback due to no accessor # round_mode foreach (qw/odd even zero trunc +inf -inf/) { - ok (${"$mbf\::round_mode"} = $_,$_); - ok (${"$mbi\::round_mode"} = $_,$_); + is (${"$mbf\::round_mode"} = $_,$_); + is (${"$mbi\::round_mode"} = $_,$_); } ${"$mbf\::round_mode"} = 'zero'; - ok (${"$mbf\::round_mode"},'zero'); - ok (${"$mbi\::round_mode"},'-inf'); # from above + is (${"$mbf\::round_mode"},'zero'); + is (${"$mbi\::round_mode"},'-inf'); # from above # reset for further tests ${"$mbi\::accuracy"} = undef; @@ -99,20 +99,20 @@ foreach my $class ($mbi,$mbf) # local copies $x = $mbf->new('123.456'); -ok_undef ($x->accuracy()); -ok ($x->accuracy(5),5); -ok_undef ($x->accuracy(undef),undef); -ok_undef ($x->precision()); -ok ($x->precision(5),5); -ok_undef ($x->precision(undef),undef); +is ($x->accuracy(), undef); +is ($x->accuracy(5),5); +is ($x->accuracy(undef),undef, undef); +is ($x->precision(), undef); +is ($x->precision(5),5); +is ($x->precision(undef),undef, undef); { no strict 'refs'; # see if MBF changes MBIs values - ok (${"$mbi\::accuracy"} = 42,42); - ok (${"$mbf\::accuracy"} = 64,64); - ok (${"$mbi\::accuracy"},42); # should be still 42 - ok (${"$mbf\::accuracy"},64); # should be now 64 + is (${"$mbi\::accuracy"} = 42,42); + is (${"$mbf\::accuracy"} = 64,64); + is (${"$mbi\::accuracy"},42); # should be still 42 + is (${"$mbf\::accuracy"},64); # should be now 64 } ############################################################################### @@ -123,19 +123,19 @@ ok_undef ($x->precision(undef),undef); ${"$mbi\::accuracy"} = 4; ${"$mbi\::precision"} = undef; - ok ($mbi->new(123456),123500); # with A + is ($mbi->new(123456),123500); # with A ${"$mbi\::accuracy"} = undef; ${"$mbi\::precision"} = 3; - ok ($mbi->new(123456),123000); # with P + is ($mbi->new(123456),123000); # with P ${"$mbf\::accuracy"} = 4; ${"$mbf\::precision"} = undef; ${"$mbi\::precision"} = undef; - ok ($mbf->new('123.456'),'123.5'); # with A + is ($mbf->new('123.456'),'123.5'); # with A ${"$mbf\::accuracy"} = undef; ${"$mbf\::precision"} = -1; - ok ($mbf->new('123.456'),'123.5'); # with P from MBF, not MBI! + is ($mbf->new('123.456'),'123.5'); # with P from MBF, not MBI! ${"$mbf\::precision"} = undef; # reset } @@ -147,63 +147,63 @@ ok_undef ($x->precision(undef),undef); no strict 'refs'; ${"$mbi\::precision"} = undef; ${"$mbf\::precision"} = undef; ${"$mbi\::accuracy"} = 4; ${"$mbf\::accuracy"} = undef; - ok ($mbf->new('123.456'),'123.456'); + is ($mbf->new('123.456'),'123.456'); ${"$mbi\::accuracy"} = undef; # reset } ############################################################################### # see if setting accuracy/precision actually rounds the number -$x = $mbf->new('123.456'); $x->accuracy(4); ok ($x,'123.5'); -$x = $mbf->new('123.456'); $x->precision(-2); ok ($x,'123.46'); +$x = $mbf->new('123.456'); $x->accuracy(4); is ($x,'123.5'); +$x = $mbf->new('123.456'); $x->precision(-2); is ($x,'123.46'); -$x = $mbi->new(123456); $x->accuracy(4); ok ($x,123500); -$x = $mbi->new(123456); $x->precision(2); ok ($x,123500); +$x = $mbi->new(123456); $x->accuracy(4); is ($x,123500); +$x = $mbi->new(123456); $x->precision(2); is ($x,123500); ############################################################################### # test actual rounding via round() $x = $mbf->new('123.456'); -ok ($x->copy()->round(5),'123.46'); -ok ($x->copy()->round(4),'123.5'); -ok ($x->copy()->round(5,2),'NaN'); -ok ($x->copy()->round(undef,-2),'123.46'); -ok ($x->copy()->round(undef,2),120); +is ($x->copy()->round(5),'123.46'); +is ($x->copy()->round(4),'123.5'); +is ($x->copy()->round(5,2),'NaN'); +is ($x->copy()->round(undef,-2),'123.46'); +is ($x->copy()->round(undef,2),120); $x = $mbi->new('123'); -ok ($x->round(5,2),'NaN'); +is ($x->round(5,2),'NaN'); $x = $mbf->new('123.45000'); -ok ($x->copy()->round(undef,-1,'odd'),'123.5'); +is ($x->copy()->round(undef,-1,'odd'),'123.5'); # see if rounding is 'sticky' $x = $mbf->new('123.4567'); $y = $x->copy()->bround(); # no-op since nowhere A or P defined -ok ($y,123.4567); +is ($y,123.4567); $y = $x->copy()->round(5); -ok ($y->accuracy(),5); -ok_undef ($y->precision()); # A has precedence, so P still unset +is ($y->accuracy(),5); +is ($y->precision(), undef); # A has precedence, so P still unset $y = $x->copy()->round(undef,2); -ok ($y->precision(),2); -ok_undef ($y->accuracy()); # P has precedence, so A still unset +is ($y->precision(),2); +is ($y->accuracy(), undef); # P has precedence, so A still unset # see if setting A clears P and vice versa $x = $mbf->new('123.4567'); -ok ($x,'123.4567'); -ok ($x->accuracy(4),4); -ok ($x->precision(-2),-2); # clear A -ok_undef ($x->accuracy()); +is ($x,'123.4567'); +is ($x->accuracy(4),4); +is ($x->precision(-2),-2); # clear A +is ($x->accuracy(), undef); $x = $mbf->new('123.4567'); -ok ($x,'123.4567'); -ok ($x->precision(-2),-2); -ok ($x->accuracy(4),4); # clear P -ok_undef ($x->precision()); +is ($x,'123.4567'); +is ($x->precision(-2),-2); +is ($x->accuracy(4),4); # clear P +is ($x->precision(), undef); # does copy work? $x = $mbf->new(123.456); $x->accuracy(4); $x->precision(2); -$z = $x->copy(); ok_undef ($z->accuracy(),undef); ok ($z->precision(),2); +$z = $x->copy(); is ($z->accuracy(),undef); is ($z->precision(),2); # does $x->bdiv($y,d) work when $d > div_scale? $x = $mbf->new('0.008'); $x->accuracy(8); @@ -211,24 +211,24 @@ $x = $mbf->new('0.008'); $x->accuracy(8); for my $e ( 4, 8, 16, 32 ) { print "# Tried: $x->bdiv(3,$e)\n" - unless ok (scalar $x->copy()->bdiv(3,$e), '0.002' . ('6' x ($e-2)) . '7'); + unless is (scalar $x->copy()->bdiv(3,$e), '0.002' . ('6' x ($e-2)) . '7'); } # does accuracy()/precision work on zeros? foreach my $c ($mbi,$mbf) { - $x = $c->bzero(); $x->accuracy(5); ok ($x->{_a},5); - $x = $c->bzero(); $x->precision(5); ok ($x->{_p},5); - $x = $c->new(0); $x->accuracy(5); ok ($x->{_a},5); - $x = $c->new(0); $x->precision(5); ok ($x->{_p},5); + $x = $c->bzero(); $x->accuracy(5); is ($x->{_a},5); + $x = $c->bzero(); $x->precision(5); is ($x->{_p},5); + $x = $c->new(0); $x->accuracy(5); is ($x->{_a},5); + $x = $c->new(0); $x->precision(5); is ($x->{_p},5); - $x = $c->bzero(); $x->round(5); ok ($x->{_a},5); - $x = $c->bzero(); $x->round(undef,5); ok ($x->{_p},5); - $x = $c->new(0); $x->round(5); ok ($x->{_a},5); - $x = $c->new(0); $x->round(undef,5); ok ($x->{_p},5); + $x = $c->bzero(); $x->round(5); is ($x->{_a},5); + $x = $c->bzero(); $x->round(undef,5); is ($x->{_p},5); + $x = $c->new(0); $x->round(5); is ($x->{_a},5); + $x = $c->new(0); $x->round(undef,5); is ($x->{_p},5); # see if trying to increasing A in bzero() doesn't do something - $x = $c->bzero(); $x->{_a} = 3; $x->round(5); ok ($x->{_a},3); + $x = $c->bzero(); $x->{_a} = 3; $x->round(5); is ($x->{_a},3); } ############################################################################### @@ -240,37 +240,37 @@ foreach my $c ($mbi,$mbf) # ${"$c\::precision"} = undef; # reset # ${"$c\::accuracy"} = undef; # reset - ok ($c->new(123)->badd(123),246); - ok ($c->badd(123,321),444); - ok ($c->badd(123,$c->new(321)),444); + is ($c->new(123)->badd(123),246); + is ($c->badd(123,321),444); + is ($c->badd(123,$c->new(321)),444); - ok ($c->new(123)->bsub(122),1); - ok ($c->bsub(321,123),198); - ok ($c->bsub(321,$c->new(123)),198); + is ($c->new(123)->bsub(122),1); + is ($c->bsub(321,123),198); + is ($c->bsub(321,$c->new(123)),198); - ok ($c->new(123)->bmul(123),15129); - ok ($c->bmul(123,123),15129); - ok ($c->bmul(123,$c->new(123)),15129); + is ($c->new(123)->bmul(123),15129); + is ($c->bmul(123,123),15129); + is ($c->bmul(123,$c->new(123)),15129); -# ok ($c->new(15129)->bdiv(123),123); -# ok ($c->bdiv(15129,123),123); -# ok ($c->bdiv(15129,$c->new(123)),123); +# is ($c->new(15129)->bdiv(123),123); +# is ($c->bdiv(15129,123),123); +# is ($c->bdiv(15129,$c->new(123)),123); - ok ($c->new(15131)->bmod(123),2); - ok ($c->bmod(15131,123),2); - ok ($c->bmod(15131,$c->new(123)),2); + is ($c->new(15131)->bmod(123),2); + is ($c->bmod(15131,123),2); + is ($c->bmod(15131,$c->new(123)),2); - ok ($c->new(2)->bpow(16),65536); - ok ($c->bpow(2,16),65536); - ok ($c->bpow(2,$c->new(16)),65536); + is ($c->new(2)->bpow(16),65536); + is ($c->bpow(2,16),65536); + is ($c->bpow(2,$c->new(16)),65536); - ok ($c->new(2**15)->brsft(1),2**14); - ok ($c->brsft(2**15,1),2**14); - ok ($c->brsft(2**15,$c->new(1)),2**14); + is ($c->new(2**15)->brsft(1),2**14); + is ($c->brsft(2**15,1),2**14); + is ($c->brsft(2**15,$c->new(1)),2**14); - ok ($c->new(2**13)->blsft(1),2**14); - ok ($c->blsft(2**13,1),2**14); - ok ($c->blsft(2**13,$c->new(1)),2**14); + is ($c->new(2**13)->blsft(1),2**14); + is ($c->blsft(2**13,1),2**14); + is ($c->blsft(2**13,$c->new(1)),2**14); } ############################################################################### @@ -283,95 +283,95 @@ $y = $mbf->new('654.321'); $x->{_a} = 5; # $x->accuracy(5) would round $x straightaway $y->{_a} = 4; # $y->accuracy(4) would round $x straightaway -$z = $x + $y; ok ($z,'777.8'); -$z = $y - $x; ok ($z,'530.9'); -$z = $y * $x; ok ($z,'80780'); -$z = $x ** 2; ok ($z,'15241'); -$z = $x * $x; ok ($z,'15241'); +$z = $x + $y; is ($z,'777.8'); +$z = $y - $x; is ($z,'530.9'); +$z = $y * $x; is ($z,'80780'); +$z = $x ** 2; is ($z,'15241'); +$z = $x * $x; is ($z,'15241'); -# not: $z = -$x; ok ($z,'-123.46'); ok ($x,'123.456'); -$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; ok ($z,62); +# not: $z = -$x; is ($z,'-123.46'); is ($x,'123.456'); +$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; is ($z,62); $x = $mbf->new(123456); $x->{_a} = 4; -$z = $x->copy; $z++; ok ($z,123500); +$z = $x->copy; $z++; is ($z,123500); $x = $mbi->new(123456); $y = $mbi->new(654321); $x->{_a} = 5; # $x->accuracy(5) would round $x straightaway $y->{_a} = 4; # $y->accuracy(4) would round $x straightaway -$z = $x + $y; ok ($z,777800); -$z = $y - $x; ok ($z,530900); -$z = $y * $x; ok ($z,80780000000); -$z = $x ** 2; ok ($z,15241000000); -# not yet: $z = -$x; ok ($z,-123460); ok ($x,123456); -$z = $x->copy; $z++; ok ($z,123460); -$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; ok ($z,62000); +$z = $x + $y; is ($z,777800); +$z = $y - $x; is ($z,530900); +$z = $y * $x; is ($z,80780000000); +$z = $x ** 2; is ($z,15241000000); +# not yet: $z = -$x; is ($z,-123460); is ($x,123456); +$z = $x->copy; $z++; is ($z,123460); +$z = $x->copy(); $z->{_a} = 2; $z = $z / 2; is ($z,62000); $x = $mbi->new(123400); $x->{_a} = 4; -ok ($x->bnot(),-123400); # not -1234001 +is ($x->bnot(),-123400); # not -1234001 # both babs() and bneg() don't need to round, since the input will already # be rounded (either as $x or via new($string)), and they don't change the # value. The two tests below peek at this by using _a (illegally) directly -$x = $mbi->new(-123401); $x->{_a} = 4; ok ($x->babs(),123401); -$x = $mbi->new(-123401); $x->{_a} = 4; ok ($x->bneg(),123401); +$x = $mbi->new(-123401); $x->{_a} = 4; is ($x->babs(),123401); +$x = $mbi->new(-123401); $x->{_a} = 4; is ($x->bneg(),123401); # test fdiv rounding to A and R (bug in v1.48 and maybe earlier versions) $mbf->round_mode('even'); -$x = $mbf->new('740.7')->fdiv('6',4,undef,'zero'); ok ($x,'123.4'); +$x = $mbf->new('740.7')->fdiv('6',4,undef,'zero'); is ($x,'123.4'); $x = $mbi->new('123456'); $y = $mbi->new('123456'); $y->{_a} = 6; -ok ($x->bdiv($y),1); ok ($x->{_a},6); # carried over +is ($x->bdiv($y),1); is ($x->{_a},6); # carried over $x = $mbi->new('123456'); $y = $mbi->new('123456'); $x->{_a} = 6; -ok ($x->bdiv($y),1); ok ($x->{_a},6); # carried over +is ($x->bdiv($y),1); is ($x->{_a},6); # carried over $x = $mbi->new('123456'); $y = $mbi->new('223456'); $y->{_a} = 6; -ok ($x->bdiv($y),0); ok ($x->{_a},6); # carried over +is ($x->bdiv($y),0); is ($x->{_a},6); # carried over $x = $mbi->new('123456'); $y = $mbi->new('223456'); $x->{_a} = 6; -ok ($x->bdiv($y),0); ok ($x->{_a},6); # carried over +is ($x->bdiv($y),0); is ($x->{_a},6); # carried over ############################################################################### # test that bop(0) does the same than bop(undef) $x = $mbf->new('1234567890'); -ok ($x->copy()->bsqrt(0),$x->copy()->bsqrt(undef)); -ok ($x->copy->bsqrt(0),'35136.41828644462161665823116758077037159'); +is ($x->copy()->bsqrt(0),$x->copy()->bsqrt(undef)); +is ($x->copy->bsqrt(0),'35136.41828644462161665823116758077037159'); -ok_undef ($x->{_a}); +is ($x->{_a}, undef); # test that bsqrt() modifies $x and does not just return something else # (especially under BareCalc) $z = $x->bsqrt(); -ok ($z,$x); ok ($x,'35136.41828644462161665823116758077037159'); +is ($z,$x); is ($x,'35136.41828644462161665823116758077037159'); $x = $mbf->new('1.234567890123456789'); -ok ($x->copy()->bpow('0.5',0),$x->copy()->bpow('0.5',undef)); -ok ($x->copy()->bpow('0.5',0),$x->copy()->bsqrt(undef)); -ok ($x->copy()->bpow('2',0),'1.524157875323883675019051998750190521'); +is ($x->copy()->bpow('0.5',0),$x->copy()->bpow('0.5',undef)); +is ($x->copy()->bpow('0.5',0),$x->copy()->bsqrt(undef)); +is ($x->copy()->bpow('2',0),'1.524157875323883675019051998750190521'); ############################################################################### # test (also under Bare) that bfac() rounds at last step -ok ($mbi->new(12)->bfac(),'479001600'); -ok ($mbi->new(12)->bfac(2),'480000000'); -$x = $mbi->new(12); $x->accuracy(2); ok ($x->bfac(),'480000000'); -$x = $mbi->new(13); $x->accuracy(2); ok ($x->bfac(),'6200000000'); -$x = $mbi->new(13); $x->accuracy(3); ok ($x->bfac(),'6230000000'); -$x = $mbi->new(13); $x->accuracy(4); ok ($x->bfac(),'6227000000'); +is ($mbi->new(12)->bfac(),'479001600'); +is ($mbi->new(12)->bfac(2),'480000000'); +$x = $mbi->new(12); $x->accuracy(2); is ($x->bfac(),'480000000'); +$x = $mbi->new(13); $x->accuracy(2); is ($x->bfac(),'6200000000'); +$x = $mbi->new(13); $x->accuracy(3); is ($x->bfac(),'6230000000'); +$x = $mbi->new(13); $x->accuracy(4); is ($x->bfac(),'6227000000'); # this does 1,2,3...9,10,11,12...20 -$x = $mbi->new(20); $x->accuracy(1); ok ($x->bfac(),'2000000000000000000'); +$x = $mbi->new(20); $x->accuracy(1); is ($x->bfac(),'2000000000000000000'); ############################################################################### # test bsqrt) rounding to given A/P/R (bug prior to v1.60) -$x = $mbi->new('123456')->bsqrt(2,undef); ok ($x,'350'); # not 351 -$x = $mbi->new('3')->bsqrt(2,undef); ok ($x->accuracy(),2); +$x = $mbi->new('123456')->bsqrt(2,undef); is ($x,'350'); # not 351 +$x = $mbi->new('3')->bsqrt(2,undef); is ($x->accuracy(),2); $mbi->round_mode('even'); $x = $mbi->new('126025')->bsqrt(2,undef,'+inf'); -ok ($x,'360'); # not 355 nor 350 +is ($x,'360'); # not 355 nor 350 -$x = $mbi->new('126025')->bsqrt(undef,2); ok ($x,'400'); # not 355 +$x = $mbi->new('126025')->bsqrt(undef,2); is ($x,'400'); # not 355 ############################################################################### @@ -381,34 +381,32 @@ $x = $mbf->new(10); $u = $mbf->new(2.5); $y = $mbi->new(2); -$z = $x + $y; ok ($z,12); ok (ref($z),$mbf); -$z = $x / $y; ok ($z,5); ok (ref($z),$mbf); -$z = $u * $y; ok ($z,5); ok (ref($z),$mbf); +$z = $x + $y; is ($z,12); is (ref($z),$mbf); +$z = $x / $y; is ($z,5); is (ref($z),$mbf); +$z = $u * $y; is ($z,5); is (ref($z),$mbf); $y = $mbi->new(12345); -$z = $u->copy()->bmul($y,2,undef,'odd'); ok ($z,31000); -$z = $u->copy()->bmul($y,3,undef,'odd'); ok ($z,30900); -$z = $u->copy()->bmul($y,undef,0,'odd'); ok ($z,30863); -$z = $u->copy()->bmul($y,undef,1,'odd'); ok ($z,30863); -$z = $u->copy()->bmul($y,undef,2,'odd'); ok ($z,30860); -$z = $u->copy()->bmul($y,undef,3,'odd'); ok ($z,30900); -$z = $u->copy()->bmul($y,undef,-1,'odd'); ok ($z,30862.5); +$z = $u->copy()->bmul($y,2,undef,'odd'); is ($z,31000); +$z = $u->copy()->bmul($y,3,undef,'odd'); is ($z,30900); +$z = $u->copy()->bmul($y,undef,0,'odd'); is ($z,30863); +$z = $u->copy()->bmul($y,undef,1,'odd'); is ($z,30863); +$z = $u->copy()->bmul($y,undef,2,'odd'); is ($z,30860); +$z = $u->copy()->bmul($y,undef,3,'odd'); is ($z,30900); +$z = $u->copy()->bmul($y,undef,-1,'odd'); is ($z,30862.5); my $warn = ''; $SIG{__WARN__} = sub { $warn = shift; }; # these should no longer warn, even tho '3.17' is a NaN in BigInt (>= returns # now false, bug until v1.80) -$warn = ''; eval "\$z = 3.17 <= \$y"; ok ($z, ''); -print "# Got: '$warn'\n" unless -ok ($warn !~ /^Use of uninitialized value (\$y )?(in numeric le \(<=\) |)at/); -$warn = ''; eval "\$z = \$y >= 3.17"; ok ($z, ''); -print "# Got: '$warn'\n" unless -ok ($warn !~ /^Use of uninitialized value (\$y )?(in numeric ge \(>=\) |)at/); +$warn = ''; eval "\$z = 3.17 <= \$y"; is ($z, ''); +unlike ($warn, qr/^Use of uninitialized value (\$y )?(in numeric le \(<=\) |)at/); +$warn = ''; eval "\$z = \$y >= 3.17"; is ($z, ''); +unlike ($warn, qr/^Use of uninitialized value (\$y )?(in numeric ge \(>=\) |)at/); # XXX TODO breakage: -# $z = $y->copy()->bmul($u,2,0,'odd'); ok ($z,31000); -# $z = $y * $u; ok ($z,5); ok (ref($z),$mbi); -# $z = $y + $x; ok ($z,12); ok (ref($z),$mbi); -# $z = $y / $x; ok ($z,0); ok (ref($z),$mbi); +# $z = $y->copy()->bmul($u,2,0,'odd'); is ($z,31000); +# $z = $y * $u; is ($z,5); is (ref($z),$mbi); +# $z = $y + $x; is ($z,12); is (ref($z),$mbi); +# $z = $y / $x; is ($z,0); is (ref($z),$mbi); ############################################################################### # rounding in bdiv with fallback and already set A or P @@ -421,199 +419,199 @@ ok ($warn !~ /^Use of uninitialized value (\$y )?(in numeric ge \(>=\) |)at/); } $x = $mbf->new(10); $x->{_a} = 4; - ok ($x->bdiv(3),'3.333'); - ok ($x->{_a},4); # set's it since no fallback + is ($x->bdiv(3),'3.333'); + is ($x->{_a},4); # set's it since no fallback $x = $mbf->new(10); $x->{_a} = 4; $y = $mbf->new(3); -ok ($x->bdiv($y),'3.333'); -ok ($x->{_a},4); # set's it since no fallback +is ($x->bdiv($y),'3.333'); +is ($x->{_a},4); # set's it since no fallback # rounding to P of x $x = $mbf->new(10); $x->{_p} = -2; -ok ($x->bdiv(3),'3.33'); +is ($x->bdiv(3),'3.33'); # round in div with requested P $x = $mbf->new(10); -ok ($x->bdiv(3,undef,-2),'3.33'); +is ($x->bdiv(3,undef,-2),'3.33'); # round in div with requested P greater than fallback { no strict 'refs'; ${"$mbf\::div_scale"} = 5; $x = $mbf->new(10); - ok ($x->bdiv(3,undef,-8),'3.33333333'); + is ($x->bdiv(3,undef,-8),'3.33333333'); ${"$mbf\::div_scale"} = 40; } $x = $mbf->new(10); $y = $mbf->new(3); $y->{_a} = 4; -ok ($x->bdiv($y),'3.333'); -ok ($x->{_a},4); ok ($y->{_a},4); # set's it since no fallback -ok_undef ($x->{_p}); ok_undef ($y->{_p}); +is ($x->bdiv($y),'3.333'); +is ($x->{_a},4); is ($y->{_a},4); # set's it since no fallback +is ($x->{_p}, undef); is ($y->{_p}, undef); # rounding to P of y $x = $mbf->new(10); $y = $mbf->new(3); $y->{_p} = -2; -ok ($x->bdiv($y),'3.33'); -ok ($x->{_p},-2); - ok ($y->{_p},-2); -ok_undef ($x->{_a}); ok_undef ($y->{_a}); +is ($x->bdiv($y),'3.33'); +is ($x->{_p},-2); + is ($y->{_p},-2); +is ($x->{_a}, undef); is ($y->{_a}, undef); ############################################################################### # test whether bround(-n) fails in MBF (undocumented in MBI) eval { $x = $mbf->new(1); $x->bround(-2); }; -ok ($@ =~ /^bround\(\) needs positive accuracy/,1); +like ($@, qr/^bround\(\) needs positive accuracy/); # test whether rounding to higher accuracy is no-op $x = $mbf->new(1); $x->{_a} = 4; -ok ($x,'1.000'); +is ($x,'1.000'); $x->bround(6); # must be no-op -ok ($x->{_a},4); -ok ($x,'1.000'); +is ($x->{_a},4); +is ($x,'1.000'); $x = $mbi->new(1230); $x->{_a} = 3; -ok ($x,'1230'); +is ($x,'1230'); $x->bround(6); # must be no-op -ok ($x->{_a},3); -ok ($x,'1230'); +is ($x->{_a},3); +is ($x,'1230'); # bround(n) should set _a $x->bround(2); # smaller works -ok ($x,'1200'); -ok ($x->{_a},2); +is ($x,'1200'); +is ($x->{_a},2); # bround(-n) is undocumented and only used by MBF # bround(-n) should set _a $x = $mbi->new(12345); $x->bround(-1); -ok ($x,'12300'); -ok ($x->{_a},4); +is ($x,'12300'); +is ($x->{_a},4); # bround(-n) should set _a $x = $mbi->new(12345); $x->bround(-2); -ok ($x,'12000'); -ok ($x->{_a},3); +is ($x,'12000'); +is ($x->{_a},3); # bround(-n) should set _a $x = $mbi->new(12345); $x->{_a} = 5; $x->bround(-3); -ok ($x,'10000'); -ok ($x->{_a},2); +is ($x,'10000'); +is ($x->{_a},2); # bround(-n) should set _a $x = $mbi->new(12345); $x->{_a} = 5; $x->bround(-4); -ok ($x,'0'); -ok ($x->{_a},1); +is ($x,'0'); +is ($x->{_a},1); # bround(-n) should be noop if n too big $x = $mbi->new(12345); $x->bround(-5); -ok ($x,'0'); # scale to "big" => 0 -ok ($x->{_a},0); +is ($x,'0'); # scale to "big" => 0 +is ($x->{_a},0); # bround(-n) should be noop if n too big $x = $mbi->new(54321); $x->bround(-5); -ok ($x,'100000'); # used by MBF to round 0.0054321 at 0.0_6_00000 -ok ($x->{_a},0); +is ($x,'100000'); # used by MBF to round 0.0054321 at 0.0_6_00000 +is ($x->{_a},0); # bround(-n) should be noop if n too big $x = $mbi->new(54321); $x->{_a} = 5; $x->bround(-6); -ok ($x,'100000'); # no-op -ok ($x->{_a},0); +is ($x,'100000'); # no-op +is ($x->{_a},0); # bround(n) should set _a $x = $mbi->new(12345); $x->{_a} = 5; $x->bround(5); # must be no-op -ok ($x,'12345'); -ok ($x->{_a},5); +is ($x,'12345'); +is ($x->{_a},5); # bround(n) should set _a $x = $mbi->new(12345); $x->{_a} = 5; $x->bround(6); # must be no-op -ok ($x,'12345'); +is ($x,'12345'); -$x = $mbf->new('0.0061'); $x->bfround(-2); ok ($x,'0.01'); -$x = $mbf->new('0.004'); $x->bfround(-2); ok ($x,'0.00'); -$x = $mbf->new('0.005'); $x->bfround(-2); ok ($x,'0.00'); +$x = $mbf->new('0.0061'); $x->bfround(-2); is ($x,'0.01'); +$x = $mbf->new('0.004'); $x->bfround(-2); is ($x,'0.00'); +$x = $mbf->new('0.005'); $x->bfround(-2); is ($x,'0.00'); -$x = $mbf->new('12345'); $x->bfround(2); ok ($x,'12340'); -$x = $mbf->new('12340'); $x->bfround(2); ok ($x,'12340'); +$x = $mbf->new('12345'); $x->bfround(2); is ($x,'12340'); +$x = $mbf->new('12340'); $x->bfround(2); is ($x,'12340'); # MBI::bfround should clear A for negative P $x = $mbi->new('1234'); $x->accuracy(3); $x->bfround(-2); -ok_undef ($x->{_a}); +is ($x->{_a}, undef); # test that bfround() and bround() work with large numbers $x = $mbf->new(1)->bdiv(5678,undef,-63); -ok ($x, '0.000176118351532229658330398027474462839027826699542092286016203'); +is ($x, '0.000176118351532229658330398027474462839027826699542092286016203'); $x = $mbf->new(1)->bdiv(5678,undef,-90); -ok ($x, '0.000176118351532229658330398027474462839027826699542092286016202888340965128566396618527651'); +is ($x, '0.000176118351532229658330398027474462839027826699542092286016202888340965128566396618527651'); $x = $mbf->new(1)->bdiv(5678,80); -ok ($x, '0.00017611835153222965833039802747446283902782669954209228601620288834096512856639662'); +is ($x, '0.00017611835153222965833039802747446283902782669954209228601620288834096512856639662'); ############################################################################### # rounding with already set precision/accuracy $x = $mbf->new(1); $x->{_p} = -5; -ok ($x,'1.00000'); +is ($x,'1.00000'); # further rounding donw -ok ($x->bfround(-2),'1.00'); -ok ($x->{_p},-2); +is ($x->bfround(-2),'1.00'); +is ($x->{_p},-2); $x = $mbf->new(12345); $x->{_a} = 5; -ok ($x->bround(2),'12000'); -ok ($x->{_a},2); +is ($x->bround(2),'12000'); +is ($x->{_a},2); $x = $mbf->new('1.2345'); $x->{_a} = 5; -ok ($x->bround(2),'1.2'); -ok ($x->{_a},2); +is ($x->bround(2),'1.2'); +is ($x->{_a},2); # mantissa/exponent format and A/P $x = $mbf->new('12345.678'); $x->accuracy(4); -ok ($x,'12350'); ok ($x->{_a},4); ok_undef ($x->{_p}); +is ($x,'12350'); is ($x->{_a},4); is ($x->{_p}, undef); -#ok_undef ($x->{_m}->{_a}); ok_undef ($x->{_e}->{_a}); -#ok_undef ($x->{_m}->{_p}); ok_undef ($x->{_e}->{_p}); +#is ($x->{_m}->{_a}, undef); is ($x->{_e}->{_a}, undef); +#is ($x->{_m}->{_p}, undef); is ($x->{_e}->{_p}, undef); # check for no A/P in case of fallback # result $x = $mbf->new(100) / 3; -ok_undef ($x->{_a}); ok_undef ($x->{_p}); +is ($x->{_a}, undef); is ($x->{_p}, undef); # result & reminder $x = $mbf->new(100) / 3; ($x,$y) = $x->bdiv(3); -ok_undef ($x->{_a}); ok_undef ($x->{_p}); -ok_undef ($y->{_a}); ok_undef ($y->{_p}); +is ($x->{_a}, undef); is ($x->{_p}, undef); +is ($y->{_a}, undef); is ($y->{_p}, undef); ############################################################################### # math with two numbers with differen A and P $x = $mbf->new(12345); $x->accuracy(4); # '12340' $y = $mbf->new(12345); $y->accuracy(2); # '12000' -ok ($x+$y,24000); # 12340+12000=> 24340 => 24000 +is ($x+$y,24000); # 12340+12000=> 24340 => 24000 $x = $mbf->new(54321); $x->accuracy(4); # '12340' $y = $mbf->new(12345); $y->accuracy(3); # '12000' -ok ($x-$y,42000); # 54320+12300=> 42020 => 42000 +is ($x-$y,42000); # 54320+12300=> 42020 => 42000 $x = $mbf->new('1.2345'); $x->precision(-2); # '1.23' $y = $mbf->new('1.2345'); $y->precision(-4); # '1.2345' -ok ($x+$y,'2.46'); # 1.2345+1.2300=> 2.4645 => 2.46 +is ($x+$y,'2.46'); # 1.2345+1.2300=> 2.4645 => 2.46 ############################################################################### # round should find and use proper class #$x = Foo->new(); -#ok ($x->round($Foo::accuracy),'a' x $Foo::accuracy); -#ok ($x->round(undef,$Foo::precision),'p' x $Foo::precision); -#ok ($x->bfround($Foo::precision),'p' x $Foo::precision); -#ok ($x->bround($Foo::accuracy),'a' x $Foo::accuracy); +#is ($x->round($Foo::accuracy),'a' x $Foo::accuracy); +#is ($x->round(undef,$Foo::precision),'p' x $Foo::precision); +#is ($x->bfround($Foo::precision),'p' x $Foo::precision); +#is ($x->bround($Foo::accuracy),'a' x $Foo::accuracy); ############################################################################### # find out whether _find_round_parameters is doing what's it's supposed to do @@ -628,50 +626,50 @@ ok ($x+$y,'2.46'); # 1.2345+1.2300=> 2.4645 => 2.46 $x = $mbi->new(123); my @params = $x->_find_round_parameters(); -ok (scalar @params,1); # nothing to round +is (scalar @params,1); # nothing to round @params = $x->_find_round_parameters(1); -ok (scalar @params,4); # a=1 -ok ($params[0],$x); # self -ok ($params[1],1); # a -ok_undef ($params[2]); # p -ok ($params[3],'odd'); # round_mode +is (scalar @params,4); # a=1 +is ($params[0],$x); # self +is ($params[1],1); # a +is ($params[2], undef); # p +is ($params[3],'odd'); # round_mode @params = $x->_find_round_parameters(undef,2); -ok (scalar @params,4); # p=2 -ok ($params[0],$x); # self -ok_undef ($params[1]); # a -ok ($params[2],2); # p -ok ($params[3],'odd'); # round_mode +is (scalar @params,4); # p=2 +is ($params[0],$x); # self +is ($params[1], undef); # a +is ($params[2],2); # p +is ($params[3],'odd'); # round_mode eval { @params = $x->_find_round_parameters(undef,2,'foo'); }; -ok ($@ =~ /^Unknown round mode 'foo'/,1); +like ($@, qr/^Unknown round mode 'foo'/); @params = $x->_find_round_parameters(undef,2,'+inf'); -ok (scalar @params,4); # p=2 -ok ($params[0],$x); # self -ok_undef ($params[1]); # a -ok ($params[2],2); # p -ok ($params[3],'+inf'); # round_mode +is (scalar @params,4); # p=2 +is ($params[0],$x); # self +is ($params[1], undef); # a +is ($params[2],2); # p +is ($params[3],'+inf'); # round_mode @params = $x->_find_round_parameters(2,-2,'+inf'); -ok (scalar @params,1); # error, A and P defined -ok ($params[0],$x); # self +is (scalar @params,1); # error, A and P defined +is ($params[0],$x); # self { no strict 'refs'; ${"$mbi\::accuracy"} = 1; @params = $x->_find_round_parameters(undef,-2); - ok (scalar @params,1); # error, A and P defined - ok ($params[0],$x); # self - ok ($x->is_nan(),1); # and must be NaN + is (scalar @params,1); # error, A and P defined + is ($params[0],$x); # self + is ($x->is_nan(),1); # and must be NaN ${"$mbi\::accuracy"} = undef; ${"$mbi\::precision"} = 1; @params = $x->_find_round_parameters(1,undef); - ok (scalar @params,1); # error, A and P defined - ok ($params[0],$x); # self - ok ($x->is_nan(),1); # and must be NaN + is (scalar @params,1); # error, A and P defined + is ($params[0],$x); # self + is ($x->is_nan(),1); # and must be NaN ${"$mbi\::precision"} = undef; # reset } @@ -681,32 +679,32 @@ ok ($params[0],$x); # self foreach my $c ($mbi,$mbf) { - $x = $c->new(2)->bzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->bone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->binf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - $x = $c->new(2)->bnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); + $x = $c->new(2)->bzero(); is ($x->{_a}, undef); is ($x->{_p}, undef); + $x = $c->new(2)->bone(); is ($x->{_a}, undef); is ($x->{_p}, undef); + $x = $c->new(2)->binf(); is ($x->{_a}, undef); is ($x->{_p}, undef); + $x = $c->new(2)->bnan(); is ($x->{_a}, undef); is ($x->{_p}, undef); $x = $c->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->bnan(); - ok_undef ($x->{_a}); ok_undef ($x->{_p}); + is ($x->{_a}, undef); is ($x->{_p}, undef); $x = $c->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->binf(); - ok_undef ($x->{_a}); ok_undef ($x->{_p}); + is ($x->{_a}, undef); is ($x->{_p}, undef); - $x = $c->new(2,1); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1); ok_undef ($x->{_a}); ok ($x->{_p},1); + $x = $c->new(2,1); is ($x->{_a},1); is ($x->{_p}, undef); + $x = $c->new(2,undef,1); is ($x->{_a}, undef); is ($x->{_p},1); - $x = $c->new(2,1)->bzero(); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1)->bzero(); ok_undef ($x->{_a}); ok ($x->{_p},1); + $x = $c->new(2,1)->bzero(); is ($x->{_a},1); is ($x->{_p}, undef); + $x = $c->new(2,undef,1)->bzero(); is ($x->{_a}, undef); is ($x->{_p},1); - $x = $c->new(2,1)->bone(); ok ($x->{_a},1); ok_undef ($x->{_p}); - $x = $c->new(2,undef,1)->bone(); ok_undef ($x->{_a}); ok ($x->{_p},1); + $x = $c->new(2,1)->bone(); is ($x->{_a},1); is ($x->{_p}, undef); + $x = $c->new(2,undef,1)->bone(); is ($x->{_a}, undef); is ($x->{_p},1); - $x = $c->new(2); $x->bone('+',2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bone('+',undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); - $x = $c->new(2); $x->bone('-',2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bone('-',undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); + $x = $c->new(2); $x->bone('+',2,undef); is ($x->{_a},2); is ($x->{_p}, undef); + $x = $c->new(2); $x->bone('+',undef,2); is ($x->{_a}, undef); is ($x->{_p},2); + $x = $c->new(2); $x->bone('-',2,undef); is ($x->{_a},2); is ($x->{_p}, undef); + $x = $c->new(2); $x->bone('-',undef,2); is ($x->{_a}, undef); is ($x->{_p},2); - $x = $c->new(2); $x->bzero(2,undef); ok ($x->{_a},2); ok_undef ($x->{_p}); - $x = $c->new(2); $x->bzero(undef,2); ok_undef ($x->{_a}); ok ($x->{_p},2); + $x = $c->new(2); $x->bzero(2,undef); is ($x->{_a},2); is ($x->{_p}, undef); + $x = $c->new(2); $x->bzero(undef,2); is ($x->{_a}, undef); is ($x->{_p},2); } ############################################################################### @@ -715,13 +713,13 @@ foreach my $c ($mbi,$mbf) for my $c ($mbi,$mbf) { $c->accuracy(2); - $x = $c->bone(); ok ($x->accuracy(),2); - $x = $c->bzero(); ok ($x->accuracy(),2); + $x = $c->bone(); is ($x->accuracy(),2); + $x = $c->bzero(); is ($x->accuracy(),2); $c->accuracy(undef); $c->precision(-2); - $x = $c->bone(); ok ($x->precision(),-2); - $x = $c->bzero(); ok ($x->precision(),-2); + $x = $c->bone(); is ($x->precision(),-2); + $x = $c->bzero(); is ($x->precision(),-2); $c->precision(undef); } @@ -733,10 +731,10 @@ for my $c ($mbi,$mbf) no strict 'refs'; foreach my $c ($mbi,$mbf) { - ok ($c->new(123,4,-3),'NaN'); # with parameters + is ($c->new(123,4,-3),'NaN'); # with parameters ${"$c\::accuracy"} = 42; ${"$c\::precision"} = 2; - ok ($c->new(123),'NaN'); # with globals + is ($c->new(123),'NaN'); # with globals ${"$c\::accuracy"} = undef; ${"$c\::precision"} = undef; } @@ -752,7 +750,7 @@ foreach my $class ($mbi,$mbf) $try .= "my \$y = $class->new(12); \$y->precision(-3); "; $try .= "\$x->b$_(\$y);"; $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, 'NaN'); + print "# Tried: '$try'\n" if !is ($rc, 'NaN'); } } @@ -761,17 +759,17 @@ foreach (qw/new bsqrt/) { my $try = 'my $x = $mbi->$_(1234,5,-3); '; $rc = eval $try; - print "# Tried: '$try'\n" if !ok ($rc, 'NaN'); + print "# Tried: '$try'\n" if !is ($rc, 'NaN'); } # see if $x->bsub(0) and $x->badd(0) really round foreach my $class ($mbi,$mbf) { $x = $class->new(123); $class->accuracy(2); $x->bsub(0); - ok ($x,120); + is ($x,120); $class->accuracy(undef); $x = $class->new(123); $class->accuracy(2); $x->badd(0); - ok ($x,120); + is ($x,120); $class->accuracy(undef); } @@ -813,7 +811,7 @@ while (<DATA>) $ans =~ s/^0[xb]//; $ans = $mbi->new($ans)->bstr(); } - print "# Tried: '$try'\n" if !ok ($rc, $ans); + print "# Tried: '$try'\n" if !is ($rc, $ans); # check internal state of number objects is_valid($rc,$f) if ref $rc; @@ -825,7 +823,7 @@ while (<DATA>) # print "# Tried: '$try'\n"; if ($a ne '') { - if (!(ok ($x->{_a}, $a) && ok_undef ($x->{_p}))) + if (!(is ($x->{_a}, $a) && is ($x->{_p}, undef))) { print "# Check: A=$a and P=undef\n"; print "# Tried: '$try'\n"; @@ -833,7 +831,7 @@ while (<DATA>) } if ($p ne '') { - if (!(ok ($x->{_p}, $p) && ok_undef ($x->{_a}))) + if (!(is ($x->{_p}, $p) && is($x->{_a}, undef))) { print "# Check: A=undef and P=$p\n"; print "# Tried: '$try'\n"; @@ -845,20 +843,6 @@ while (<DATA>) 1; ############################################################################### -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return 1 if !defined $x; - ok ($x,'undef'); - print "# Called from ",join(' ',caller()),"\n"; - return 0; - } - -############################################################################### # sub to check validity of a BigInt internally, to ensure that no op leaves a # number object in an invalid state (f.i. "-0") @@ -878,9 +862,9 @@ sub is_valid $e = $CALC->_check($x->{value}) if $e eq '0'; # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); + is (1,1), return if ($e eq '0'); - ok (1,$e." after op '$f'"); + is (1,$e." after op '$f'"); } # format is: diff --git a/dist/Math-BigInt/t/mbimbf.t b/dist/Math-BigInt/t/mbimbf.t index 94b44b7211..b77e668385 100644 --- a/dist/Math-BigInt/t/mbimbf.t +++ b/dist/Math-BigInt/t/mbimbf.t @@ -4,13 +4,8 @@ # of classes use strict; -use Test; - -BEGIN - { - plan tests => 684 +use Test::More tests => 684 + 26; # own tests - } use Math::BigInt 1.70; use Math::BigFloat 1.43; @@ -29,46 +24,42 @@ require 't/mbimbf.inc'; Math::BigInt->round_mode('even'); # reset for tests Math::BigFloat->round_mode('even'); # reset for tests -ok ($Math::BigInt::rnd_mode,'even'); -ok ($Math::BigFloat::rnd_mode,'even'); +is ($Math::BigInt::rnd_mode,'even'); +is ($Math::BigFloat::rnd_mode,'even'); my $x = eval '$mbi->round_mode("huhmbi");'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbi' at/); +like ($@, qr/^Unknown round mode 'huhmbi' at/); $x = eval '$mbf->round_mode("huhmbf");'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbf' at/); +like ($@, qr/^Unknown round mode 'huhmbf' at/); # old way (now with test for validity) $x = eval '$Math::BigInt::rnd_mode = "huhmbi";'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbi' at/); +like ($@, qr/^Unknown round mode 'huhmbi' at/); $x = eval '$Math::BigFloat::rnd_mode = "huhmbf";'; -print "# Got '$@'\n" unless - ok ($@ =~ /^Unknown round mode 'huhmbf' at/); +like ($@, qr/^Unknown round mode 'huhmbf' at/); # see if accessor also changes old variable -$mbi->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); -$mbf->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); +$mbi->round_mode('odd'); is ($Math::BigInt::rnd_mode,'odd'); +$mbf->round_mode('odd'); is ($Math::BigInt::rnd_mode,'odd'); foreach my $class (qw/Math::BigInt Math::BigFloat/) { - ok ($class->accuracy(5),5); # set A - ok_undef ($class->precision()); # and now P must be cleared - ok ($class->precision(5),5); # set P - ok_undef ($class->accuracy()); # and now A must be cleared + is ($class->accuracy(5),5); # set A + is ($class->precision(), undef); # and now P must be cleared + is ($class->precision(5),5); # set P + is ($class->accuracy(), undef); # and now A must be cleared } foreach my $class (qw/Math::BigInt Math::BigFloat/) { $class->accuracy(42); my $x = $class->new(123); # $x gets A of 42, too! - ok ($x->accuracy(),42); # really? - ok ($x->accuracy(undef),42); # $x has no A, but the + is ($x->accuracy(),42); # really? + is ($x->accuracy(undef),42); # $x has no A, but the # global is still in effect for $x # so the return value of that operation should # be 42, not undef - ok ($x->accuracy(),42); # so $x should still have A = 42 + is ($x->accuracy(),42); # so $x should still have A = 42 $class->accuracy(undef); # reset for further tests $class->precision(undef); } @@ -76,12 +67,12 @@ foreach my $class (qw/Math::BigInt Math::BigFloat/) $x = Math::BigFloat->new(100); $x = $x->blog(Math::BigInt->new(10)); -ok ($x,2); +is ($x,2); # bug until v1.88 for sqrt() with enough digits for my $i (80,88,100) { $x = Math::BigFloat->new("1." . ("0" x $i) . "1"); $x = $x->bsqrt; - ok ($x, 1); + is ($x, 1); } diff --git a/dist/Math-BigInt/t/req_mbf1.t b/dist/Math-BigInt/t/req_mbf1.t index 9f6d1c7cec..ac8375c309 100644 --- a/dist/Math-BigInt/t/req_mbf1.t +++ b/dist/Math-BigInt/t/req_mbf1.t @@ -3,14 +3,8 @@ # check that simple requiring BigFloat and then bone() works use strict; -use Test; +use Test::More tests => 1; -BEGIN - { - plan tests => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->bone(); ok ($x,1); +require Math::BigFloat; my $x = Math::BigFloat->bone(); is ($x,1); # all tests done - diff --git a/dist/Math-BigInt/t/req_mbfa.t b/dist/Math-BigInt/t/req_mbfa.t index a57e66735d..eb4d5e10cb 100644 --- a/dist/Math-BigInt/t/req_mbfa.t +++ b/dist/Math-BigInt/t/req_mbfa.t @@ -3,14 +3,8 @@ # check that simple requiring BigFloat and then bnan() works use strict; -use Test; +use Test::More tests => 1; -BEGIN - { - plan tests => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->bnan(1); ok ($x,'NaN'); +require Math::BigFloat; my $x = Math::BigFloat->bnan(1); is ($x,'NaN'); # all tests done - diff --git a/dist/Math-BigInt/t/req_mbfi.t b/dist/Math-BigInt/t/req_mbfi.t index de976becd9..1ea5224c23 100644 --- a/dist/Math-BigInt/t/req_mbfi.t +++ b/dist/Math-BigInt/t/req_mbfi.t @@ -3,14 +3,8 @@ # check that simple requiring BigFloat and then binf() works use strict; -use Test; +use Test::More tests => 1; -BEGIN - { - plan tests => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->binf(); ok ($x,'inf'); +require Math::BigFloat; my $x = Math::BigFloat->binf(); is ($x,'inf'); # all tests done - diff --git a/dist/Math-BigInt/t/req_mbfn.t b/dist/Math-BigInt/t/req_mbfn.t index f12c18a9e6..1db441798a 100644 --- a/dist/Math-BigInt/t/req_mbfn.t +++ b/dist/Math-BigInt/t/req_mbfn.t @@ -3,14 +3,8 @@ # check that simple requiring BigFloat and then new() works use strict; -use Test; +use Test::More tests => 1; -BEGIN - { - plan tests => 1; - } - -require Math::BigFloat; my $x = Math::BigFloat->new(1); ++$x; ok ($x,2); +require Math::BigFloat; my $x = Math::BigFloat->new(1); ++$x; is ($x,2); # all tests done - diff --git a/dist/Math-BigInt/t/req_mbfw.t b/dist/Math-BigInt/t/req_mbfw.t index de52ac2b96..9b075c0a74 100644 --- a/dist/Math-BigInt/t/req_mbfw.t +++ b/dist/Math-BigInt/t/req_mbfw.t @@ -21,4 +21,3 @@ Math::BigFloat->import ( with => 'Math::BigInt::Subclass' ); like (Math::BigFloat->config()->{with}, qr/^Math::BigInt::(Fast)?Calc\z/, 'with ignored' ); # all tests done - diff --git a/dist/Math-BigInt/t/require.t b/dist/Math-BigInt/t/require.t index eab33b967b..66d9687a13 100644 --- a/dist/Math-BigInt/t/require.t +++ b/dist/Math-BigInt/t/require.t @@ -3,18 +3,13 @@ # check that simple requiring BigInt works use strict; -use Test; - -BEGIN - { - plan tests => 1; - } +use Test::More tests => 1; my ($x); require Math::BigInt; $x = Math::BigInt->new(1); ++$x; -ok ($x||'undef',2); +is ($x,2); # all tests done diff --git a/dist/Math-BigInt/t/sub_mbf.t b/dist/Math-BigInt/t/sub_mbf.t index d1f00e42d8..91b960c390 100644 --- a/dist/Math-BigInt/t/sub_mbf.t +++ b/dist/Math-BigInt/t/sub_mbf.t @@ -1,14 +1,11 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - unshift @INC, 't'; - plan tests => 2316 +use Test::More tests => 2316 + 6; # + our own tests - } + + +BEGIN { unshift @INC, 't'; } use Math::BigFloat::Subclass; @@ -21,16 +18,16 @@ require 't/bigfltpm.inc'; # perform same tests as bigfltpm ############################################################################### # Now do custom tests for Subclass itself my $ms = $class->new(23); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); +print "# Missing custom attribute \$ms->{_custom}" if !is (1, $ms->{_custom}); # Check that subclass is a Math::BigFloat, but not a Math::Bigint -ok ($ms->isa('Math::BigFloat'),1); -ok ($ms->isa('Math::BigInt') || 0,0); +isa_ok ($ms, 'Math::BigFloat'); +isnt ($ms->isa('Math::BigInt'), 1); use Math::BigFloat; my $bf = Math::BigFloat->new(23); # same as other $ms += $bf; -print "# Tried: \$ms += \$bf, got $ms" if !ok (46, $ms); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); -print "# Wrong class: ref(\$ms) was ".ref($ms) if !ok ($class, ref($ms)); +print "# Tried: \$ms += \$bf, got $ms" if !is (46, $ms); +print "# Missing custom attribute \$ms->{_custom}" if !is (1, $ms->{_custom}); +print "# Wrong class: ref(\$ms) was ".ref($ms) if !is ($class, ref($ms)); diff --git a/dist/Math-BigInt/t/sub_mbi.t b/dist/Math-BigInt/t/sub_mbi.t index 14db066490..c548cb3578 100644 --- a/dist/Math-BigInt/t/sub_mbi.t +++ b/dist/Math-BigInt/t/sub_mbi.t @@ -1,14 +1,10 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - unshift @INC, 't'; - plan tests => 3279 +use Test::More tests => 3279 + 5; # +5 own tests - } + +BEGIN { unshift @INC, 't'; } use Math::BigInt::Subclass; @@ -24,15 +20,15 @@ require 't/bigintpm.inc'; # perform same tests as bigintpm # Now do custom tests for Subclass itself my $ms = $class->new(23); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); +print "# Missing custom attribute \$ms->{_custom}" if !is (1, $ms->{_custom}); # Check that a subclass is still considered a BigInt -ok ($ms->isa('Math::BigInt'),1); +isa_ok ($ms, 'Math::BigInt'); use Math::BigInt; my $bi = Math::BigInt->new(23); # same as other $ms += $bi; -print "# Tried: \$ms += \$bi, got $ms" if !ok (46, $ms); -print "# Missing custom attribute \$ms->{_custom}" if !ok (1, $ms->{_custom}); -print "# Wrong class: ref(\$ms) was ".ref($ms) if !ok ($class, ref($ms)); +print "# Tried: \$ms += \$bi, got $ms" if !is (46, $ms); +print "# Missing custom attribute \$ms->{_custom}" if !is (1, $ms->{_custom}); +print "# Wrong class: ref(\$ms) was ".ref($ms) if !is ($class, ref($ms)); diff --git a/dist/Math-BigInt/t/sub_mif.t b/dist/Math-BigInt/t/sub_mif.t index ef59c0564f..3ccbca0403 100644 --- a/dist/Math-BigInt/t/sub_mif.t +++ b/dist/Math-BigInt/t/sub_mif.t @@ -4,13 +4,9 @@ # of classes use strict; -use Test; +use Test::More tests => 684; -BEGIN - { - unshift @INC, 't'; - plan tests => 684; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt::Subclass; use Math::BigFloat::Subclass; @@ -21,4 +17,3 @@ $mbi = 'Math::BigInt::Subclass'; $mbf = 'Math::BigFloat::Subclass'; require 't/mbimbf.inc'; - diff --git a/dist/Math-BigInt/t/upgrade.inc b/dist/Math-BigInt/t/upgrade.inc index 1160a21c6b..e623b731a2 100644 --- a/dist/Math-BigInt/t/upgrade.inc +++ b/dist/Math-BigInt/t/upgrade.inc @@ -46,7 +46,7 @@ sub _swap ############################################################################## package main; -my $CALC = $class->config()->{lib}; ok ($CALC,$CL); +my $CALC = $class->config()->{lib}; is ($CALC,$CL); my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class); @@ -197,16 +197,16 @@ while (<DATA>) } if ($ans eq "") { - ok_undef ($ans1); + is ($ans1, undef); } else { # print "try: $try ans: $ans1 $ans\n"; - print "# Tried: '$try'\n" if !ok ($ans1, $ans); + print "# Tried: '$try'\n" if !is ($ans1, $ans); if ($expected_class ne $class) { - ok (ref($ans1),$expected_class); # also checks that it really is ref! - ok ($Math::BigInt::upgrade,'Math::BigFloat'); # still okay? + is (ref($ans1),$expected_class); # also checks that it really is ref! + is ($Math::BigInt::upgrade,'Math::BigFloat'); # still okay? } } # check internal state of number objects @@ -217,26 +217,14 @@ close DATA; my $warn = ''; $SIG{__WARN__} = sub { $warn = shift; }; # these should not warn -$warn = ''; eval "\$z = 3.17 <= \$y"; ok ($z, 1); ok ($warn, ''); -$warn = ''; eval "\$z = \$y >= 3.17"; ok ($z, 1); ok ($warn, ''); +$warn = ''; eval "\$z = 3.17 <= \$y"; is ($z, 1); is ($warn, ''); +$warn = ''; eval "\$z = \$y >= 3.17"; is ($z, 1); is ($warn, ''); # all tests done 1; ############################################################################### -############################################################################### -# 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'); - } - -############################################################################### # sub to check validity of a BigInt internally, to ensure that no op leaves a # number object in an invalid state (f.i. "-0") @@ -258,9 +246,9 @@ sub is_valid #$e = $CALC->_check($x->{value}) if $e eq '0'; # test done, see if error did crop up - ok (1,1), return if ($e eq '0'); + is (1,1), return if ($e eq '0'); - ok (1,$e." after op '$f'"); + is (1,$e." after op '$f'"); } __DATA__ diff --git a/dist/Math-BigInt/t/upgrade.t b/dist/Math-BigInt/t/upgrade.t index a62189cfb2..630deb53dc 100644 --- a/dist/Math-BigInt/t/upgrade.t +++ b/dist/Math-BigInt/t/upgrade.t @@ -1,13 +1,8 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - plan tests => 2112 - + 2; # our own tests - } +use Test::More tests => 2112 + + 2; # our own tests use Math::BigInt upgrade => 'Math::BigFloat'; use Math::BigFloat; @@ -18,7 +13,7 @@ $class = "Math::BigInt"; $CL = "Math::BigInt::Calc"; $ECL = "Math::BigFloat"; -ok (Math::BigInt->upgrade(),'Math::BigFloat'); -ok (Math::BigInt->downgrade()||'',''); +is (Math::BigInt->upgrade(),'Math::BigFloat'); +is (Math::BigInt->downgrade()||'',''); require 't/upgrade.inc'; # all tests here for sharing diff --git a/dist/Math-BigInt/t/upgradef.t b/dist/Math-BigInt/t/upgradef.t index 58381cc05f..611d9fad27 100644 --- a/dist/Math-BigInt/t/upgradef.t +++ b/dist/Math-BigInt/t/upgradef.t @@ -1,13 +1,7 @@ #!/usr/bin/perl -w -use Test; use strict; - -BEGIN - { - plan tests => 0 - + 6; # our own tests - } +use Test::More tests => 6; ############################################################################### package Math::BigFloat::Test; @@ -48,14 +42,14 @@ $class = "Math::BigFloat"; $CL = "Math::BigInt::Calc"; $ECL = "Math::BigFloat::Test"; -ok (Math::BigFloat->upgrade(),$ECL); -ok (Math::BigFloat->downgrade()||'',''); +is (Math::BigFloat->upgrade(),$ECL); +is (Math::BigFloat->downgrade()||'',''); $x = $class->new(123); $y = $ECL->new(123); $z = $x->bmul($y); -ok (ref($z),$ECL); ok ($z,123); +is (ref($z),$ECL); is ($z,123); $x = $class->new(123); $y = $ECL->new(123); $z = $x->badd($y); -ok (ref($z),$ECL); ok ($z,321); +is (ref($z),$ECL); is ($z,321); diff --git a/dist/Math-BigInt/t/use.t b/dist/Math-BigInt/t/use.t index 4ece8fefc6..3d0b9e2cd6 100644 --- a/dist/Math-BigInt/t/use.t +++ b/dist/Math-BigInt/t/use.t @@ -6,20 +6,14 @@ # works. use strict; -use Test; - -BEGIN - { - plan tests => 1; - } +use Test::More tests => 1; my ($try,$ans,$x); use Math::BigInt(); $x = Math::BigInt->new(1); ++$x; -ok ($x||'undef',2); +is ($x,2); # all tests done 1; - diff --git a/dist/Math-BigInt/t/use_lib1.t b/dist/Math-BigInt/t/use_lib1.t index d31881451c..2045af1833 100644 --- a/dist/Math-BigInt/t/use_lib1.t +++ b/dist/Math-BigInt/t/use_lib1.t @@ -4,17 +4,12 @@ # all use_lib*.t should be equivalent use strict; -use Test; +use Test::More tests => 2; -BEGIN - { - unshift @INC, 't'; - plan tests => 2; - } +BEGIN { unshift @INC, 't'; } use Math::BigFloat lib => 'BareCalc'; -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); +is (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); +is (Math::BigFloat->new(123)->badd(123),246); diff --git a/dist/Math-BigInt/t/use_lib2.t b/dist/Math-BigInt/t/use_lib2.t index fbd0c9b0cc..23239e10e9 100644 --- a/dist/Math-BigInt/t/use_lib2.t +++ b/dist/Math-BigInt/t/use_lib2.t @@ -4,18 +4,13 @@ # all use_lib*.t should be equivalent use strict; -use Test; +use Test::More tests => 2; -BEGIN - { - unshift @INC, 't'; - plan tests => 2; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt; use Math::BigFloat lib => 'BareCalc'; -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); +is (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); +is (Math::BigFloat->new(123)->badd(123),246); diff --git a/dist/Math-BigInt/t/use_lib3.t b/dist/Math-BigInt/t/use_lib3.t index 503230b6e1..95263a0dcd 100644 --- a/dist/Math-BigInt/t/use_lib3.t +++ b/dist/Math-BigInt/t/use_lib3.t @@ -4,18 +4,13 @@ # all use_lib*.t should be equivalent use strict; -use Test; +use Test::More tests => 2; -BEGIN - { - unshift @INC, 't'; - plan tests => 2; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt lib => 'BareCalc'; use Math::BigFloat; -ok (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); - -ok (Math::BigFloat->new(123)->badd(123),246); +is (Math::BigInt->config()->{lib},'Math::BigInt::BareCalc'); +is (Math::BigFloat->new(123)->badd(123),246); diff --git a/dist/Math-BigInt/t/use_lib4.t b/dist/Math-BigInt/t/use_lib4.t index fbb1ffd979..a0d0564a35 100644 --- a/dist/Math-BigInt/t/use_lib4.t +++ b/dist/Math-BigInt/t/use_lib4.t @@ -5,18 +5,13 @@ # the former lib statement use strict; -use Test; +use Test::More tests => 2; -BEGIN - { - unshift @INC, 't'; - plan tests => 2; - } +BEGIN { unshift @INC, 't'; } use Math::BigInt lib => 'BareCalc'; use Math::BigFloat lib => 'Calc'; -ok (Math::BigInt->config()->{lib},'Math::BigInt::Calc'); - -ok (Math::BigFloat->new(123)->badd(123),246); +is (Math::BigInt->config()->{lib},'Math::BigInt::Calc'); +is (Math::BigFloat->new(123)->badd(123),246); diff --git a/dist/Math-BigInt/t/use_mbfw.t b/dist/Math-BigInt/t/use_mbfw.t index 43fcfab6e6..afa3733250 100644 --- a/dist/Math-BigInt/t/use_mbfw.t +++ b/dist/Math-BigInt/t/use_mbfw.t @@ -4,14 +4,9 @@ # broken in versions up to v1.63 use strict; -use Test; - -BEGIN - { - unshift @INC, 't'; - plan tests => 2; - } +use Test::More tests => 2; +BEGIN { unshift @INC, 't'; } # the replacement lib can handle the lib statement, but it could also ignore # it completely, for instance, when it is a 100% replacement for BigInt, but @@ -21,12 +16,11 @@ BEGIN use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'BareCalc'; -ok (Math::BigFloat->config()->{with}, 'Math::BigInt::BareCalc' ); +is (Math::BigFloat->config()->{with}, 'Math::BigInt::BareCalc' ); -# ok ($Math::BigInt::Subclass::lib, 'BareCalc' ); +# is ($Math::BigInt::Subclass::lib, 'BareCalc' ); # it never arrives here, but that is a design decision in SubClass -ok (Math::BigInt->config->{lib}, 'Math::BigInt::BareCalc' ); +is (Math::BigInt->config->{lib}, 'Math::BigInt::BareCalc' ); # all tests done - diff --git a/dist/Math-BigInt/t/with_sub.t b/dist/Math-BigInt/t/with_sub.t index b84069150e..16ebb20342 100644 --- a/dist/Math-BigInt/t/with_sub.t +++ b/dist/Math-BigInt/t/with_sub.t @@ -2,15 +2,8 @@ # Test use Math::BigFloat with => 'Math::BigInt::SomeSubclass'; -use Test; use strict; - -BEGIN - { - unshift @INC, 't'; - plan tests => 2316 - + 1; - } +use Test::More tests => 2316 + 1; use Math::BigFloat with => 'Math::BigInt::Subclass', lib => 'Calc'; @@ -19,6 +12,6 @@ $class = "Math::BigFloat"; $CL = "Math::BigInt::Calc"; # the with argument is ignored -ok (Math::BigFloat->config()->{with}, 'Math::BigInt::Calc'); +is (Math::BigFloat->config()->{with}, 'Math::BigInt::Calc'); require 't/bigfltpm.inc'; # all tests here for sharing |