This is an automated email from the git hooks/post-receive script.

ppm-guest pushed a commit to annotated tag v0.14
in repository libmath-prime-util-perl.

commit 1f192303da2862b71b7a0aa94cde5d1ba0c55846
Author: Dana Jacobsen <d...@acm.org>
Date:   Fri Nov 23 12:57:04 2012 -0800

    Streamline random prime test, add more testing for nbit and maurer random 
primes
---
 t/16-randomprime.t | 130 ++++++++++++++++++++++++++++++++++-------------------
 t/81-bignum.t      |   4 ++
 2 files changed, 87 insertions(+), 47 deletions(-)

diff --git a/t/16-randomprime.t b/t/16-randomprime.t
index eff57e0..da06444 100644
--- a/t/16-randomprime.t
+++ b/t/16-randomprime.t
@@ -6,14 +6,67 @@ use Test::More;
 #use Math::Random::MT qw/rand/;
 #use Math::Random::MT::Auto qw/rand/;
 #sub rand { return 0.5; }
-use Math::Prime::Util qw/random_prime random_ndigit_prime is_prime/;
+use Math::Prime::Util qw/random_prime random_ndigit_prime random_nbit_prime
+                         random_maurer_prime is_prime/;
 
 my $use64 = Math::Prime::Util::prime_get_config->{'maxbits'} > 32;
 my $extra = defined $ENV{RELEASE_TESTING} && $ENV{RELEASE_TESTING};
+my $maxbits = $use64 ? 64 : 32;
 
-plan tests => 13+4 + 6*1 + 11*3 + 10*2 + 12*2 + 2*$use64 + 10*2;
+my @random_to = (2, 3, 4, 5, 6, 7, 8, 9, 100, 1000, 1000000, 4294967295);
+
+my @random_nbit_tests = ( 2 .. 6, 10, 15 .. 17, 28, 32 );
+push @random_nbit_tests, (34) if $use64;
+@random_nbit_tests = (2 .. $maxbits) if $extra;
+
+my @random_ndigit_tests = (1 .. ($use64 ? 20 : 10));
+
+my %ranges = (
+  "2 to 20" => [2,19],
+  "3 to 7" => [3,7],
+  "20 to 100" => [23,97],
+  "5678 to 9876" => [5683,9871],
+  "27767 to 88493" => [27767,88493],
+  "27764 to 88498" => [27767,88493],
+  "27764 to 88493" => [27767,88493],
+  "27767 to 88498" => [27767,88493],
+  "17051687 to 17051899" => [17051687,17051899],
+  "17051688 to 17051898" => [17051707,17051887],
+);
+
+my %range_edge = (
+  "0 to 2" => [2,2],
+  "2 to 2" => [2,2],
+  "2 to 3" => [2,3],
+  "3 to 5" => [3,5],
+  "10 to 20" => [11,19],
+  "8 to 12" => [11,11],
+  "10 to 12" => [11,11],
+  "16706143 to 16706143" => [16706143,16706143],
+  "16706142 to 16706144" => [16706143,16706143],
+  "3842610773 to 3842611109" => [3842610773,3842611109],
+  "3842610772 to 3842611110" => [3842610773,3842611109],
+);
+my %range_edge_empty = (
+  "0 to 0" => [],
+  "0 to 1" => [],
+  "2 to 1" => [],
+  "3 to 2" => [],
+  "1294268492 to 1294268778" => [],
+  "3842610774 to 3842611108" => [],
+);
+
+plan tests => 13+4+4+4
+              + (1 * scalar (keys %range_edge_empty))
+              + (3 * scalar (keys %range_edge))
+              + (2 * scalar (keys %ranges))
+              + (2 * scalar @random_to)
+              + (1 * scalar @random_ndigit_tests)
+              + (2 * scalar @random_nbit_tests)
+              + 0;
 
 my $infinity = ~0 * ~0;
+my $nrandom_range_samples = $extra ? 1000 : 50;
 
 ok(!eval { random_prime(undef); }, "random_prime(undef)");
 ok(!eval { random_prime(-3); }, "random_prime(-3)");
@@ -34,32 +87,21 @@ ok(!eval { random_ndigit_prime(0); }, 
"random_ndigit_prime(0)");
 ok(!eval { random_ndigit_prime(-5); }, "random_ndigit_prime(-5)");
 ok(!eval { random_ndigit_prime(50); }, "random_ndigit_prime(50)");
 
-my %range_edge_empty = (
-  "0 to 0" => [],
-  "0 to 1" => [],
-  "2 to 1" => [],
-  "3 to 2" => [],
-  "1294268492 to 1294268778" => [],
-  "3842610774 to 3842611108" => [],
-);
+ok(!eval { random_nbit_prime(undef); }, "random_nbit_prime(undef)");
+ok(!eval { random_nbit_prime(0); }, "random_nbit_prime(0)");
+ok(!eval { random_nbit_prime(-5); }, "random_nbit_prime(-5)");
+ok(!eval { random_nbit_prime(130); }, "random_nbit_prime(130)");
+
+ok(!eval { random_maurer_prime(undef); }, "random_maurer_prime(undef)");
+ok(!eval { random_maurer_prime(0); }, "random_maurer_prime(0)");
+ok(!eval { random_maurer_prime(-5); }, "random_maurer_prime(-5)");
+ok(!eval { random_maurer_prime(130); }, "random_maurer_prime(130)");
+
 while (my($range, $expect) = each (%range_edge_empty)) {
   my($low,$high) = $range =~ /(\d+) to (\d+)/;
   is( random_prime($low,$high), undef, "primes($low,$high) should return 
undef" );
 }
 
-my %range_edge = (
-  "0 to 2" => [2,2],
-  "2 to 2" => [2,2],
-  "2 to 3" => [2,3],
-  "3 to 5" => [3,5],
-  "10 to 20" => [11,19],
-  "8 to 12" => [11,11],
-  "10 to 12" => [11,11],
-  "16706143 to 16706143" => [16706143,16706143],
-  "16706142 to 16706144" => [16706143,16706143],
-  "3842610773 to 3842611109" => [3842610773,3842611109],
-  "3842610772 to 3842611110" => [3842610773,3842611109],
-);
 while (my($range, $expect) = each (%range_edge)) {
   my($low,$high) = $range =~ /(\d+) to (\d+)/;
   my $got = random_prime($low,$high);
@@ -68,23 +110,11 @@ while (my($range, $expect) = each (%range_edge)) {
   cmp_ok( $got, '<=', $expect->[1], "random_prime($low,$high) >= 
$expect->[1]");
 }
 
-my %ranges = (
-  "2 to 20" => [2,19],
-  "3 to 7" => [3,7],
-  "20 to 100" => [23,97],
-  "5678 to 9876" => [5683,9871],
-  "27767 to 88493" => [27767,88493],
-  "27764 to 88498" => [27767,88493],
-  "27764 to 88493" => [27767,88493],
-  "27767 to 88498" => [27767,88493],
-  "17051687 to 17051899" => [17051687,17051899],
-  "17051688 to 17051898" => [17051707,17051887],
-);
 while (my($range, $expect) = each (%ranges)) {
   my($low,$high) = $range =~ /(\d+) to (\d+)/;
   my $isprime = 1;
   my $inrange = 1;
-  for (1 .. 1000) {
+  for (1 .. $nrandom_range_samples) {
     my $got = random_prime($low,$high);
     $isprime *= is_prime($got) ? 1 : 0;
     $inrange *= (($got >= $expect->[0]) && ($got <= $expect->[1])) ? 1 : 0;
@@ -93,11 +123,10 @@ while (my($range, $expect) = each (%ranges)) {
   ok($inrange, "All returned values for $low-$high were in the range" );
 }
 
-my @to = (2, 3, 4, 5, 6, 7, 8, 9, 100, 1000, 1000000, 4294967295);
-foreach my $high (@to) {
+foreach my $high (@random_to) {
   my $isprime = 1;
   my $inrange = 1;
-  for (1 .. 1000) {
+  for (1 .. $nrandom_range_samples) {
     my $got = random_prime($high);
     $isprime *= is_prime($got) ? 1 : 0;
     $inrange *= (($got >= 2) && ($got <= $high)) ? 1 : 0;
@@ -106,14 +135,21 @@ foreach my $high (@to) {
   ok($inrange, "All returned values for $high were in the range" );
 }
 
-if ($use64) {
-  my $got = random_prime(2**34);
-  cmp_ok( $got, '<=', 2**34, "34-bit random_prime is in range");
-  ok( is_prime($got), "32-bit prime is indeed prime");
+foreach my $digits ( @random_ndigit_tests ) {
+  my $n = random_ndigit_prime($digits);
+  ok ( length($n) == $digits && is_prime($n),
+       "$digits-digit random prime is in range and prime");
+}
+
+foreach my $bits ( @random_nbit_tests ) {
+  check_bits( random_nbit_prime($bits), $bits, "nbit" );
+  check_bits( random_maurer_prime($bits), $bits, "Maurer" );
 }
 
-foreach my $digits (1 .. 10) {
-  my $got = random_ndigit_prime($digits);
-  is( length($got), $digits, "$digits-digit random prime is $digits digits");
-  ok( is_prime($got), "$digits-digit random prime is indeed prime");
+sub check_bits {
+  my($n, $bits, $what) = @_;
+  my $min = 1 << ($bits-1);
+  my $max = ~0 >> ($maxbits - $bits);
+  ok ( $n >= $min && $n <= $max && is_prime($n),
+       "$bits-bit random $what prime is in range and prime");
 }
diff --git a/t/81-bignum.t b/t/81-bignum.t
index dc3baf9..f732d8f 100644
--- a/t/81-bignum.t
+++ b/t/81-bignum.t
@@ -106,6 +106,10 @@ use Math::Prime::Util qw/
 #        LogarithmicIntegral
 #        RiemannR
 
+# Test bignum using PP
+diag "Math::Prime::Util::GMP not being used.\n"
+  unless Math::Prime::Util::prime_get_config->{gmp};
+
 
 ###############################################################################
 

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libmath-prime-util-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to