Commit | Line | Data |
f3d61276 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test; |
5 | |
6 | BEGIN |
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 | |
34 | use Math::BigInt::Scalar; |
35 | |
36 | my $C = 'Math::BigInt::Scalar'; # pass classname to sub's |
37 | |
38 | # _new and _str |
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); |
41 | |
42 | # _add, _sub, _mul, _div |
43 | |
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); |
48 | |
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); |
55 | |
56 | ok (${$C->_str($re)},123); ok (${$C->_str($rr)},2); |
57 | |
58 | # is_zero, _is_one, _one, _zero |
59 | ok ($C->_is_zero($x),0); |
60 | ok ($C->_is_one($x),0); |
61 | |
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); |
64 | |
65 | # is_odd, is_even |
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); |
68 | |
69 | # _digit |
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); |
77 | |
78 | # _copy |
79 | $x = $C->_new(\"12356"); |
80 | ok (${$C->_str($C->_copy($x))},12356); |
81 | |
82 | # _acmp |
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); |
89 | |
90 | # _div |
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); |
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"); |
120 | ok ($C->_check($x),0); |
121 | ok ($C->_check(123),'123 is not a reference'); |
122 | |
123 | # done |
124 | |
125 | 1; |
126 | |