9 # to locate the testing files
10 my $location = $0; $location =~ s/bigints.t//i;
13 @INC = qw(../t/lib); # testing with the core distribution
15 unshift @INC, '../lib'; # for testing manually
20 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
24 unshift @INC, $location;
26 print "# INC = @INC\n";
31 # testing of Math::BigInt::BitVect, primarily for interface/api and not for the
34 use Math::BigInt::Scalar;
36 my $C = 'Math::BigInt::Scalar'; # pass classname to sub's
39 my $x = $C->_new(\"123"); my $y = $C->_new(\"321");
40 ok (ref($x),'SCALAR'); ok (${$C->_str($x)},123); ok (${$C->_str($y)},321);
42 # _add, _sub, _mul, _div
44 ok (${$C->_str($C->_add($x,$y))},444);
45 ok (${$C->_str($C->_sub($x,$y))},123);
46 ok (${$C->_str($C->_mul($x,$y))},39483);
47 ok (${$C->_str($C->_div($x,$y))},123);
49 ok (${$C->_str($C->_mul($x,$y))},39483);
50 ok (${$C->_str($x)},39483);
51 ok (${$C->_str($y)},321);
52 my $z = $C->_new(\"2");
53 ok (${$C->_str($C->_add($x,$z))},39485);
54 my ($re,$rr) = $C->_div($x,$y);
56 ok (${$C->_str($re)},123); ok (${$C->_str($rr)},2);
58 # is_zero, _is_one, _one, _zero
59 ok ($C->_is_zero($x),0);
60 ok ($C->_is_one($x),0);
62 ok ($C->_is_one($C->_one()),1); ok ($C->_is_one($C->_zero()),0);
63 ok ($C->_is_zero($C->_zero()),1); ok ($C->_is_zero($C->_one()),0);
66 ok ($C->_is_odd($C->_one()),1); ok ($C->_is_odd($C->_zero()),0);
67 ok ($C->_is_even($C->_one()),0); ok ($C->_is_even($C->_zero()),1);
70 $x = $C->_new(\"123456789");
71 ok ($C->_digit($x,0),9);
72 ok ($C->_digit($x,1),8);
73 ok ($C->_digit($x,2),7);
74 ok ($C->_digit($x,-1),1);
75 ok ($C->_digit($x,-2),2);
76 ok ($C->_digit($x,-3),3);
79 $x = $C->_new(\"12356");
80 ok (${$C->_str($C->_copy($x))},12356);
83 $x = $C->_new(\"123456789");
84 $y = $C->_new(\"987654321");
85 ok ($C->_acmp($x,$y),-1);
86 ok ($C->_acmp($y,$x),1);
87 ok ($C->_acmp($x,$x),0);
88 ok ($C->_acmp($y,$y),0);
91 $x = $C->_new(\"3333"); $y = $C->_new(\"1111");
92 ok (${$C->_str( scalar $C->_div($x,$y))},3);
93 $x = $C->_new(\"33333"); $y = $C->_new(\"1111"); ($x,$y) = $C->_div($x,$y);
94 ok (${$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);
99 $x = $C->_new(\"12345"); $x = $C->_num($x); ok (ref($x)||'',''); ok ($x,12345);
102 $x = $C->_new(\"12345"); $x = $C->_len($x); ok (ref($x)||'',''); ok ($x,5);
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);
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);
116 # $x = $C->_new(\"-2"); $y = $C->_new(\"4"); ok ($C->_acmp($x,$y),-1);
119 $x = $C->_new(\"123456789");
120 ok ($C->_check($x),0);
121 ok ($C->_check(123),'123 is not a reference');