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 59
|
# -*- mode: perl; -*-
use strict;
use warnings;
use lib 't';
use Test::More tests => 13;
use Math::BigInt::Subclass;
use Math::BigFloat::Subclass;
use Math::BigFloat::BareSubclass;
use Math::BigInt;
use Math::BigFloat;
my $class = "Math::BigInt::Subclass";
my $LIB = "Math::BigInt::Calc";
# Check that a subclass is still considered a Math::BigInt
isa_ok($class->new(123), 'Math::BigInt');
# ditto for plain Math::BigInt
isa_ok(Math::BigInt->new(123), 'Math::BigInt');
# But Math::BigFloat objects aren't
ok(!Math::BigFloat->new(123)->isa('Math::BigInt'),
"A Math::BigFloat isn't a Math::BigInt");
{
# see what happens if we feed a Math::BigFloat into new()
my $x = Math::BigInt->new(Math::BigFloat->new(123));
is(ref($x), 'Math::BigInt', 'ref($x) = "Math::BigInt"');
isa_ok($x, 'Math::BigInt');
}
{
# ditto for subclass
my $x = Math::BigInt->new(Math::BigFloat::Subclass->new(123));
is(ref($x), 'Math::BigInt', 'ref($x) = "Math::BigInt"');
isa_ok($x, 'Math::BigInt');
}
{
my $x = Math::BigFloat->new(Math::BigInt->new(123));
is(ref($x), 'Math::BigFloat', 'ref($x) = "Math::BigFloat"');
isa_ok($x, 'Math::BigFloat');
}
{
my $x = Math::BigFloat->new(Math::BigInt::Subclass->new(123));
is(ref($x), 'Math::BigFloat', 'ref($x) = "Math::BigFloat"');
isa_ok($x, 'Math::BigFloat');
}
{
my $x = Math::BigFloat->new(9999.99);
my $y = Math::BigFloat::BareSubclass->new(9999.99);
ok($x == $y, "Math::BigFloat parent == subclass");
ok($y == $x, "Math::BigFloat subclass == parent");
}
|