This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update bignum, Math::BigInt, Math::BigInt::FastCalc, and Math::BigRat
[perl5.git] / cpan / Math-BigRat / t / new-mbr.t
index dad9942..24da7a8 100644 (file)
@@ -1,21 +1,25 @@
-#!perl
+# -*- mode: perl; -*-
 
 use strict;
 use warnings;
 
-use Test::More tests => 4;
-use Math::BigRat;
+use Test::More tests => 8;
+
+my $class;
+
+BEGIN { $class = 'Math::BigRat'; }
+BEGIN { use_ok($class); }
 
 use Scalar::Util qw< refaddr >;
 
 # CPAN RT #132712.
 
-my $q1 = Math::BigRat -> new("-1/2");
+my $q1 = $class -> new("-1/2");
 my ($n, $d) = $q1 -> parts();
 
 my $n_orig = $n -> copy();
 my $d_orig = $d -> copy();
-my $q2 = Math::BigRat -> new($n, $d);
+my $q2 = $class -> new($n, $d);
 
 cmp_ok($n, "==", $n_orig,
        "The value of the numerator hasn't changed");
@@ -26,3 +30,39 @@ isnt(refaddr($n), refaddr($n_orig),
      "The addresses of the numerators have changed");
 isnt(refaddr($d), refaddr($d_orig),
      "The addresses of the denominators have changed");
+
+# new()
+
+{
+    my $x = $class -> new();
+    subtest qq|\$x = $class -> new();|, => sub {
+        plan tests => 2;
+
+        is(ref($x), $class, "output arg is a $class");
+        is($x, "0", 'output arg has the right value');
+    };
+}
+
+# new("")
+
+{
+    my $x = $class -> new("");
+    subtest qq|\$x = $class -> new("");|, => sub {
+        plan tests => 2;
+
+        is(ref($x), $class, "output arg is a $class");
+        is($x, "NaN", 'output arg has the right value');
+    };
+}
+
+# new(undef)
+
+{
+    my $x = $class -> new(undef);
+    subtest qq|\$x = $class -> new(undef);|, => sub {
+        plan tests => 2;
+
+        is(ref($x), $class, "output arg is a $class");
+        is($x, "0", 'output arg has the right value');
+    };
+}