1# -*- mode: perl; -*- 2 3use strict; 4use warnings; 5use lib 't'; 6 7use Test::More tests => 13; 8 9use Math::BigInt::Subclass; 10use Math::BigFloat::Subclass; 11use Math::BigFloat::BareSubclass; 12use Math::BigInt; 13use Math::BigFloat; 14 15my $class = "Math::BigInt::Subclass"; 16my $LIB = "Math::BigInt::Calc"; 17 18# Check that a subclass is still considered a Math::BigInt 19isa_ok($class->new(123), 'Math::BigInt'); 20 21# ditto for plain Math::BigInt 22isa_ok(Math::BigInt->new(123), 'Math::BigInt'); 23 24# But Math::BigFloat objects aren't 25ok(!Math::BigFloat->new(123)->isa('Math::BigInt'), 26 "A Math::BigFloat isn't a Math::BigInt"); 27 28{ 29 # see what happens if we feed a Math::BigFloat into new() 30 my $x = Math::BigInt->new(Math::BigFloat->new(123)); 31 is(ref($x), 'Math::BigInt', 'ref($x) = "Math::BigInt"'); 32 isa_ok($x, 'Math::BigInt'); 33} 34 35{ 36 # ditto for subclass 37 my $x = Math::BigInt->new(Math::BigFloat::Subclass->new(123)); 38 is(ref($x), 'Math::BigInt', 'ref($x) = "Math::BigInt"'); 39 isa_ok($x, 'Math::BigInt'); 40} 41 42{ 43 my $x = Math::BigFloat->new(Math::BigInt->new(123)); 44 is(ref($x), 'Math::BigFloat', 'ref($x) = "Math::BigFloat"'); 45 isa_ok($x, 'Math::BigFloat'); 46} 47 48{ 49 my $x = Math::BigFloat->new(Math::BigInt::Subclass->new(123)); 50 is(ref($x), 'Math::BigFloat', 'ref($x) = "Math::BigFloat"'); 51 isa_ok($x, 'Math::BigFloat'); 52} 53 54{ 55 my $x = Math::BigFloat->new(9999.99); 56 my $y = Math::BigFloat::BareSubclass->new(9999.99); 57 ok($x == $y, "Math::BigFloat parent == subclass"); 58 ok($y == $x, "Math::BigFloat subclass == parent"); 59} 60