This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync Math::BigRat with CPAN 0.2624
[perl5.git] / cpan / Math-BigRat / t / bigrat.t
index 41fcd2d..bd49ea1 100644 (file)
@@ -19,90 +19,92 @@ my $mbf = 'Math::BigFloat';
 my ($x, $y, $z);
 
 $x = Math::BigRat->new(1234);
-is($x, 1234);
+is($x, 1234, 'value of $x');
 isa_ok($x, 'Math::BigRat');
-is($x->isa('Math::BigFloat'), 0);
-is($x->isa('Math::BigInt'), 0);
+ok(!$x->isa('Math::BigInt'),
+   "An object of class '" . ref($x) . "' isn't a 'Math::BigInt'");
+ok(!$x->isa('Math::BigFloat'),
+   "An object of class '" . ref($x) . "' isn't a 'Math::BigFloat'");
 
 ##############################################################################
 # new and bnorm()
 
-foreach my $func (qw/ new bnorm /) {
-    $x = $mbr->$func(1234);
-    is($x, 1234, qq|\$x = $mbr->$func(1234)|);
+foreach my $method (qw/ new bnorm /) {
+    $x = $mbr->$method(1234);
+    is($x, 1234, qq|\$x = $mbr->$method(1234)|);
 
-    $x = $mbr->$func("1234/1");
-    is($x, 1234, qq|\$x = $mbr->$func("1234/1")|);
+    $x = $mbr->$method("1234/1");
+    is($x, 1234, qq|\$x = $mbr->$method("1234/1")|);
 
-    $x = $mbr->$func("1234/2");
-    is($x, 617, qq|\$x = $mbr->$func("1234/2")|);
+    $x = $mbr->$method("1234/2");
+    is($x, 617, qq|\$x = $mbr->$method("1234/2")|);
 
-    $x = $mbr->$func("100/1.0");
-    is($x, 100, qq|\$x = $mbr->$func("100/1.0")|);
+    $x = $mbr->$method("100/1.0");
+    is($x, 100, qq|\$x = $mbr->$method("100/1.0")|);
 
-    $x = $mbr->$func("10.0/1.0");
-    is($x, 10, qq|\$x = $mbr->$func("10.0/1.0")|);
+    $x = $mbr->$method("10.0/1.0");
+    is($x, 10, qq|\$x = $mbr->$method("10.0/1.0")|);
 
-    $x = $mbr->$func("0.1/10");
-    is($x, "1/100", qq|\$x = $mbr->$func("0.1/10")|);
+    $x = $mbr->$method("0.1/10");
+    is($x, "1/100", qq|\$x = $mbr->$method("0.1/10")|);
 
-    $x = $mbr->$func("0.1/0.1");
-    is($x, "1", qq|\$x = $mbr->$func("0.1/0.1")|);
+    $x = $mbr->$method("0.1/0.1");
+    is($x, "1", qq|\$x = $mbr->$method("0.1/0.1")|);
 
-    $x = $mbr->$func("1e2/10");
-    is($x, 10, qq|\$x = $mbr->$func("1e2/10")|);
+    $x = $mbr->$method("1e2/10");
+    is($x, 10, qq|\$x = $mbr->$method("1e2/10")|);
 
-    $x = $mbr->$func("5/1e2");
-    is($x, "1/20", qq|\$x = $mbr->$func("5/1e2")|);
+    $x = $mbr->$method("5/1e2");
+    is($x, "1/20", qq|\$x = $mbr->$method("5/1e2")|);
 
-    $x = $mbr->$func("1e2/1e1");
-    is($x, 10, qq|\$x = $mbr->$func("1e2/1e1")|);
+    $x = $mbr->$method("1e2/1e1");
+    is($x, 10, qq|\$x = $mbr->$method("1e2/1e1")|);
 
-    $x = $mbr->$func("1 / 3");
-    is($x, "1/3", qq|\$x = $mbr->$func("1 / 3")|);
+    $x = $mbr->$method("1 / 3");
+    is($x, "1/3", qq|\$x = $mbr->$method("1 / 3")|);
 
-    $x = $mbr->$func("-1 / 3");
-    is($x, "-1/3", qq|\$x = $mbr->$func("-1 / 3")|);
+    $x = $mbr->$method("-1 / 3");
+    is($x, "-1/3", qq|\$x = $mbr->$method("-1 / 3")|);
 
-    $x = $mbr->$func("NaN");
-    is($x, "NaN", qq|\$x = $mbr->$func("NaN")|);
+    $x = $mbr->$method("NaN");
+    is($x, "NaN", qq|\$x = $mbr->$method("NaN")|);
 
-    $x = $mbr->$func("inf");
-    is($x, "inf", qq|\$x = $mbr->$func("inf")|);
+    $x = $mbr->$method("inf");
+    is($x, "inf", qq|\$x = $mbr->$method("inf")|);
 
-    $x = $mbr->$func("-inf");
-    is($x, "-inf", qq|\$x = $mbr->$func("-inf")|);
+    $x = $mbr->$method("-inf");
+    is($x, "-inf", qq|\$x = $mbr->$method("-inf")|);
 
-    $x = $mbr->$func("1/");
-    is($x, "NaN", qq|\$x = $mbr->$func("1/")|);
+    $x = $mbr->$method("1/");
+    is($x, "NaN", qq|\$x = $mbr->$method("1/")|);
 
-    $x = $mbr->$func("0x7e");
-    is($x, 126, qq|\$x = $mbr->$func("0x7e")|);
+    $x = $mbr->$method("0x7e");
+    is($x, 126, qq|\$x = $mbr->$method("0x7e")|);
 
     # input ala "1+1/3" isn"t parsed ok yet
-    $x = $mbr->$func("1+1/3");
-    is($x, "NaN", qq|\$x = $mbr->$func("1+1/3")|);
+    $x = $mbr->$method("1+1/3");
+    is($x, "NaN", qq|\$x = $mbr->$method("1+1/3")|);
 
-    $x = $mbr->$func("1/1.2");
-    is($x, "5/6", qq|\$x = $mbr->$func("1/1.2")|);
+    $x = $mbr->$method("1/1.2");
+    is($x, "5/6", qq|\$x = $mbr->$method("1/1.2")|);
 
-    $x = $mbr->$func("1.3/1.2");
-    is($x, "13/12", qq|\$x = $mbr->$func("1.3/1.2")|);
+    $x = $mbr->$method("1.3/1.2");
+    is($x, "13/12", qq|\$x = $mbr->$method("1.3/1.2")|);
 
-    $x = $mbr->$func("1.2/1");
-    is($x, "6/5", qq|\$x = $mbr->$func("1.2/1")|);
+    $x = $mbr->$method("1.2/1");
+    is($x, "6/5", qq|\$x = $mbr->$method("1.2/1")|);
 
     ############################################################################
     # other classes as input
 
-    $x = $mbr->$func($mbi->new(1231));
-    is($x, "1231", qq|\$x = $mbr->$func($mbi->new(1231))|);
+    $x = $mbr->$method($mbi->new(1231));
+    is($x, "1231", qq|\$x = $mbr->$method($mbi->new(1231))|);
 
-    $x = $mbr->$func($mbf->new(1232));
-    is($x, "1232", qq|\$x = $mbr->$func($mbf->new(1232))|);
+    $x = $mbr->$method($mbf->new(1232));
+    is($x, "1232", qq|\$x = $mbr->$method($mbf->new(1232))|);
 
-    $x = $mbr->$func($mbf->new(1232.3));
-    is($x, "12323/10", qq|\$x = $mbr->$func($mbf->new(1232.3))|);
+    $x = $mbr->$method($mbf->new(1232.3));
+    is($x, "12323/10", qq|\$x = $mbr->$method($mbf->new(1232.3))|);
 }
 
 my $n = 'numerator';
@@ -322,14 +324,19 @@ is($x, 'NaN');
 ##############################################################################
 # binc/bdec
 
+note("binc()");
 $x = $mbr->new('3/2');
 is($x->binc(), '5/2');
+
+note("bdec()");
+
 $x = $mbr->new('15/6');
 is($x->bdec(), '3/2');
 
 ##############################################################################
-# bfloor/bceil
+# bfloor
 
+note("bfloor()");
 $x = $mbr->new('-7/7');
 is($x->$n(), '-1');
 is($x->$d(), '1');
@@ -426,6 +433,8 @@ subtest qq|$mbr -> new("NaN") -> numify()| => sub {
 ##############################################################################
 # as_hex(), as_bin(), as_oct()
 
+note("as_hex(), as_bin(), as_oct()");
+
 $x = $mbr->new('8/8');
 is($x->as_hex(), '0x1');
 is($x->as_bin(), '0b1');
@@ -439,32 +448,36 @@ is($x->as_oct(), '012');
 ##############################################################################
 # broot(), blog(), bmodpow() and bmodinv()
 
+note("broot(), blog(), bmodpow(), bmodinv()");
+
 $x = $mbr->new(2) ** 32;
 $y = $mbr->new(4);
 $z = $mbr->new(3);
 
 is($x->copy()->broot($y), 2 ** 8);
-is(ref($x->copy()->broot($y)), $mbr);
+is(ref($x->copy()->broot($y)), $mbr, "\$x is a $mbr");
 
 is($x->copy()->bmodpow($y, $z), 1);
-is(ref($x->copy()->bmodpow($y, $z)), $mbr);
+is(ref($x->copy()->bmodpow($y, $z)), $mbr, "\$x is a $mbr");
 
 $x = $mbr->new(8);
 $y = $mbr->new(5033);
 $z = $mbr->new(4404);
 
 is($x->copy()->bmodinv($y), $z);
-is(ref($x->copy()->bmodinv($y)), $mbr);
+is(ref($x->copy()->bmodinv($y)), $mbr, "\$x is a $mbr");
 
 # square root with exact result
 $x = $mbr->new('1.44');
 is($x->copy()->broot(2), '6/5');
-is(ref($x->copy()->broot(2)), $mbr);
+is(ref($x->copy()->broot(2)), $mbr, "\$x is a $mbr");
 
 # log with exact result
 $x = $mbr->new('256.1');
-is($x->copy()->blog(2), '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000');
-is(ref($x->copy()->blog(2)), $mbr);
+is($x->copy()->blog(2),
+   '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000',
+   "\$x = $mbr->new('256.1')->blog(2)");
+is(ref($x->copy()->blog(2)), $mbr, "\$x is a $mbr");
 
 $x = $mbr->new(144);
 is($x->copy()->broot('2'), 12, 'v/144 = 12');
@@ -475,6 +488,8 @@ is($x->copy()->broot('3'), 12, '(12*12*12) ** 1/3 = 12');
 ##############################################################################
 # from_hex(), from_bin(), from_oct()
 
+note("from_hex(), from_bin(), from_oct()");
+
 $x = Math::BigRat->from_hex('0x100');
 is($x, '256', 'from_hex');