xref: /openbsd-src/gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.t (revision 3d61058aa5c692477b6d18acfbbdb653a9930ff9)
1# -*- mode: perl; -*-
2
3use strict;
4use warnings;
5
6use Test::More tests => 2136            # tests in require'd file
7                         + 6;           # tests in this file
8
9use Math::BigInt;
10use Math::BigFloat;
11
12my $x = Math::BigInt -> new(9);
13my $y = Math::BigInt -> new(4);
14
15# Without upgrading.
16
17my $zi = $x / $y;
18cmp_ok($zi, "==", 2, "9/4 = 2 without upgrading");
19is(ref($zi), "Math::BigInt", "9/4 gives a Math::BigInt without upgrading");
20
21# With upgrading.
22
23Math::BigInt -> upgrade("Math::BigFloat");
24my $zf = $x / $y;
25cmp_ok($zf, "==", 2.25, "9/4 = 2.25 with upgrading");
26is(ref($zf), "Math::BigFloat", "9/4 gives a Math::BigFloat with upgrading");
27
28# Other tests.
29
30our ($CLASS, $EXPECTED_CLASS, $LIB);
31$CLASS          = "Math::BigInt";
32$EXPECTED_CLASS = "Math::BigFloat";
33$LIB            = "Math::BigInt::Calc";         # backend
34
35is(Math::BigInt->upgrade(), "Math::BigFloat",
36   "Math::BigInt->upgrade()");
37is(Math::BigInt->downgrade(), undef,
38   "Math::BigInt->downgrade()");
39
40require './t/upgrade.inc';      # all tests here for sharing
41