10 unshift @INC, '../lib'; # for running manually
14 # test whether Math::BigInt->config() and Math::BigFloat->config() works
16 use Math::BigInt lib => 'Calc';
19 my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat';
21 ##############################################################################
24 ok ($mbi->can('config'));
26 my $cfg = $mbi->config();
28 ok (ref($cfg),'HASH');
30 is ($cfg->{lib},'Math::BigInt::Calc', 'lib');
31 is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version');
32 is ($cfg->{class},$mbi,'class');
33 is ($cfg->{upgrade}||'','', 'upgrade');
34 is ($cfg->{div_scale},40, 'div_Scale');
36 is ($cfg->{precision}||0,0, 'precision'); # should test for undef
37 is ($cfg->{accuracy}||0,0,'accuracy');
38 is ($cfg->{round_mode},'even','round_mode');
40 is ($cfg->{trap_nan},0, 'trap_nan');
41 is ($cfg->{trap_inf},0, 'trap_inf');
43 is ($mbi->config('lib'), 'Math::BigInt::Calc', 'config("lib")');
45 # can set via hash ref?
46 $cfg = $mbi->config( { trap_nan => 1 } );
47 is ($cfg->{trap_nan},1, 'can set via hash ref');
50 $mbi->config( trap_nan => 0 );
52 ##############################################################################
55 ok ($mbf->can('config'));
57 $cfg = $mbf->config();
59 ok (ref($cfg),'HASH');
61 is ($cfg->{lib},'Math::BigInt::Calc', 'lib');
62 is ($cfg->{with},'Math::BigInt::Calc', 'with');
63 is ($cfg->{lib_version}, $Math::BigInt::Calc::VERSION, 'lib_version');
64 is ($cfg->{class},$mbf,'class');
65 is ($cfg->{upgrade}||'','', 'upgrade');
66 is ($cfg->{div_scale},40, 'div_Scale');
68 is ($cfg->{precision}||0,0, 'precision'); # should test for undef
69 is ($cfg->{accuracy}||0,0,'accuracy');
70 is ($cfg->{round_mode},'even','round_mode');
72 is ($cfg->{trap_nan},0, 'trap_nan');
73 is ($cfg->{trap_inf},0, 'trap_inf');
75 is ($mbf->config('lib'), 'Math::BigInt::Calc', 'config("lib")');
77 # can set via hash ref?
78 $cfg = $mbf->config( { trap_nan => 1 } );
79 is ($cfg->{trap_nan},1, 'can set via hash ref');
82 $mbf->config( trap_nan => 0 );
84 ##############################################################################
94 upgrade => 'Math::BigInt::SomeClass',
95 downgrade => 'Math::BigInt::SomeClass',
100 foreach my $key (keys %$test)
102 # see if setting in MBI works
103 eval ( "$mbi\->config( $key => '$test->{$key}' );" );
104 $c = $mbi->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}");
106 # see if setting it in MBI leaves MBF alone
107 if (($c->{$key}||0) ne $test->{$key})
113 is ("$key eq $c->{$key}","$key ne $test->{$key}", "$key");
116 # see if setting in MBF works
117 eval ( "$mbf\->config( $key => '$test->{$key}' );" );
118 $c = $mbf->config(); ok ("$key = $c->{$key}", "$key = $test->{$key}");
121 ##############################################################################
122 # test setting illegal keys (should croak)
124 $@ = ""; my $never_reached = 0;
125 eval ("$mbi\->config( 'some_garbage' => 1 ); $never_reached = 1;");
126 is ($never_reached,0);
128 $@ = ""; $never_reached = 0;
129 eval ("$mbf\->config( 'some_garbage' => 1 ); $never_reached = 1;");
130 is ($never_reached,0);
132 # this does not work. Why?
133 #ok ($@ eq "Illegal keys 'some_garbage' passed to Math::BigInt->config() at ./config.t line 104", 1);