[libmath-prime-util-perl] 28/43: Improve test coverage
Partha P. Mukherjee
ppm-guest at moszumanska.debian.org
Thu May 21 18:53:08 UTC 2015
This is an automated email from the git hooks/post-receive script.
ppm-guest pushed a commit to annotated tag v0.40
in repository libmath-prime-util-perl.
commit 3b6009c37b712e48e9ae115fbd27826e19749a5a
Author: Dana Jacobsen <dana at acm.org>
Date: Thu Apr 3 15:33:33 2014 -0700
Improve test coverage
---
MANIFEST | 1 +
TODO | 29 -----------------
bench/bench-primearray.pl | 1 +
lib/Math/Prime/Util/PP.pm | 4 +++
t/13-primecount.t | 5 ++-
t/17-pseudoprime.t | 6 ++--
t/18-functions.t | 74 +++++++++++++++++++++++-------------------
t/19-moebius.t | 2 ++
t/23-random-certs.t | 32 ++++++++++++++++++
t/32-iterators.t | 12 +++++--
t/50-factoring.t | 2 ++
t/80-pp.t | 82 ++++++++++++++++++++++++++++++++++++++++++++---
12 files changed, 178 insertions(+), 72 deletions(-)
diff --git a/MANIFEST b/MANIFEST
index 31a067d..486cdc3 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -104,6 +104,7 @@ t/20-primorial.t
t/21-conseq-lcm.t
t/22-aks-prime.t
t/23-primality-proofs.t
+t/23-random-certs.t
t/24-partitions.t
t/30-relations.t
t/31-threading.t
diff --git a/TODO b/TODO
index 55c161e..021d8b0 100644
--- a/TODO
+++ b/TODO
@@ -68,32 +68,3 @@
- Ensure a fast path for Math::GMP from MPU -> MPU:GMP -> GMP, and back.
- znlog better implementation
-
-- coverage:
- util.c: modinverse, divmod (from dlp_prho), Ei with x > 2000
- lmo.c: legendre phi
- factor.c: factor with a perfect power: e.g. 2*3^2 and 5*7 * 5*7, dlp_prho
- Util: random_maurer_prime_with_cert
- random_shawe_taylor_prime_with_cert
- random_proven_prime_with_cert
- miller_rabin_random non-GMP
- primorial non-GMP
- pn_primorial non-GMP
- partitions non-GMP
- generic forprimes
- generic forcomposites
- generic fordivisors
- prime_iterator to GMP
- prime_iterator to PP
- next_prime to PP
- prev_prime to PP
- prime_count to PP
- factor to PP
- PP: prime_precalc, prime_memfree
- _tiny_prime_count
- is_bpsw_prime
- partitions, primorial, nth_prime_approx, gcd, lcm,cheb_theta/psi
- divisor_sum with overflowing k=2
- trial_factor with bigint
- pminus1_factor with stage 2
- ecm_factor with stage 2
diff --git a/bench/bench-primearray.pl b/bench/bench-primearray.pl
index 88f0ff6..ff5bd62 100755
--- a/bench/bench-primearray.pl
+++ b/bench/bench-primearray.pl
@@ -29,6 +29,7 @@ cmpthese($count,{
$s += $_ for @primes[0..$ilimit];
die unless $s == $expect; },
'pa each' => sub { $s=0; tie my @primes, "Math::Prime::Util::PrimeArray";
+ # Note: using last inside each is Very Bad Stuff.
while(my(undef,$v) = each @primes) { last if $v > $nlimit; $s += $v; }
die $s unless $s == $expect; },
'pa shift' => sub { $s=0; tie my @primes, "Math::Prime::Util::PrimeArray";
diff --git a/lib/Math/Prime/Util/PP.pm b/lib/Math/Prime/Util/PP.pm
index a2c843b..f25fa77 100644
--- a/lib/Math/Prime/Util/PP.pm
+++ b/lib/Math/Prime/Util/PP.pm
@@ -1336,6 +1336,9 @@ sub prime_count_upper {
sub twin_prime_count {
my($low,$high) = @_;
+ if (defined $high) { _validate_positive_integer($low); }
+ else { ($low,$high) = (2, $low); }
+ _validate_positive_integer($high);
my $sum = 0;
# TODO: I suspect calling primes() on segments would be faster in most cases.
if ($high >= $low) {
@@ -1351,6 +1354,7 @@ sub twin_prime_count {
sub twin_prime_count_approx {
my($n) = @_;
+ $n = _upgrade_to_float($n) if ref($n);
my $logn = log($n);
my $li2 = ExponentialIntegral($logn) + 2.8853900817779268147198494 - ($n/$logn);
return int(1.32032363169373914785562422 * $li2 + 0.5);
diff --git a/t/13-primecount.t b/t/13-primecount.t
index 2d87671..545e8b6 100644
--- a/t/13-primecount.t
+++ b/t/13-primecount.t
@@ -89,7 +89,7 @@ plan tests => 0 + 1
+ scalar(keys %intervals)
+ 1
+ 5 + 2*$extra # prime count specific methods
- + 3; # twin prime counts
+ + 3 + (($isxs && $use64) ? 1 : 0); # twin prime counts
ok( eval { prime_count(13); 1; }, "prime_count in void context");
@@ -180,3 +180,6 @@ if ($extra) {
is(twin_prime_count(13,31), 2, "twin prime count 13 to 31");
is(twin_prime_count(10**8,10**8+34587), 137, "twin prime count 10^8 to +34587");
is(twin_prime_count(654321), 5744, "twin prime count 654321");
+if ($isxs && $use64) {
+ is(twin_prime_count(1000000000123456), 1177209242446, "twin prime count 1000000000123456");
+}
diff --git a/t/17-pseudoprime.t b/t/17-pseudoprime.t
index 978e5f6..2c015ce 100644
--- a/t/17-pseudoprime.t
+++ b/t/17-pseudoprime.t
@@ -79,9 +79,9 @@ if ($use64) {
push @{$pseudoprimes{psp3}}, 4398117272641;
push @{$pseudoprimes{3}}, 1099558795087;
push @{$pseudoprimes{lucas}}, 2199055761527;
- push @{$pseudoprimes{slucas}}, 12598021314449;
- push @{$pseudoprimes{eslucas}}, 10099386070337;
- push @{$pseudoprimes{aeslucas1}}, 10071551814917;
+ push @{$pseudoprimes{slucas}}, 4294967311,4294967357,12598021314449;
+ push @{$pseudoprimes{eslucas}}, 4294967311,4294967357,10099386070337;
+ push @{$pseudoprimes{aeslucas1}}, 4294967311,4294967357,10071551814917;
push @{$pseudoprimes{aeslucas2}}, 34372519409;
}
diff --git a/t/18-functions.t b/t/18-functions.t
index e4dd417..e9d66a6 100644
--- a/t/18-functions.t
+++ b/t/18-functions.t
@@ -9,26 +9,6 @@ use Math::Prime::Util qw/
my $infinity = 20**20**20;
-plan tests => 3 + 6 + 1 + 16 + 11 + 9 + 6;
-
-eval { LogarithmicIntegral(-1); };
-like($@, qr/invalid/i, "li(-1) is invalid");
-eval { RiemannR(0); };
-like($@, qr/invalid/i, "R(0) is invalid");
-eval { RiemannR(-1); };
-like($@, qr/invalid/i, "R(-1) is invalid");
-
-cmp_ok( ExponentialIntegral(0), '<=',-$infinity, "Ei(0) is -infinity");
-cmp_ok( ExponentialIntegral(-$infinity),'==', 0, "Ei(-inf) is 0" );
-cmp_ok( ExponentialIntegral($infinity), '>=', $infinity, "Ei(inf) is infinity");
-
-cmp_ok( LogarithmicIntegral(0), '==', 0, "li(0) is 0");
-cmp_ok( LogarithmicIntegral(1), '<=',-$infinity, "li(1) is -infinity");
-cmp_ok( LogarithmicIntegral($infinity), '>=', $infinity, "li(inf) is infinity");
-
-# Example used in Math::Cephes
-cmp_closeto( ExponentialIntegral(2.2), 5.732614700, 1e-06, "Ei(2.2)");
-
my %eivals = (
-10 => -0.00000415696892968532438,
-0.5 => -0.55977359477616,
@@ -46,14 +26,10 @@ my %eivals = (
20 => 25615652.664056588820481,
40 => 6039718263611241.5783592,
41 => 16006649143245041.110700,
+ 79 => 2.61362206325045575e+32,
);
-while (my($n, $ein) = each (%eivals)) {
- cmp_closeto( ExponentialIntegral($n), $ein, 0.00000001 * abs($ein), "Ei($n) ~= $ein");
-}
-
-# In pari these are: -eint1(-log($n))
-my %livals = (
+my %livals = ( # In pari these are: -eint1(-log($n))
0 => 0,
1.01 => -4.0229586739299358695031,
2 => 1.0451637801174927848446,
@@ -67,10 +43,6 @@ my %livals = (
100000000000 => 4118066400.6216115150394,
);
-while (my($n, $lin) = each (%livals)) {
- cmp_closeto( LogarithmicIntegral($n), $lin, 0.00000001 * abs($lin), "li($n) ~= $lin");
-}
-
# Values from T. R. Nicely for comparison
my %rvals = (
1.01 => 1.0060697180622924796117,
@@ -83,9 +55,6 @@ my %rvals = (
10000000000 => 455050683.30684692446315,
18446744073709551615 => 4.25656284014012122706963685602e17,
);
-while (my($n, $rin) = each (%rvals)) {
- cmp_closeto( RiemannR($n), $rin, 0.00000001 * abs($rin), "R($n) ~= $rin");
-}
my %rzvals = (
2 => 0.6449340668482264364724151666,
@@ -95,6 +64,45 @@ my %rzvals = (
8.5 => 0.0028592508824156277133439825,
20.6 => 0.0000006293391573578212882457,
);
+
+
+plan tests => 3 + 6 + 1
+ + scalar(keys(%eivals))
+ + scalar(keys(%livals))
+ + scalar(keys(%rvals))
+ + scalar(keys(%rzvals))
+ ;
+
+eval { LogarithmicIntegral(-1); };
+like($@, qr/invalid/i, "li(-1) is invalid");
+eval { RiemannR(0); };
+like($@, qr/invalid/i, "R(0) is invalid");
+eval { RiemannR(-1); };
+like($@, qr/invalid/i, "R(-1) is invalid");
+
+cmp_ok( ExponentialIntegral(0), '<=',-$infinity, "Ei(0) is -infinity");
+cmp_ok( ExponentialIntegral(-$infinity),'==', 0, "Ei(-inf) is 0" );
+cmp_ok( ExponentialIntegral($infinity), '>=', $infinity, "Ei(inf) is infinity");
+
+cmp_ok( LogarithmicIntegral(0), '==', 0, "li(0) is 0");
+cmp_ok( LogarithmicIntegral(1), '<=',-$infinity, "li(1) is -infinity");
+cmp_ok( LogarithmicIntegral($infinity), '>=', $infinity, "li(inf) is infinity");
+
+# Example used in Math::Cephes
+cmp_closeto( ExponentialIntegral(2.2), 5.732614700, 1e-06, "Ei(2.2)");
+
+while (my($n, $ein) = each (%eivals)) {
+ cmp_closeto( ExponentialIntegral($n), $ein, 0.00000001 * abs($ein), "Ei($n) ~= $ein");
+}
+
+while (my($n, $lin) = each (%livals)) {
+ cmp_closeto( LogarithmicIntegral($n), $lin, 0.00000001 * abs($lin), "li($n) ~= $lin");
+}
+
+while (my($n, $rin) = each (%rvals)) {
+ cmp_closeto( RiemannR($n), $rin, 0.00000001 * abs($rin), "R($n) ~= $rin");
+}
+
while (my($n, $zin) = each (%rzvals)) {
cmp_closeto( RiemannZeta($n), $zin, 0.00000001 * abs($zin), "Zeta($n) ~= $zin");
}
diff --git a/t/19-moebius.t b/t/19-moebius.t
index dc086e4..11415b1 100644
--- a/t/19-moebius.t
+++ b/t/19-moebius.t
@@ -276,6 +276,7 @@ my @legendre_sums = (
[100000, 7, 18053],
[10000, 8, 1711],
[1000000, 168, 78331],
+ [800000, 213, 63739],
);
my @gcds = (
@@ -337,6 +338,7 @@ my @znlogs = (
);
if ($usexs) {
push @znlogs, [ [5678,5,10007], 8620]; # 5678 = 5^8620 mod 10007
+ push @znlogs, [ [5675,5,10000019], 2003974]; # 5675 = 5^2003974 mod 10000019
}
my %powers = (
diff --git a/t/23-random-certs.t b/t/23-random-certs.t
new file mode 100644
index 0000000..d54773f
--- /dev/null
+++ b/t/23-random-certs.t
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More;
+use Math::Prime::Util qw/is_prime verify_prime
+ random_maurer_prime_with_cert
+ random_shawe_taylor_prime_with_cert
+ random_proven_prime_with_cert
+ /;
+
+use Math::BigInt try=>"GMP,Pari";
+
+plan tests => 3*2;
+
+{
+ my($n,$cert) = random_maurer_prime_with_cert(80);
+ ok( is_prime($n), "Random Maurer prime returns a prime" );
+ ok( verify_prime($cert), " with a valid certificate" );
+}
+
+{
+ my($n,$cert) = random_shawe_taylor_prime_with_cert(80);
+ ok( is_prime($n), "Random Shawe-Taylor prime returns a prime" );
+ ok( verify_prime($cert), " with a valid certificate" );
+}
+
+{
+ my($n,$cert) = random_proven_prime_with_cert(80);
+ ok( is_prime($n), "Random proven prime returns a prime" );
+ ok( verify_prime($cert), " with a valid certificate" );
+}
diff --git a/t/32-iterators.t b/t/32-iterators.t
index c810bb7..da01f97 100644
--- a/t/32-iterators.t
+++ b/t/32-iterators.t
@@ -13,13 +13,13 @@ my $use64 = Math::Prime::Util::prime_get_config->{'maxbits'} > 32;
my $broken64 = (18446744073709550592 == ~0);
plan tests => 8 # forprimes errors
- + 12 + 6 # forprimes simple
+ + 12 + 7 # forprimes simple
+ 3 # forcomposites simple
+ 2 # fordivisors simple
+ 3 # iterator errors
+ 7 # iterator simple
+ 2 # forprimes/iterator nesting
- + 2 # forprimes BigInt/BigFloat
+ + 3 # forprimes BigInt/BigFloat
+ 3 # oo iterator errors
+ 7 # oo iterator simple
+ 25 # oo iterator methods
@@ -67,6 +67,9 @@ ok(!eval { forprimes { 1 } 5.6; }, "forprimes abc");
{ my @t; forprimes { push @t, $_ } 2147483647,2147483659;
is_deeply( [@t], [2147483647,2147483659], "forprimes 2147483647,2147483659" );
}
+{ my @t; forprimes { push @t, $_ } 3842610774,3842611326;
+ is_deeply( [@t], [3842611109,3842611139,3842611163,3842611181,3842611211,3842611229,3842611249,3842611259,3842611261,3842611291,3842611301], "forprimes 3842610774,3842611326" );
+}
{ my @t; forcomposites { push @t, $_ } 2147483647,2147483659;
is_deeply( [@t], [qw/2147483648 2147483649 2147483650 2147483651 2147483652 2147483653 2147483654 2147483655 2147483656 2147483657 2147483658/], "forcomposites 2147483647,2147483659" );
}
@@ -151,6 +154,11 @@ ok(!eval { prime_iterator(4.5); }, "iterator 4.5");
forprimes { push @t, $_ } Math::BigFloat->new("5"), Math::BigFloat->new("11");
is_deeply( [@t], [5,7,11], "forprimes with BigFloat range" );
}
+{my $it = prime_iterator(Math::BigInt->new("68719476736"));
+ is_deeply( [map { $it->() } 1..3],
+ [68719476767,68719476851,68719476853],
+ "iterator 3 primes with BigInt start" );
+}
# Test new object iterator
ok(!eval { prime_iterator_object(-2); }, "iterator -2");
diff --git a/t/50-factoring.t b/t/50-factoring.t
index 49cfbce..ce0d5ed 100644
--- a/t/50-factoring.t
+++ b/t/50-factoring.t
@@ -33,6 +33,7 @@ my @testn = qw/0 1 2 3 4 5 6 7 8 16 57 64 377 9592 30107 78498 664579 5761455
2231139 2463289 3008891 5115953 6961021 8030207 10486123
10893343 12327779 701737021
549900 10000142
+ 392498
/;
my @testn64 = qw/37607912018 346065536839 600851475143
@@ -43,6 +44,7 @@ my @testn64 = qw/37607912018 346065536839 600851475143
6469693230 200560490130 7420738134810 304250263527210
13082761331670030 614889782588491410
440091295252541 5333042142001571
+ 79127989298
/;
push @testn, @testn64 if $use64;
diff --git a/t/80-pp.t b/t/80-pp.t
index b6033ec..8b6a315 100644
--- a/t/80-pp.t
+++ b/t/80-pp.t
@@ -250,6 +250,7 @@ plan tests => 2 +
3 + scalar(keys %small_single) + scalar(keys %small_range) +
2*scalar(keys %primegaps) + 8 + 1 + 1 + 1 +
scalar(keys %pivals_small) + scalar(keys %pi_intervals) +
+ 6 + # PC, pc approx
2*scalar(keys %pivals_small) + scalar(keys %nthprimes_small) +
4 + scalar(keys %pseudoprimes) +
scalar(keys %eivals) + scalar(keys %livals) + scalar(keys %rvals) + scalar(keys %rzvals) +
@@ -258,17 +259,20 @@ plan tests => 2 +
10 + 7*3 + # factoring subs
1 + # HOLF
($extra ? 3 : 0) + # HOLF extra
+ 3 + # factor stage 2
10 + # AKS
($use64 ? 3 : 2) + # Lucas and BLS75 primality proofs
4 + # M-R and Lucas on bigint
- 13 + # Misc util.pm functions
+ 2 + # PC and NP approx
+ 26 + # Misc util.pm functions
scalar(keys %ipp) + # is_prob_prime
1;
-use Math::Prime::Util qw/primes prime_count_approx prime_count_lower
+use Math::Prime::Util qw/primes
+ prime_count_approx nth_prime_approx
prime_get_config prime_set_config
consecutive_integer_lcm
- chebyshev_theta chebyshev_psi
+ primorial pn_primorial partitions miller_rabin_random
is_prob_prime
/;
use Math::BigInt;
@@ -281,7 +285,17 @@ require_ok 'Math::Prime::Util::PrimalityProving';
*primes = \&Math::Prime::Util::PP::primes;
*prime_count = \&Math::Prime::Util::PP::prime_count;
+ *prime_count_lower = \&Math::Prime::Util::PP::prime_count_lower;
+ *prime_count_upper = \&Math::Prime::Util::PP::prime_count_upper;
*nth_prime = \&Math::Prime::Util::PP::nth_prime;
+ undef *prime_count_approx;
+ undef *nth_prime_approx;
+ *prime_count_approx = \&Math::Prime::Util::PP::prime_count_approx;
+ *nth_prime_approx = \&Math::Prime::Util::PP::nth_prime_approx;
+
+ *twin_prime_count = \&Math::Prime::Util::PP::twin_prime_count;
+ *nth_twin_prime = \&Math::Prime::Util::PP::nth_twin_prime;
+ *twin_prime_count_approx = \&Math::Prime::Util::PP::twin_prime_count_approx;
*is_prime = \&Math::Prime::Util::PP::is_prime;
*next_prime = \&Math::Prime::Util::PP::next_prime;
@@ -298,10 +312,15 @@ require_ok 'Math::Prime::Util::PrimalityProving';
*factor = \&Math::Prime::Util::PP::factor;
+ *gcd = \&Math::Prime::Util::PP::gcd;
+ *lcm = \&Math::Prime::Util::PP::lcm;
+
*moebius = \&Math::Prime::Util::PP::moebius;
*euler_phi = \&Math::Prime::Util::PP::euler_phi;
*mertens = \&Math::Prime::Util::PP::mertens;
*exp_mangoldt = \&Math::Prime::Util::PP::exp_mangoldt;
+ *chebyshev_theta= \&Math::Prime::Util::PP::chebyshev_theta;
+ *chebyshev_psi = \&Math::Prime::Util::PP::chebyshev_psi;
*RiemannR = \&Math::Prime::Util::PP::RiemannR;
*RiemannZeta = \&Math::Prime::Util::PP::RiemannZeta;
@@ -394,6 +413,15 @@ while (my($range, $expect) = each (%pi_intervals)) {
is( prime_count($low,$high), $expect, "prime_count($range) = $expect");
}
+# These are small enough they should be exact.
+is( prime_count_lower(450), 87, "prime_count_lower(450)" );
+is( prime_count_upper(450), 87, "prime_count_upper(450)" );
+# Make sure these are about right
+cmp_closeto( prime_count_lower(1234567), 95327, 10, "prime_count_lower(1234567) in range" );
+cmp_closeto( prime_count_upper(1234567), 95413, 10, "prime_count_upper(1234567) in range" );
+cmp_closeto( prime_count_lower(412345678), 21956686, 1000, "prime_count_lower(412345678) in range" );
+cmp_closeto( prime_count_upper(412345678), 21959328, 1000, "prime_count_upper(412345678) in range" );
+
###############################################################################
while (my($n, $pin) = each (%pivals_small)) {
@@ -591,6 +619,18 @@ if ($extra) {
}
}
+##### Some numbers that go to stage 2 of tests
+{
+ my $nbig = Math::BigInt->new("9087500560545072247139");
+ my @nfac;
+ @nfac = sort {$a<=>$b} Math::Prime::Util::PP::pminus1_factor($nbig,1000,10000);
+ is_deeply( [@nfac], ["24133","376559091722747783"], "p-1 stage 2 finds factors of $nbig" );
+ @nfac = sort {$a<=>$b} Math::Prime::Util::PP::trial_factor($nbig, 50000);
+ is_deeply( [@nfac], ["24133","376559091722747783"], "trial factor finds factors of $nbig" );
+ @nfac = sort {$a<=>$b} Math::Prime::Util::PP::ecm_factor($nbig, 10,1000,100);
+ is_deeply( [@nfac], ["24133","376559091722747783"], "ecm factor finds factors of $nbig" );
+}
+
##### AKS primality test. Be very careful with performance.
is( is_aks_prime(1), 0, "AKS: 1 is composite (less than 2)" );
is( is_aks_prime(2), 1, "AKS: 2 is prime" );
@@ -603,7 +643,7 @@ is( is_aks_prime(70747), 0, "AKS: 70747 is composite (n mod r)" );
SKIP: {
skip "Skipping PP AKS test without EXTENDED_TESTING", 2 unless $extra;
diag "32-bit Perl will be very slow for AKS" unless $use64;
- is( is_aks_prime(101), 1, "AKS: 101 is prime (passed anr test)" );
+ is( is_aks_prime(1009), 1, "AKS: 1009 is prime (passed anr test)" );
is( is_aks_prime(74513), 0, "AKS: 74513 is composite (failed anr test)" );
}
@@ -635,6 +675,13 @@ if ($use64) {
}
{
+ my $ntha = nth_prime_approx(1287248);
+ ok( $ntha >= 20274907 && $ntha <= 20284058, "nth_prime_approx(1287248) in range" );
+ my $pca = prime_count_approx(128722248);
+ ok( $pca >= 7309252 && $pca <= 7310044, "prime_count_approx(128722248) in range" );
+}
+
+{
# Test some functions usually not tested in Util.pm
my $xs = prime_get_config->{'xs'};
my $gmp = prime_get_config->{'gmp'};
@@ -668,6 +715,33 @@ if ($use64) {
is( is_prob_prime($n), $isp, "is_prob_prime($n) should be $isp" );
}
+ is( primorial(24), 223092870, "primorial(24)" );
+ is( primorial(118), "31610054640417607788145206291543662493274686990", "primorial(118)" );
+ is( pn_primorial(7), 510510, "pn_primorial(7)" );
+ is( partitions(74), 7089500, "partitions(74)" );
+ is( miller_rabin_random(4294967281, 20), "0", "Miller-Rabin random 40 on composite" );
+
+ { my @t;
+ Math::Prime::Util::_generic_forprimes(sub {push @t,$_}, 2387234,2387303);
+ is_deeply( [@t], [2387237,2387243,2387249,2387269,2387291,2387299,2387303],
+ "generic forprimes 2387234,2387303" );
+ }
+ { my @t;
+ Math::Prime::Util::_generic_forcomposites(sub {push @t,$_}, 15202630,15202641);
+ is_deeply( [@t], [15202630,15202632,15202634,15202635,15202636,15202638,15202640,15202641], "generic forcomposites 15202630,15202641" );
+ }
+ { my $k = 0;
+ Math::Prime::Util::_generic_fordivisors(sub {$k += $_+int(sqrt($_))},92834);
+ is( $k, 168921, "generic fordivisors: d|92834: k+=d+int(sqrt(d))" );
+ }
+
+ is( gcd(-30,-90,90), 30, "gcd(-30,-90,90) = 30" );
+ is( lcm(11926,78001,2211), 2790719778, "lcm(11926,78001,2211) = 2790719778" );
+
+ is( twin_prime_count(4321), 114, "twin_prime_count(4321)" );
+ cmp_closeto( twin_prime_count_approx(Math::BigInt->new("412345678412345678412345678")), "149939117920176008847283", 1e10, "twin_prime_count_approx(412345678412345678412345678)" );
+ is( nth_twin_prime(977), 76871, "nth_twin_prime(977)" );
+
prime_set_config(xs=>$xs, gmp=>$gmp, verbose=>$verbose);
}
--
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