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
CommitLineData
6853e8af 1# -*- mode: perl; -*-
7deec013
NB
2
3use strict;
4use warnings;
5
6853e8af
RL
6use Test::More tests => 8;
7
8my $class;
9
10BEGIN { $class = 'Math::BigRat'; }
11BEGIN { use_ok($class); }
7deec013
NB
12
13use Scalar::Util qw< refaddr >;
14
15# CPAN RT #132712.
16
6853e8af 17my $q1 = $class -> new("-1/2");
7deec013
NB
18my ($n, $d) = $q1 -> parts();
19
20my $n_orig = $n -> copy();
21my $d_orig = $d -> copy();
6853e8af 22my $q2 = $class -> new($n, $d);
7deec013
NB
23
24cmp_ok($n, "==", $n_orig,
25 "The value of the numerator hasn't changed");
26cmp_ok($d, "==", $d_orig,
27 "The value of the denominator hasn't changed");
28
29isnt(refaddr($n), refaddr($n_orig),
30 "The addresses of the numerators have changed");
31isnt(refaddr($d), refaddr($d_orig),
32 "The addresses of the denominators have changed");
6853e8af
RL
33
34# new()
35
36{
37 my $x = $class -> new();
38 subtest qq|\$x = $class -> new();|, => sub {
39 plan tests => 2;
40
41 is(ref($x), $class, "output arg is a $class");
42 is($x, "0", 'output arg has the right value');
43 };
44}
45
46# new("")
47
48{
49 my $x = $class -> new("");
50 subtest qq|\$x = $class -> new("");|, => sub {
51 plan tests => 2;
52
53 is(ref($x), $class, "output arg is a $class");
54 is($x, "NaN", 'output arg has the right value');
55 };
56}
57
58# new(undef)
59
60{
61 my $x = $class -> new(undef);
62 subtest qq|\$x = $class -> new(undef);|, => sub {
63 plan tests => 2;
64
65 is(ref($x), $class, "output arg is a $class");
66 is($x, "0", 'output arg has the right value');
67 };
68}