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