Move Math::BigInt from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Math-BigInt / t / bigints.t
CommitLineData
f3d61276 1#!/usr/bin/perl -w
2
3use strict;
4use Test;
5
6BEGIN
7 {
8 $| = 1;
990fb837 9 # to locate the testing files
10 my $location = $0; $location =~ s/bigints.t//i;
11 if ($ENV{PERL_CORE})
12 {
13 @INC = qw(../t/lib); # testing with the core distribution
14 }
15 unshift @INC, '../lib'; # for testing manually
16 if (-d 't')
17 {
18 chdir 't';
19 require File::Spec;
20 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
21 }
22 else
23 {
24 unshift @INC, $location;
25 }
26 print "# INC = @INC\n";
27
f3d61276 28 plan tests => 51;
29 }
30
091c87b1 31# testing of Math::BigInt:Scalar (used by the testsuite),
32# primarily for interface/api and not for the math functionality
f3d61276 33
34use Math::BigInt::Scalar;
35
36my $C = 'Math::BigInt::Scalar'; # pass classname to sub's
37
38# _new and _str
9b924220 39my $x = $C->_new("123"); my $y = $C->_new("321");
40ok (ref($x),'SCALAR'); ok ($C->_str($x),123); ok ($C->_str($y),321);
f3d61276 41
42# _add, _sub, _mul, _div
43
9b924220 44ok ($C->_str($C->_add($x,$y)),444);
45ok ($C->_str($C->_sub($x,$y)),123);
46ok ($C->_str($C->_mul($x,$y)),39483);
47ok ($C->_str($C->_div($x,$y)),123);
f3d61276 48
9b924220 49ok ($C->_str($C->_mul($x,$y)),39483);
50ok ($C->_str($x),39483);
51ok ($C->_str($y),321);
52my $z = $C->_new("2");
53ok ($C->_str($C->_add($x,$z)),39485);
f3d61276 54my ($re,$rr) = $C->_div($x,$y);
55
9b924220 56ok ($C->_str($re),123); ok ($C->_str($rr),2);
f3d61276 57
58# is_zero, _is_one, _one, _zero
59ok ($C->_is_zero($x),0);
60ok ($C->_is_one($x),0);
61
62ok ($C->_is_one($C->_one()),1); ok ($C->_is_one($C->_zero()),0);
63ok ($C->_is_zero($C->_zero()),1); ok ($C->_is_zero($C->_one()),0);
64
65# is_odd, is_even
66ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero()),0);
67ok ($C->_is_even($C->_one()),0); ok ($C->_is_even($C->_zero()),1);
68
69# _digit
9b924220 70$x = $C->_new("123456789");
f3d61276 71ok ($C->_digit($x,0),9);
72ok ($C->_digit($x,1),8);
73ok ($C->_digit($x,2),7);
74ok ($C->_digit($x,-1),1);
75ok ($C->_digit($x,-2),2);
76ok ($C->_digit($x,-3),3);
77
78# _copy
9b924220 79$x = $C->_new("12356");
80ok ($C->_str($C->_copy($x)),12356);
f3d61276 81
82# _acmp
9b924220 83$x = $C->_new("123456789");
84$y = $C->_new("987654321");
f3d61276 85ok ($C->_acmp($x,$y),-1);
86ok ($C->_acmp($y,$x),1);
87ok ($C->_acmp($x,$x),0);
88ok ($C->_acmp($y,$y),0);
89
90# _div
9b924220 91$x = $C->_new("3333"); $y = $C->_new("1111");
92ok ($C->_str( scalar $C->_div($x,$y)),3);
93$x = $C->_new("33333"); $y = $C->_new("1111"); ($x,$y) = $C->_div($x,$y);
94ok ($C->_str($x),30); ok ($C->_str($y),3);
95$x = $C->_new("123"); $y = $C->_new("1111");
96($x,$y) = $C->_div($x,$y); ok ($C->_str($x),0); ok ($C->_str($y),123);
f3d61276 97
98# _num
9b924220 99$x = $C->_new("12345"); $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,12345);
f3d61276 100
101# _len
9b924220 102$x = $C->_new("12345"); $x = $C->_len($x); ok (ref($x)||'',''); ok ($x,5);
f3d61276 103
104# _and, _or, _xor
9b924220 105$x = $C->_new("3"); $y = $C->_new("4"); ok ($C->_str( $C->_or($x,$y)),7);
106$x = $C->_new("1"); $y = $C->_new("4"); ok ($C->_str( $C->_xor($x,$y)),5);
107$x = $C->_new("7"); $y = $C->_new("3"); ok ($C->_str( $C->_and($x,$y)),3);
f3d61276 108
109# _pow
9b924220 110$x = $C->_new("2"); $y = $C->_new("4"); ok ($C->_str( $C->_pow($x,$y)),16);
111$x = $C->_new("2"); $y = $C->_new("5"); ok ($C->_str( $C->_pow($x,$y)),32);
112$x = $C->_new("3"); $y = $C->_new("3"); ok ($C->_str( $C->_pow($x,$y)),27);
f3d61276 113
114
f3d61276 115# _check
9b924220 116$x = $C->_new("123456789");
f3d61276 117ok ($C->_check($x),0);
118ok ($C->_check(123),'123 is not a reference');
119
120# done
121
1221;
123