File: 03_large_int.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 (27 lines) | stat: -rw-r--r-- 706 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
use Test::More tests => 4;

use strict;
use warnings;
use Config;

use_ok('Math::BaseCalc');

if ($Config{use64bitint} eq 'define') {
  my $x = do {use integer; 2**63-1};
  roundtrip36( $x, '1y2p0ij32e8e7' );
} else {
  my $x = do {use integer; 2**31-1};
  roundtrip36( $x, 'zik0zj' );
}

sub roundtrip36 {
  my ($int, $int_base36) = @_;

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