File: 04-bigint.t

package info (click to toggle)
libmath-basecalc-perl 1.019-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 144 kB
  • sloc: perl: 212; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 698 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use Test::More;
use strict;
use warnings;

eval "use Math::BigInt";
if ($@) {
  plan skip_all => "Requires Math::BigInt";
} else {
  plan tests => 4;
}

use_ok('Math::BaseCalc');

my $bignum = Math::BigInt->new(2) ** 120 + 7;

roundtrip36( $bignum, '24q5bylddqo566k7npiubn5z' );


sub roundtrip36 {
  my ($num, $expect) = @_;

  my $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']);
  my $base36 = $calc36->to_base($num);
  is($base36, $expect, "to_base has done proper conversion of $num");
  my $num2 = $calc36->from_base($base36);
  is($num2, $num->numify, "$num has roundtripped");
  $num2 = $calc36->from_base($expect);
  is($num2, $num->numify, "from_base correct for $expect ($num)");
}