| 1 | #!/usr/bin/perl -w
|
|---|
| 2 |
|
|---|
| 3 | ###############################################################################
|
|---|
| 4 |
|
|---|
| 5 | use Test;
|
|---|
| 6 | use strict;
|
|---|
| 7 |
|
|---|
| 8 | BEGIN
|
|---|
| 9 | {
|
|---|
| 10 | $| = 1;
|
|---|
| 11 | chdir 't' if -d 't';
|
|---|
| 12 | unshift @INC, '../lib';
|
|---|
| 13 | plan tests => 32;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | use bigint;
|
|---|
| 17 |
|
|---|
| 18 | ###############################################################################
|
|---|
| 19 | # _constant tests
|
|---|
| 20 |
|
|---|
| 21 | foreach (qw/
|
|---|
| 22 | 123:123
|
|---|
| 23 | 123.4:123
|
|---|
| 24 | 1.4:1
|
|---|
| 25 | 0.1:0
|
|---|
| 26 | -0.1:0
|
|---|
| 27 | -1.1:-1
|
|---|
| 28 | -123.4:-123
|
|---|
| 29 | -123:-123
|
|---|
| 30 | 123e2:123e2
|
|---|
| 31 | 123e-1:12
|
|---|
| 32 | 123e-4:0
|
|---|
| 33 | 123e-3:0
|
|---|
| 34 | 123.345e-1:12
|
|---|
| 35 | 123.456e+2:12345
|
|---|
| 36 | 1234.567e+3:1234567
|
|---|
| 37 | 1234.567e+4:1234567E1
|
|---|
| 38 | 1234.567e+6:1234567E3
|
|---|
| 39 | /)
|
|---|
| 40 | {
|
|---|
| 41 | my ($x,$y) = split /:/;
|
|---|
| 42 | print "# Try $x\n";
|
|---|
| 43 | ok (bigint::_constant("$x"),"$y");
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | ###############################################################################
|
|---|
| 47 | # general tests
|
|---|
| 48 |
|
|---|
| 49 | my $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant
|
|---|
| 50 |
|
|---|
| 51 | # todo: ok (2 + 2.5,4.5); # should still work
|
|---|
| 52 | # todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');
|
|---|
| 53 |
|
|---|
| 54 | $x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);
|
|---|
| 55 |
|
|---|
| 56 | ok (12->bfac(),479001600);
|
|---|
| 57 | ok (9/4,2);
|
|---|
| 58 |
|
|---|
| 59 | ok (4.5+4.5,8); # truncate
|
|---|
| 60 | ok (ref(4.5+4.5) =~ /^Math::BigInt/);
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | ###############################################################################
|
|---|
| 64 | # accurarcy and precision
|
|---|
| 65 |
|
|---|
| 66 | ok_undef (bigint->accuracy());
|
|---|
| 67 | ok (bigint->accuracy(12),12);
|
|---|
| 68 | ok (bigint->accuracy(),12);
|
|---|
| 69 |
|
|---|
| 70 | ok_undef (bigint->precision());
|
|---|
| 71 | ok (bigint->precision(12),12);
|
|---|
| 72 | ok (bigint->precision(),12);
|
|---|
| 73 |
|
|---|
| 74 | ok (bigint->round_mode(),'even');
|
|---|
| 75 | ok (bigint->round_mode('odd'),'odd');
|
|---|
| 76 | ok (bigint->round_mode(),'odd');
|
|---|
| 77 |
|
|---|
| 78 | ###############################################################################
|
|---|
| 79 | ###############################################################################
|
|---|
| 80 | # Perl 5.005 does not like ok ($x,undef)
|
|---|
| 81 |
|
|---|
| 82 | sub ok_undef
|
|---|
| 83 | {
|
|---|
| 84 | my $x = shift;
|
|---|
| 85 |
|
|---|
| 86 | ok (1,1) and return if !defined $x;
|
|---|
| 87 | ok ($x,'undef');
|
|---|
| 88 | }
|
|---|