1#!/usr/bin/perl -w 2 3# test rounding, accuracy, precicion and fallback, round_mode and mixing 4# of classes 5 6use strict; 7use Test; 8 9BEGIN 10 { 11 $| = 1; 12 # to locate the testing files 13 my $location = $0; $location =~ s/mbimbf.t//i; 14 if ($ENV{PERL_CORE}) 15 { 16 @INC = qw(../lib); # testing with the core distribution 17 } 18 else 19 { 20 unshift @INC, '../lib'; # for testing manually 21 } 22 if (-d 't') 23 { 24 chdir 't'; 25 require File::Spec; 26 unshift @INC, File::Spec->catdir(File::Spec->updir, $location); 27 } 28 else 29 { 30 unshift @INC, $location; 31 } 32 print "# INC = @INC\n"; 33 34 plan tests => 684 35 + 23; # own tests 36 } 37 38use Math::BigInt 1.70; 39use Math::BigFloat 1.43; 40 41use vars qw/$mbi $mbf/; 42 43$mbi = 'Math::BigInt'; 44$mbf = 'Math::BigFloat'; 45 46require 'mbimbf.inc'; 47 48# some tests that won't work with subclasses, since the things are only 49# garantied in the Math::BigInt/BigFloat (unless subclass chooses to support 50# this) 51 52Math::BigInt->round_mode('even'); # reset for tests 53Math::BigFloat->round_mode('even'); # reset for tests 54 55ok ($Math::BigInt::rnd_mode,'even'); 56ok ($Math::BigFloat::rnd_mode,'even'); 57 58my $x = eval '$mbi->round_mode("huhmbi");'; 59print "# Got '$@'\n" unless 60 ok ($@ =~ /^Unknown round mode 'huhmbi' at/); 61 62$x = eval '$mbf->round_mode("huhmbf");'; 63print "# Got '$@'\n" unless 64 ok ($@ =~ /^Unknown round mode 'huhmbf' at/); 65 66# old way (now with test for validity) 67$x = eval '$Math::BigInt::rnd_mode = "huhmbi";'; 68print "# Got '$@'\n" unless 69 ok ($@ =~ /^Unknown round mode 'huhmbi' at/); 70$x = eval '$Math::BigFloat::rnd_mode = "huhmbf";'; 71print "# Got '$@'\n" unless 72 ok ($@ =~ /^Unknown round mode 'huhmbf' at/); 73# see if accessor also changes old variable 74$mbi->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); 75$mbf->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); 76 77foreach my $class (qw/Math::BigInt Math::BigFloat/) 78 { 79 ok ($class->accuracy(5),5); # set A 80 ok_undef ($class->precision()); # and now P must be cleared 81 ok ($class->precision(5),5); # set P 82 ok_undef ($class->accuracy()); # and now A must be cleared 83 } 84 85foreach my $class (qw/Math::BigInt Math::BigFloat/) 86 { 87 $class->accuracy(42); 88 my $x = $class->new(123); # $x gets A of 42, too! 89 ok ($x->accuracy(),42); # really? 90 ok ($x->accuracy(undef),42); # $x has no A, but the 91 # global is still in effect for $x 92 # so the return value of that operation should 93 # be 42, not undef 94 ok ($x->accuracy(),42); # so $x should still have A = 42 95 $class->accuracy(undef); # reset for further tests 96 $class->precision(undef); 97 } 98# bug with flog(Math::BigFloat,Math::BigInt) 99$x = Math::BigFloat->new(100); 100$x = $x->blog(Math::BigInt->new(10)); 101 102ok ($x,2); 103