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 / dparts-mbr.t
CommitLineData
6853e8af
RL
1# -*- mode: perl; -*-
2
3use strict;
4use warnings;
5
6use Test::More tests => 17;
7
8my $class;
9
10BEGIN {
11 $class = 'Math::BigRat';
12 use_ok($class);
13}
14
15while (<DATA>) {
16 s/#.*$//; # remove comments
17 s/\s+$//; # remove trailing whitespace
18 next unless length; # skip empty lines
19
20 my ($x_str, $int_str, $frc_str) = split /:/;
21 my $test;
22
23 $test = qq|\$x = $class -> new("$x_str");|
24 . qq| (\$i, \$f) = \$x -> dparts();|;
25
26 subtest $test => sub {
27 plan tests => 5;
28
29 my $x = $class -> new($x_str);
30 my ($int_got, $frc_got) = $x -> dparts();
31
32 is(ref($int_got), $class, "class of integer part");
33 is(ref($frc_got), $class, "class of fraction part");
34
35 is($int_got, $int_str, "value of integer part");
36 is($frc_got, $frc_str, "value of fraction part");
37 is($x, $x_str, "input is unmodified");
38 };
39
40 $test = qq|\$x = $class -> new("$x_str");|
41 . qq| \$i = \$x -> dparts();|;
42
43 subtest $test => sub {
44 plan tests => 3,
45
46 my $x = $class -> new($x_str);
47 my $int_got = $x -> dparts();
48
49 isa_ok($int_got, $class);
50
51 is($int_got, $int_str, "value of integer part");
52 is($x, $x_str, "input is unmodified");
53 };
54}
55
56__DATA__
57
58NaN:NaN:NaN
59
60inf:inf:0
61-inf:-inf:0
62
63-9/4:-2:-1/4
64-1:-1:0
650:0:0
661:1:0
679/4:2:1/4