File: down-mbi-up-mbf.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (58 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- mode: perl; -*-

use strict;
use warnings;

use Test::More tests => 14;

use bignum;

is(bignum -> downgrade(), "Math::BigInt",
   "bignum's downgrade class is Math::BigInt");
is(bignum -> upgrade(), "Math::BigFloat",
  "bignum's upgrade class is Math::BigFloat");

is(Math::BigFloat -> downgrade(), "Math::BigInt",
  "Math::BigFloat's downgrade class is Math::BigInt");
is(Math::BigInt -> upgrade(), "Math::BigFloat",
  "Math::BigInt's upgrade class is Math::BigFloat");

my $i1 = 7;
my $i2 = 2;
my $f1 = 3.75;
my $f2 = 1.25;

is(ref($i1), "Math::BigInt", "literal $i1 is a Math::BigInt");
is(ref($f1), "Math::BigFloat", "literal $f1 is a Math::BigFloat");

# Verify that the result is upgraded to a Math::BigFloat.

cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5");
is(ref($i1/$i2), "Math::BigFloat", "$i1/$i2 is 3.5 as a Math::BigFloat");

# Verify that the result is downgraded to a Math::BigInt.

cmp_ok($f1/$f2, "==", "3", "$f1/$f2 is 3");
is(ref($f1/$f2), "Math::BigInt", "$f1/$f2 is 3 as a Math::BigInt");

# Change the upgrade class during runtime.

SKIP: {
    eval "use Math::BigRat";
    skip "Math::BigRat not installed", 4 if $@;

    bignum -> upgrade("Math::BigRat");

    my $r1 = 3.75;
    my $r2 = 1.25;

    # Verify that the result is upgraded to a Math::BigRat.

    cmp_ok($i1/$i2, "==", "3.5", "$i1/$i2 is 3.5");
    is(ref($i1/$i2), "Math::BigRat", "$i1/$i2 is 3.5 as a Math::BigRat");

    # Verify that the result is downgraded to a Math::BigInt.

    cmp_ok($r1/$r2, "==", "3", "($r1)/($r2) is 3");
    is(ref($r1/$r2), "Math::BigInt", "($r1)/($r2) is 3 as a Math::BigInt");
};