Commit | Line | Data |
---|---|---|
6853e8af RL |
1 | # -*- mode: perl; -*- |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use Test::More tests => 21; | |
7 | ||
8 | use Scalar::Util qw< refaddr >; | |
9 | ||
10 | my $class; | |
11 | ||
12 | BEGIN { | |
13 | $class = 'Math::BigRat'; | |
14 | use_ok($class); | |
15 | } | |
16 | ||
17 | while (<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 | ||
80 | NaN:NaN | |
81 | inf:0 | |
82 | 5:1/5 | |
83 | 2:1/2 | |
84 | 1:1 | |
85 | 0:inf | |
86 | -1:-1 | |
87 | -2:-1/2 | |
88 | -5:-1/5 | |
89 | -inf:0 |