Forgot to update the MANIFEST.
[p5sagit/p5-mst-13.2.git] / lib / 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
31# testing of Math::BigInt::BitVect, primarily for interface/api and not for the
32# math functionality
33
34use Math::BigInt::Scalar;
35
36my $C = 'Math::BigInt::Scalar'; # pass classname to sub's
37
38# _new and _str
39my $x = $C->_new(\"123"); my $y = $C->_new(\"321");
40ok (ref($x),'SCALAR'); ok (${$C->_str($x)},123); ok (${$C->_str($y)},321);
41
42# _add, _sub, _mul, _div
43
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);
48
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);
54my ($re,$rr) = $C->_div($x,$y);
55
56ok (${$C->_str($re)},123); ok (${$C->_str($rr)},2);
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
70$x = $C->_new(\"123456789");
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
79$x = $C->_new(\"12356");
80ok (${$C->_str($C->_copy($x))},12356);
81
82# _acmp
83$x = $C->_new(\"123456789");
84$y = $C->_new(\"987654321");
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
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);
97
98# _num
99$x = $C->_new(\"12345"); $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,12345);
100
101# _len
102$x = $C->_new(\"12345"); $x = $C->_len($x); ok (ref($x)||'',''); ok ($x,5);
103
104# _and, _or, _xor
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);
108
109# _pow
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);
113
114
115# should not happen:
116# $x = $C->_new(\"-2"); $y = $C->_new(\"4"); ok ($C->_acmp($x,$y),-1);
117
118# _check
119$x = $C->_new(\"123456789");
120ok ($C->_check($x),0);
121ok ($C->_check(123),'123 is not a reference');
122
123# done
124
1251;
126