File: bigrat.t

package info (click to toggle)
perl 5.8.4-8sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,128 kB
  • ctags: 31,422
  • sloc: perl: 224,262; ansic: 155,398; sh: 32,253; pascal: 7,747; lisp: 6,121; makefile: 2,341; cpp: 2,035; yacc: 1,019; java: 23
file content (75 lines) | stat: -rwxr-xr-x 1,599 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl -w

###############################################################################

use Test;
use strict;

BEGIN
  {
  $| = 1;
  chdir 't' if -d 't';
  unshift @INC, '../lib';
  plan tests => 25;
  }

use bigrat;

###############################################################################
# general tests

my $x = 5; ok (ref($x) =~ /^Math::BigInt/);		# :constant

# todo:  ok (2 + 2.5,4.5);				# should still work
# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat');

$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/);

# see if Math::BigRat constant works
ok (1/3, '1/3');
ok (1/4+1/3,'7/12');
ok (5/7+3/7,'8/7');

ok (3/7+1,'10/7');
ok (3/7+1.1,'107/70');
ok (3/7+3/7,'6/7');

ok (3/7-1,'-4/7');
ok (3/7-1.1,'-47/70');
ok (3/7-2/7,'1/7');

# fails ?
# ok (1+3/7,'10/7');

ok (1.1+3/7,'107/70');
ok (3/7*5/7,'15/49');
ok (3/7 / (5/7),'3/5');
ok (3/7 / 1,'3/7');
ok (3/7 / 1.5,'2/7');

###############################################################################
# accurarcy and precision

ok_undef (bigrat->accuracy());
ok (bigrat->accuracy(12),12);
ok (bigrat->accuracy(),12);

ok_undef (bigrat->precision());
ok (bigrat->precision(12),12);
ok (bigrat->precision(),12);

ok (bigrat->round_mode(),'even');
ok (bigrat->round_mode('odd'),'odd');
ok (bigrat->round_mode(),'odd');

###############################################################################
###############################################################################
# Perl 5.005 does not like ok ($x,undef)

sub ok_undef
  {
  my $x = shift;

  ok (1,1) and return if !defined $x;
  ok ($x,'undef');
  }