1# -*- mode: perl; -*- 2 3############################################################################### 4 5use strict; 6use warnings; 7 8use Test::More tests => 27; 9 10use bigrat; 11 12############################################################################### 13# general tests 14 15my $x = 5; 16is(ref($x), 'Math::BigRat', '$x = 5 makes $x a Math::BigRat'); 17 18$x = 2 + 3.5; 19is($x, 5.5, '2 + 3.5 = 5.5'); 20is(ref($x), 'Math::BigRat', '$x = 2 + 3.5 makes $x a Math::BigRat'); 21 22$x = 2 ** 255; 23is(ref($x), 'Math::BigRat', '$x = 2 ** 255 makes $x a Math::BigRat'); 24 25is(1/3, '1/3', qq|1/3 = '1/3'|); 26is(1/4+1/3, '7/12', qq|1/4+1/3 = '7/12'|); 27is(5/7+3/7, '8/7', qq|5/7+3/7 = '8/7'|); 28 29is(3/7+1, '10/7', qq|3/7+1 = '10/7'|); 30is(3/7+1.1, '107/70', qq|3/7+1.1 = '107/70'|); 31is(3/7+3/7, '6/7', qq|3/7+3/7 = '6/7'|); 32 33is(3/7-1, '-4/7', qq|3/7-1 = '-4/7'|); 34is(3/7-1.1, '-47/70', qq|3/7-1.1 = '-47/70'|); 35is(3/7-2/7, '1/7', qq|3/7-2/7 = '1/7'|); 36 37# fails ? 38# is(1+3/7, '10/7', qq|1+3/7 = '10/7'|); 39 40is(1.1+3/7, '107/70', qq|1.1+3/7 = '107/70'|); 41is(3/7*5/7, '15/49', qq|3/7*5/7 = '15/49'|); 42is(3/7 / (5/7), '3/5', qq|3/7 / (5/7) = '3/5'|); 43is(3/7 / 1, '3/7', qq|3/7 / 1 = '3/7'|); 44is(3/7 / 1.5, '2/7', qq|3/7 / 1.5 = '2/7'|); 45 46############################################################################### 47# accuracy and precision 48 49is(bigrat->accuracy(), undef, 'get accuracy'); 50bigrat->accuracy(12); 51is(bigrat->accuracy(), 12, 'get accuracy again'); 52bigrat->accuracy(undef); 53is(bigrat->accuracy(), undef, 'get accuracy again'); 54 55is(bigrat->precision(), undef, 'get precision'); 56bigrat->precision(12); 57is(bigrat->precision(), 12, 'get precision again'); 58bigrat->precision(undef); 59is(bigrat->precision(), undef, 'get precision again'); 60 61is(bigrat->round_mode(), 'even', 'get round mode'); 62bigrat->round_mode('odd'); 63is(bigrat->round_mode(), 'odd', 'get round mode again'); 64bigrat->round_mode('even'); 65is(bigrat->round_mode(), 'even', 'get round mode again'); 66