1*0Sstevel@tonic-gate#!/usr/bin/perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate############################################################################### 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gateuse Test; 6*0Sstevel@tonic-gateuse strict; 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gateBEGIN 9*0Sstevel@tonic-gate { 10*0Sstevel@tonic-gate $| = 1; 11*0Sstevel@tonic-gate chdir 't' if -d 't'; 12*0Sstevel@tonic-gate unshift @INC, '../lib'; 13*0Sstevel@tonic-gate plan tests => 25; 14*0Sstevel@tonic-gate } 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gateuse bigrat; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate############################################################################### 19*0Sstevel@tonic-gate# general tests 20*0Sstevel@tonic-gate 21*0Sstevel@tonic-gatemy $x = 5; ok (ref($x) =~ /^Math::BigInt/); # :constant 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate# todo: ok (2 + 2.5,4.5); # should still work 24*0Sstevel@tonic-gate# todo: $x = 2 + 3.5; ok (ref($x),'Math::BigFloat'); 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate$x = 2 ** 255; ok (ref($x) =~ /^Math::BigInt/); 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate# see if Math::BigRat constant works 29*0Sstevel@tonic-gateok (1/3, '1/3'); 30*0Sstevel@tonic-gateok (1/4+1/3,'7/12'); 31*0Sstevel@tonic-gateok (5/7+3/7,'8/7'); 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gateok (3/7+1,'10/7'); 34*0Sstevel@tonic-gateok (3/7+1.1,'107/70'); 35*0Sstevel@tonic-gateok (3/7+3/7,'6/7'); 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gateok (3/7-1,'-4/7'); 38*0Sstevel@tonic-gateok (3/7-1.1,'-47/70'); 39*0Sstevel@tonic-gateok (3/7-2/7,'1/7'); 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate# fails ? 42*0Sstevel@tonic-gate# ok (1+3/7,'10/7'); 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gateok (1.1+3/7,'107/70'); 45*0Sstevel@tonic-gateok (3/7*5/7,'15/49'); 46*0Sstevel@tonic-gateok (3/7 / (5/7),'3/5'); 47*0Sstevel@tonic-gateok (3/7 / 1,'3/7'); 48*0Sstevel@tonic-gateok (3/7 / 1.5,'2/7'); 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate############################################################################### 51*0Sstevel@tonic-gate# accurarcy and precision 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gateok_undef (bigrat->accuracy()); 54*0Sstevel@tonic-gateok (bigrat->accuracy(12),12); 55*0Sstevel@tonic-gateok (bigrat->accuracy(),12); 56*0Sstevel@tonic-gate 57*0Sstevel@tonic-gateok_undef (bigrat->precision()); 58*0Sstevel@tonic-gateok (bigrat->precision(12),12); 59*0Sstevel@tonic-gateok (bigrat->precision(),12); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gateok (bigrat->round_mode(),'even'); 62*0Sstevel@tonic-gateok (bigrat->round_mode('odd'),'odd'); 63*0Sstevel@tonic-gateok (bigrat->round_mode(),'odd'); 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate############################################################################### 66*0Sstevel@tonic-gate############################################################################### 67*0Sstevel@tonic-gate# Perl 5.005 does not like ok ($x,undef) 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gatesub ok_undef 70*0Sstevel@tonic-gate { 71*0Sstevel@tonic-gate my $x = shift; 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate ok (1,1) and return if !defined $x; 74*0Sstevel@tonic-gate ok ($x,'undef'); 75*0Sstevel@tonic-gate } 76