1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# -*- mode: perl; -*-
use strict;
use warnings;
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 = $class -> new("-1/2");
my ($n, $d) = $q1 -> parts();
my $n_orig = $n -> copy();
my $d_orig = $d -> copy();
my $q2 = $class -> new($n, $d);
cmp_ok($n, "==", $n_orig,
"The value of the numerator hasn't changed");
cmp_ok($d, "==", $d_orig,
"The value of the denominator hasn't changed");
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');
};
}
|