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 / binv-mbr.t
CommitLineData
6853e8af
RL
1# -*- mode: perl; -*-
2
3use strict;
4use warnings;
5
6use Test::More tests => 21;
7
8use Scalar::Util qw< refaddr >;
9
10my $class;
11
12BEGIN {
13 $class = 'Math::BigRat';
14 use_ok($class);
15}
16
17while (<DATA>) {
18 s/#.*$//; # remove comments
19 s/\s+$//; # remove trailing whitespace
20 next unless length; # skip empty lines
21
22 my ($xval, $yval) = split /:/;
23 my ($x, $got, @got);
24
25 for my $context_is_scalar (0, 1) {
26
27 my $test = qq|\$x = $class -> new("$xval");|;
28
29 $test .= $context_is_scalar
30 ? qq| \$got = \$x -> binv();|
31 : qq| \@got = \$x -> binv();|;
32
33 my $desc = "binv() in ";
34 $desc .= $context_is_scalar ? "scalar context" : "list context";
35
36 subtest $desc,
37 sub {
38 plan tests => $context_is_scalar ? 4 : 5;
39
40 eval $test;
41 is($@, "", "'$test' gives emtpy \$\@");
42
43 if ($context_is_scalar) {
44
45 # Check output.
46
47 is(ref($got), $class,
48 "'$test' output arg is a $class");
49
50 is($x -> bstr(), $yval,
51 "'$test' output arg has the right value");
52
53 is(refaddr($got), refaddr($x),
54 "'$test' output arg is the invocand");
55
56 } else {
57
58 # Check number of output arguments.
59
60 cmp_ok(scalar(@got), '==', 1,
61 "'$test' gives one output arg");
62
63 # Check output.
64
65 is(ref($got[0]), $class,
66 "'$test' output arg is a $class");
67
68 is($got[0] -> bstr(), $yval,
69 "'$test' output arg has the right value");
70
71 is(refaddr($got[0]), refaddr($x),
72 "'$test' output arg is the invocand");
73 }
74 };
75 }
76}
77
78__DATA__
79
80NaN:NaN
81inf:0
825:1/5
832:1/2
841:1
850:inf
86-1:-1
87-2:-1/2
88-5:-1/5
89-inf:0