Commit | Line | Data |
---|---|---|
6853e8af RL |
1 | # -*- mode: perl; -*- |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use Test::More tests => 17; | |
7 | ||
8 | my $class; | |
9 | ||
10 | BEGIN { | |
11 | $class = 'Math::BigRat'; | |
12 | use_ok($class); | |
13 | } | |
14 | ||
15 | while (<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 | ||
58 | NaN:NaN:NaN | |
59 | ||
60 | inf:inf:0 | |
61 | -inf:-inf:0 | |
62 | ||
63 | -9/4:-2:-1/4 | |
64 | -1:-1:0 | |
65 | 0:0:0 | |
66 | 1:1:0 | |
67 | 9/4:2:1/4 |