my $location = $0; $location =~ s/mbi_rand.t//;
unshift @INC, $location; # to locate the testing files
chdir 't' if -d 't';
- $count = 500;
+ $count = 128;
plan tests => $count*2;
}
use Math::BigInt;
my $c = 'Math::BigInt';
-my $length = 200;
+my $length = 128;
# If you get a failure here, please re-run the test with the printed seed
# value as input: perl t/mbi_rand.t seed
my $seed = int(rand(65537)); print "# seed: $seed\n"; srand($seed);
-my ($A,$B,$ADB,$AMB,$la,$lb);
+my ($A,$B,$As,$Bs,$ADB,$AMB,$la,$lb);
+my $two = Math::BigInt->new(2);
for (my $i = 0; $i < $count; $i++)
{
# length of A and B
$la = int(rand($length)+1); $lb = int(rand($length)+1);
- $A = ''; $B = '';
+ $As = ''; $Bs = '';
# we create the numbers from "patterns", e.g. get a random number and a
# random count and string them together. This means things like
# "100000999999999999911122222222" are much more likely. If we just strung
# together digits, we would end up with "1272398823211223" etc.
- while (length($A) < $la) { $A .= int(rand(100)) x int(rand(16)); }
- while (length($B) < $lb) { $B .= int(rand(100)) x int(rand(16)); }
- $A = $c->new($A); $B = $c->new($B);
+ while (length($As) < $la) { $As .= int(rand(100)) x int(rand(16)); }
+ while (length($Bs) < $lb) { $Bs .= int(rand(100)) x int(rand(16)); }
+ $As =~ s/^0+//; $Bs =~ s/^0+//;
+ $A = $c->new($As); $B = $c->new($Bs);
# print "# A $A\n# B $B\n";
if ($A->is_zero() || $B->is_zero())
{
# $X = ($A/$B)*$B + 2 * ($A % $B) - ($A % $B);
($ADB,$AMB) = $A->copy()->bdiv($B);
print "# ". join(' ',Math::BigInt::Calc->_base_len()),"\n"
- unless ok ($ADB*$B+2*$AMB-$AMB,$A);
+ unless ok ($ADB*$B+$two*$AMB-$AMB,$As);
# swap 'em and try this, too
# $X = ($B/$A)*$A + $B % $A;
($ADB,$AMB) = $B->copy()->bdiv($A);
print "# ". join(' ',Math::BigInt::Calc->_base_len()),"\n"
- unless ok ($ADB*$A+2*$AMB-$AMB,$B);
+ unless ok ($ADB*$A+$two*$AMB-$AMB,$Bs);
}