diff options
Diffstat (limited to 'lib/Math/BigRat/t/bigrat.t')
-rwxr-xr-x | lib/Math/BigRat/t/bigrat.t | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/lib/Math/BigRat/t/bigrat.t b/lib/Math/BigRat/t/bigrat.t index 380f2e794f..9475426c7a 100755 --- a/lib/Math/BigRat/t/bigrat.t +++ b/lib/Math/BigRat/t/bigrat.t @@ -8,7 +8,7 @@ BEGIN $| = 1; chdir 't' if -d 't'; unshift @INC, '../lib'; # for running manually - plan tests => 36; + plan tests => 61; } # testing of Math::BigRat @@ -18,6 +18,14 @@ use Math::BigRat; my ($x,$y,$z); $x = Math::BigRat->new(1234); ok ($x,1234); +ok ($x->isa('Math::BigRat')); +ok (!$x->isa('Math::BigFloat')); +ok (!$x->isa('Math::BigInt')); + +############################################################################## +# new + +$x = Math::BigRat->new(1234); ok ($x,1234); $x = Math::BigRat->new('1234/1'); ok ($x,1234); $x = Math::BigRat->new('1234/2'); ok ($x,617); @@ -34,6 +42,33 @@ $x = Math::BigRat->new('inf'); ok ($x,'inf'); $x = Math::BigRat->new('-inf'); ok ($x,'-inf'); $x = Math::BigRat->new('1/'); ok ($x,'NaN'); +# input ala '1+1/3' isn't parsed ok yet +$x = Math::BigRat->new('1+1/3'); ok ($x,'NaN'); + +############################################################################## +# mixed arguments + +ok (Math::BigRat->new('3/7')->badd(1),'10/7'); +ok (Math::BigRat->new('3/10')->badd(1.1),'7/5'); +ok (Math::BigRat->new('3/7')->badd(Math::BigInt->new(1)),'10/7'); +ok (Math::BigRat->new('3/10')->badd(Math::BigFloat->new('1.1')),'7/5'); + +ok (Math::BigRat->new('3/7')->bsub(1),'-4/7'); +ok (Math::BigRat->new('3/10')->bsub(1.1),'-4/5'); +ok (Math::BigRat->new('3/7')->bsub(Math::BigInt->new(1)),'-4/7'); +ok (Math::BigRat->new('3/10')->bsub(Math::BigFloat->new('1.1')),'-4/5'); + +ok (Math::BigRat->new('3/7')->bmul(1),'3/7'); +ok (Math::BigRat->new('3/10')->bmul(1.1),'33/100'); +ok (Math::BigRat->new('3/7')->bmul(Math::BigInt->new(1)),'3/7'); +ok (Math::BigRat->new('3/10')->bmul(Math::BigFloat->new('1.1')),'33/100'); + +ok (Math::BigRat->new('3/7')->bdiv(1),'3/7'); +ok (Math::BigRat->new('3/10')->bdiv(1.1),'3/11'); +ok (Math::BigRat->new('3/7')->bdiv(Math::BigInt->new(1)),'3/7'); +ok (Math::BigRat->new('3/10')->bdiv(Math::BigFloat->new('1.1')),'3/11'); + +############################################################################## $x = Math::BigRat->new('1/4'); $y = Math::BigRat->new('1/3'); ok ($x + $y, '7/12'); ok ($x * $y, '1/12'); @@ -70,6 +105,18 @@ ok ($x->bacmp($y),1); $x = Math::BigRat->new('-124'); $y = Math::BigRat->new('-122'); ok ($x->bcmp($y),-1); +$x = Math::BigRat->new('3/7'); $y = Math::BigRat->new('5/7'); +ok ($x+$y,'8/7'); + +$x = Math::BigRat->new('3/7'); $y = Math::BigRat->new('5/7'); +ok ($x*$y,'15/49'); + +$x = Math::BigRat->new('3/5'); $y = Math::BigRat->new('5/7'); +ok ($x*$y,'3/7'); + +$x = Math::BigRat->new('3/5'); $y = Math::BigRat->new('5/7'); +ok ($x/$y,'21/25'); + $x = Math::BigRat->new('-144/9'); $x->bsqrt(); ok ($x,'NaN'); $x = Math::BigRat->new('144/9'); $x->bsqrt(); ok ($x,'4'); |