Commit | Line | Data |
0716bf9b |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test; |
5 | |
6 | BEGIN |
7 | { |
8 | $| = 1; |
9 | # chdir 't' if -d 't'; |
10 | unshift @INC, '../lib'; # for running manually |
11 | plan tests => 29; |
12 | } |
13 | |
14 | # testing of Math::BigInt::Calc, primarily for interface/api and not for the |
15 | # math functionality |
16 | |
17 | use Math::BigInt::Calc; |
18 | |
19 | my $s123 = \'123'; my $s321 = \'321'; |
20 | # _new and _str |
21 | my $x = _new($s123); my $u = _str($x); |
22 | ok ($$u,123); ok ($x->[0],123); ok (@$x,1); |
23 | my $y = _new($s321); |
24 | |
25 | # _add, _sub, _mul, _div |
26 | |
27 | ok (${_str(_add($x,$y))},444); |
28 | ok (${_str(_sub($x,$y))},123); |
29 | ok (${_str(_mul($x,$y))},39483); |
30 | ok (${_str(_div($x,$y))},123); |
31 | |
32 | # division with reminder |
33 | my $z = _new(\"111"); |
34 | _mul($x,$y); |
35 | ok (${_str($x)},39483); |
36 | _add($x,$z); |
37 | ok (${_str($x)},39594); |
38 | my ($re,$rr) = _div($x,$y); |
39 | |
40 | ok (${_str($re)},123); ok (${_str($rr)},111); |
41 | |
42 | # _copy |
43 | $x = _new(\"12356"); |
44 | ok (${_str(_copy($x))},12356); |
45 | |
46 | # digit |
47 | $x = _new(\"123456789"); |
48 | ok (_digit($x,0),9); |
49 | ok (_digit($x,1),8); |
50 | ok (_digit($x,2),7); |
51 | ok (_digit($x,-1),1); |
52 | ok (_digit($x,-2),2); |
53 | ok (_digit($x,-3),3); |
54 | |
55 | # is_zero, _is_one, _one, _zero |
56 | $x = _new(\"12356"); |
57 | ok (_is_zero($x),0); |
58 | ok (_is_one($x),0); |
59 | |
60 | # _zeros |
61 | $x = _new(\"1256000000"); ok (_zeros($x),6); |
62 | $x = _new(\"152"); ok (_zeros($x),0); |
63 | $x = _new(\"123000"); ok (_zeros($x),3); |
64 | |
65 | ok (_is_one(_one()),1); ok (_is_one(_zero()),0); |
66 | ok (_is_zero(_zero()),1); ok (_is_zero(_one()),0); |
67 | |
68 | ok (_check($x),0); |
69 | ok (_check(123),'123 is not a reference'); |
70 | |
71 | # done |
72 | |
73 | 1; |