1#!/usr/bin/perl -w 2 3use strict; 4use Test; 5 6BEGIN 7 { 8 $| = 1; 9 chdir 't' if -d 't'; 10 unshift @INC, '../lib'; # for running manually 11 plan tests => 51; 12 } 13 14# test whether Math::BigInt->config() and Math::BigFloat->config() works 15 16use Math::BigInt; 17use Math::BigFloat; 18 19my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; 20 21############################################################################## 22# BigInt 23 24ok ($mbi->can('config')); 25 26my $cfg = $mbi->config(); 27 28ok (ref($cfg),'HASH'); 29 30ok ($cfg->{lib},'Math::BigInt::Calc'); 31ok ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION); 32ok ($cfg->{class},$mbi); 33ok ($cfg->{upgrade}||'',''); 34ok ($cfg->{div_scale},40); 35 36ok ($cfg->{precision}||0,0); # should test for undef 37ok ($cfg->{accuracy}||0,0); 38 39ok ($cfg->{round_mode},'even'); 40 41ok ($cfg->{trap_nan},0); 42ok ($cfg->{trap_inf},0); 43 44############################################################################## 45# BigFloat 46 47ok ($mbf->can('config')); 48 49$cfg = $mbf->config(); 50 51ok (ref($cfg),'HASH'); 52 53ok ($cfg->{lib},'Math::BigInt::Calc'); 54ok ($cfg->{with},'Math::BigInt::Calc'); 55ok ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION); 56ok ($cfg->{class},$mbf); 57ok ($cfg->{upgrade}||'',''); 58ok ($cfg->{div_scale},40); 59 60ok ($cfg->{precision}||0,0); # should test for undef 61ok ($cfg->{accuracy}||0,0); 62 63ok ($cfg->{round_mode},'even'); 64 65ok ($cfg->{trap_nan},0); 66ok ($cfg->{trap_inf},0); 67 68############################################################################## 69# test setting values 70 71my $test = { 72 trap_nan => 1, 73 trap_inf => 1, 74 accuracy => 2, 75 precision => 3, 76 round_mode => 'zero', 77 div_scale => '100', 78 upgrade => 'Math::BigInt::SomeClass', 79 downgrade => 'Math::BigInt::SomeClass', 80 }; 81 82my $c; 83 84foreach my $key (keys %$test) 85 { 86 # see if setting in MBI works 87 eval ( "$mbi\->config( $key => '$test->{$key}' );" ); 88 $c = $mbi->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}"); 89 $c = $mbf->config(); 90 # see if setting it in MBI leaves MBF alone 91 if (($c->{$key}||0) ne $test->{$key}) 92 { 93 ok (1,1); 94 } 95 else 96 { 97 ok ("$key eq $c->{$key}","$key ne $test->{$key}"); 98 } 99 100 # see if setting in MBF works 101 eval ( "$mbf\->config( $key => '$test->{$key}' );" ); 102 $c = $mbf->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}"); 103 } 104 105############################################################################## 106# test setting illegal keys (should croak) 107 108my $never_reached = 0; 109eval ("$mbi\->config( 'some_garbage' => 1 ); $never_reached = 1;"); 110ok ($never_reached,0); 111 112$never_reached = 0; 113eval ("$mbf\->config( 'some_garbage' => 1 ); $never_reached = 1;"); 114ok ($never_reached,0); 115 116# this does not work. Why? 117#ok (@!, "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104"); 118 119# all tests done 120 121