4 use Test::More tests => 55;
6 # test whether Math::BigInt->config() and Math::BigFloat->config() works
8 use Math::BigInt lib => 'Calc';
11 my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat';
13 ##############################################################################
16 ok ($mbi->can('config'));
18 my $cfg = $mbi->config();
20 ok (ref($cfg),'HASH');
22 is ($cfg->{lib},'Math::BigInt::Calc', 'lib');
23 is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version');
24 is ($cfg->{class},$mbi,'class');
25 is ($cfg->{upgrade}||'','', 'upgrade');
26 is ($cfg->{div_scale},40, 'div_Scale');
28 is ($cfg->{precision}||0,0, 'precision'); # should test for undef
29 is ($cfg->{accuracy}||0,0,'accuracy');
30 is ($cfg->{round_mode},'even','round_mode');
32 is ($cfg->{trap_nan},0, 'trap_nan');
33 is ($cfg->{trap_inf},0, 'trap_inf');
35 is ($mbi->config('lib'), 'Math::BigInt::Calc', 'config("lib")');
37 # can set via hash ref?
38 $cfg = $mbi->config( { trap_nan => 1 } );
39 is ($cfg->{trap_nan},1, 'can set via hash ref');
42 $mbi->config( trap_nan => 0 );
44 ##############################################################################
47 ok ($mbf->can('config'));
49 $cfg = $mbf->config();
51 ok (ref($cfg),'HASH');
53 is ($cfg->{lib},'Math::BigInt::Calc', 'lib');
54 is ($cfg->{with},'Math::BigInt::Calc', 'with');
55 is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version');
56 is ($cfg->{class},$mbf,'class');
57 is ($cfg->{upgrade}||'','', 'upgrade');
58 is ($cfg->{div_scale},40, 'div_Scale');
60 is ($cfg->{precision}||0,0, 'precision'); # should test for undef
61 is ($cfg->{accuracy}||0,0,'accuracy');
62 is ($cfg->{round_mode},'even','round_mode');
64 is ($cfg->{trap_nan},0, 'trap_nan');
65 is ($cfg->{trap_inf},0, 'trap_inf');
67 is ($mbf->config('lib'), 'Math::BigInt::Calc', 'config("lib")');
69 # can set via hash ref?
70 $cfg = $mbf->config( { trap_nan => 1 } );
71 is ($cfg->{trap_nan},1, 'can set via hash ref');
74 $mbf->config( trap_nan => 0 );
76 ##############################################################################
86 upgrade => 'Math::BigInt::SomeClass',
87 downgrade => 'Math::BigInt::SomeClass',
92 foreach my $key (keys %$test)
94 # see if setting in MBI works
95 eval ( "$mbi\->config( $key => '$test->{$key}' );" );
96 $c = $mbi->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}");
98 # see if setting it in MBI leaves MBF alone
99 if (($c->{$key}||0) ne $test->{$key})
105 is ("$key eq $c->{$key}","$key ne $test->{$key}", "$key");
108 # see if setting in MBF works
109 eval ( "$mbf\->config( $key => '$test->{$key}' );" );
110 $c = $mbf->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}");
113 ##############################################################################
114 # test setting illegal keys (should croak)
116 $@ = ""; my $never_reached = 0;
117 eval ("$mbi\->config( 'some_garbage' => 1 ); $never_reached = 1;");
118 is ($never_reached,0);
120 $@ = ""; $never_reached = 0;
121 eval ("$mbf\->config( 'some_garbage' => 1 ); $never_reached = 1;");
122 is ($never_reached,0);
124 # this does not work. Why?
125 #ok ($@ eq "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104", 1);