[libmath-prime-util-perl] 39/59: Tests for random primes, fix for random primes on 5.6.2

Partha P. Mukherjee ppm-guest at moszumanska.debian.org
Thu May 21 18:44:59 UTC 2015


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

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

commit 23d03cd069bc368bbbf2a26248ab91fafb3e81c4
Author: Dana Jacobsen <dana at acm.org>
Date:   Sun Jul 8 14:07:47 2012 -0600

    Tests for random primes, fix for random primes on 5.6.2
---
 lib/Math/Prime/Util.pm    |  6 +++---
 lib/Math/Prime/Util/PP.pm |  4 ++--
 t/81-bignum.t             | 36 +++++++++++++++++++++++++++++++++---
 3 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/lib/Math/Prime/Util.pm b/lib/Math/Prime/Util.pm
index df0010d..7057bbf 100644
--- a/lib/Math/Prime/Util.pm
+++ b/lib/Math/Prime/Util.pm
@@ -21,7 +21,7 @@ our @EXPORT_OK = qw(
                      next_prime  prev_prime
                      prime_count prime_count_lower prime_count_upper prime_count_approx
                      nth_prime nth_prime_lower nth_prime_upper nth_prime_approx
-                     random_prime random_ndigit_prime random_nbit_prime
+                     random_prime random_ndigit_prime random_nbit_prime random_maurer_prime
                      factor all_factors moebius euler_phi
                      ExponentialIntegral LogarithmicIntegral RiemannR
                    );
@@ -145,8 +145,8 @@ sub _validate_positive_integer {
   croak "Parameter '$n' must be >= $min" if defined $min && $n < $min;
   croak "Parameter '$n' must be <= $max" if defined $max && $n > $max;
   if ($n <= $_Config{'maxparam'}) {
-    $_[0] = $n->as_number() if ref($n) eq 'Math::BigFloat';
-    $_[0] = int($n->bstr) if ref($n) eq 'Math::BigInt';
+    $_[0] = $_[0]->as_number() if ref($_[0]) eq 'Math::BigFloat';
+    $_[0] = int($_[0]->bstr) if ref($_[0]) eq 'Math::BigInt';
   } elsif (ref($n) ne 'Math::BigInt') {
     croak "Parameter '$n' outside of integer range" if !defined $bigint::VERSION;
     $_[0] = Math::BigInt->new("$n"); # Make $n a proper bigint object
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index eaef23f..ce6116b 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -60,8 +60,8 @@ sub _validate_positive_integer {
   croak "Parameter '$n' must be >= $min" if defined $min && $n < $min;
   croak "Parameter '$n' must be <= $max" if defined $max && $n > $max;
   if ($n <= ~0) {
-    $_[0] = $n->as_number() if ref($n) eq 'Math::BigFloat';
-    $_[0] = int($n->bstr) if ref($n) eq 'Math::BigInt';
+    $_[0] = $_[0]->as_number() if ref($_[0]) eq 'Math::BigFloat';
+    $_[0] = int($_[0]->bstr) if ref($_[0]) eq 'Math::BigInt';
   } elsif (ref($n) ne 'Math::BigInt') {
     croak "Parameter '$n' outside of integer range" if !defined $bigint::VERSION;
     $_[0] = Math::BigInt->new("$n"); # Make $n a proper bigint object
diff --git a/t/81-bignum.t b/t/81-bignum.t
index 1c318f6..bc71f0d 100644
--- a/t/81-bignum.t
+++ b/t/81-bignum.t
@@ -66,6 +66,7 @@ plan tests => 0 +
               scalar(keys %factors) +
               scalar(keys %allfactors) +
               2 +  # moebius, euler_phi
+              12 +  # random primes
               0;
 
 use bigint;     #  <--------------- We're testing large numbers here:  > 2^64
@@ -92,7 +93,16 @@ use Math::Prime::Util qw/
   next_prime
   prev_prime
   is_strong_pseudoprime
+  random_prime
+  random_ndigit_prime
+  random_nbit_prime
+  random_maurer_prime
 /;
+# TODO:  is_strong_lucas_pseudoprime
+#        ExponentialIntegral
+#        LogarithmicIntegral
+#        RiemannR
+
 
 ###############################################################################
 
@@ -169,8 +179,28 @@ SKIP: {
   is( euler_phi(618970019642690137449562110), 145857122964987051805507584, "euler_phi(618970019642690137449562110)" );
 }
 
-#  ExponentialIntegral
-#  LogarithmicIntegral
-#  RiemannR
+###############################################################################
+
+my $randprime;
+
+$randprime = random_prime(147573952590750158861, 340282366920939067930896100764782952647);
+cmp_ok( $randprime, '>=', 147573952590750158861, "random range prime isn't too small");
+cmp_ok( $randprime, '<=', 340282366920939067930896100764782952647, "random range prime isn't too big");
+ok( is_prime($randprime), "random range prime is prime");
+
+$randprime = random_ndigit_prime(25);
+cmp_ok( $randprime, '>', 10**24, "random 25-digit prime isn't too small");
+cmp_ok( $randprime, '<', 10**25, "random 25-digit prime isn't too big");
+ok( is_prime($randprime), "random 25-digit prime is prime");
+
+$randprime = random_nbit_prime(80);
+cmp_ok( $randprime, '>', 2**79, "random 80-bit prime isn't too small");
+cmp_ok( $randprime, '<', 2**80, "random 80-bit prime isn't too big");
+ok( is_prime($randprime), "random 80-bit prime is prime");
+
+$randprime = random_maurer_prime(80);
+cmp_ok( $randprime, '>', 2**79, "random 80-bit Maurer prime isn't too small");
+cmp_ok( $randprime, '<', 2**80, "random 80-bit Maurer prime isn't too big");
+ok( is_prime($randprime), "random 80-bit Maurer prime is prime");
 
 ###############################################################################

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



More information about the Pkg-perl-cvs-commits mailing list