Commit | Line | Data |
58cde26e |
1 | #!/usr/bin/perl -w |
2 | |
ee15d750 |
3 | # test rounding, accuracy, precicion and fallback, round_mode and mixing |
4 | # of classes |
58cde26e |
5 | |
6 | use strict; |
7 | use Test; |
8 | |
61f5c3f5 |
9 | BEGIN |
58cde26e |
10 | { |
11 | $| = 1; |
61f5c3f5 |
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 | |
2ab5f49d |
34 | plan tests => 669 |
b3abae2a |
35 | + 16; # own tests |
ee15d750 |
36 | } |
37 | |
2ab5f49d |
38 | use Math::BigInt 1.63; |
39 | use Math::BigFloat 1.38; |
ee15d750 |
40 | |
61f5c3f5 |
41 | use vars qw/$mbi $mbf/; |
ee15d750 |
42 | |
61f5c3f5 |
43 | $mbi = 'Math::BigInt'; |
44 | $mbf = 'Math::BigFloat'; |
58cde26e |
45 | |
61f5c3f5 |
46 | require 'mbimbf.inc'; |
58cde26e |
47 | |
61f5c3f5 |
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) |
58cde26e |
51 | |
61f5c3f5 |
52 | Math::BigInt->round_mode('even'); # reset for tests |
53 | Math::BigFloat->round_mode('even'); # reset for tests |
58cde26e |
54 | |
027dc388 |
55 | ok ($Math::BigInt::rnd_mode,'even'); |
56 | ok ($Math::BigFloat::rnd_mode,'even'); |
57 | |
61f5c3f5 |
58 | my $x = eval '$mbi->round_mode("huhmbi");'; |
dccbb853 |
59 | ok ($@ =~ /^Unknown round mode huhmbi at/); |
60 | |
61f5c3f5 |
61 | $x = eval '$mbf->round_mode("huhmbf");'; |
dccbb853 |
62 | ok ($@ =~ /^Unknown round mode huhmbf at/); |
ee15d750 |
63 | |
027dc388 |
64 | # old way (now with test for validity) |
65 | $x = eval '$Math::BigInt::rnd_mode = "huhmbi";'; |
66 | ok ($@ =~ /^Unknown round mode huhmbi at/); |
61f5c3f5 |
67 | $x = eval '$Math::BigFloat::rnd_mode = "huhmbf";'; |
68 | ok ($@ =~ /^Unknown round mode huhmbf at/); |
027dc388 |
69 | # see if accessor also changes old variable |
61f5c3f5 |
70 | $mbi->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); |
71 | $mbf->round_mode('odd'); ok ($Math::BigInt::rnd_mode,'odd'); |
58cde26e |
72 | |
b3abae2a |
73 | foreach my $class (qw/Math::BigInt Math::BigFloat/) |
74 | { |
75 | ok ($class->accuracy(5),5); # set A |
76 | ok_undef ($class->precision()); # and now P must be cleared |
77 | ok ($class->precision(5),5); # set P |
78 | ok_undef ($class->accuracy()); # and now A must be cleared |
79 | } |
80 | |