Commit | Line | Data |
---|---|---|
6853e8af | 1 | # -*- mode: perl; -*- |
7deec013 NB |
2 | |
3 | use strict; | |
4 | use warnings; | |
5 | ||
6853e8af RL |
6 | use Test::More tests => 8; |
7 | ||
8 | my $class; | |
9 | ||
10 | BEGIN { $class = 'Math::BigRat'; } | |
11 | BEGIN { use_ok($class); } | |
7deec013 NB |
12 | |
13 | use Scalar::Util qw< refaddr >; | |
14 | ||
15 | # CPAN RT #132712. | |
16 | ||
6853e8af | 17 | my $q1 = $class -> new("-1/2"); |
7deec013 NB |
18 | my ($n, $d) = $q1 -> parts(); |
19 | ||
20 | my $n_orig = $n -> copy(); | |
21 | my $d_orig = $d -> copy(); | |
6853e8af | 22 | my $q2 = $class -> new($n, $d); |
7deec013 NB |
23 | |
24 | cmp_ok($n, "==", $n_orig, | |
25 | "The value of the numerator hasn't changed"); | |
26 | cmp_ok($d, "==", $d_orig, | |
27 | "The value of the denominator hasn't changed"); | |
28 | ||
29 | isnt(refaddr($n), refaddr($n_orig), | |
30 | "The addresses of the numerators have changed"); | |
31 | isnt(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 | } |