[libmath-prime-util-perl] 10/35: Add tests for factor_exp and liouville

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


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

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

commit c170460d2f0003d39767c1394c3551d3d43ad830
Author: Dana Jacobsen <dana at acm.org>
Date:   Mon Oct 21 17:18:21 2013 -0700

    Add tests for factor_exp and liouville
---
 TODO             |  2 +-
 t/50-factoring.t | 19 ++++++++++++++-----
 t/81-bignum.t    | 16 +++++++++++++++-
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO
index 83e148c..f8a4e6d 100644
--- a/TODO
+++ b/TODO
@@ -57,4 +57,4 @@
   algorithm).  The PP code isn't doing that, which means we're doing lots of
   extra primality checks, which aren't cheap in PP.
 
-- tests for factor_exp.
+- Add parallel gap verifier to examples.
diff --git a/t/50-factoring.t b/t/50-factoring.t
index 1eec553..32af300 100644
--- a/t/50-factoring.t
+++ b/t/50-factoring.t
@@ -3,7 +3,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Math::Prime::Util qw/factor all_factors is_prime/;
+use Math::Prime::Util qw/factor factor_exp all_factors is_prime/;
 
 my $use64 = Math::Prime::Util::prime_get_config->{'maxbits'} > 32;
 my $extra = defined $ENV{EXTENDED_TESTING} && $ENV{EXTENDED_TESTING};
@@ -74,7 +74,7 @@ my %all_factors = (
       0 => [],
 );
 
-plan tests =>  (2 * scalar @testn) + scalar(keys %all_factors) + 10*9 + 8 + 1;
+plan tests =>  (3 * scalar @testn) + scalar(keys %all_factors) + 10*9 + 8 + 1;
 
 foreach my $n (@testn) {
   my @f = factor($n);
@@ -87,11 +87,14 @@ foreach my $n (@testn) {
   # Are they all prime?
   my $isprime = 1; $isprime *= is_prime($_) for @f;
   if ($n < 2) {
-    ok( !$isprime, "All factors [ $facstring ] of $n are not prime" );
+    ok( !$isprime, "   each factor is not prime" );
   } else {
-    ok( $isprime, "All factors [ $facstring ] of $n are prime" );
+    ok(  $isprime, "   each factor is prime" );
   }
-};
+
+  # Does factor_exp return the appropriate rearrangement?
+  is_deeply( [factor_exp($n)], [linear_to_exp(@f)], "   factor_exp looks right" );
+}
 
 while (my($n, $divisors) = each(%all_factors)) {
   is_deeply( [all_factors($n)], $divisors, "all_factors($n)" );
@@ -136,3 +139,9 @@ is( scalar factor(5), 1, "scalar factor(5) should be 1" );
 is( scalar factor(6), 2, "scalar factor(6) should be 2" );
 is( scalar factor(30107), 4, "scalar factor(30107) should be 4" );
 is( scalar factor(174636000), 15, "scalar factor(174636000) should be 15" );
+
+sub linear_to_exp {
+  my %exponents;
+  my @factors = grep { !$exponents{$_}++ } @_;
+  return (map { [$_, $exponents{$_}] } @factors);
+}
diff --git a/t/81-bignum.t b/t/81-bignum.t
index 2068ac6..8301ca0 100644
--- a/t/81-bignum.t
+++ b/t/81-bignum.t
@@ -73,9 +73,10 @@ plan tests =>  0
              + scalar(keys %pseudoprimes)
              + 6   # PC lower, upper, approx
              + 6*2*$extra # more PC tests
-             + scalar(keys %factors)
+             + 2*scalar(keys %factors)
              + scalar(keys %allfactors)
              + 7   # moebius, euler_phi, jordan totient, divsum, znorder
+             + 2   # liouville
              + 15  # random primes
              + 0;
 
@@ -93,12 +94,14 @@ use Math::Prime::Util qw/
   nth_prime_upper
   nth_prime_approx
   factor
+  factor_exp
   all_factors
   moebius
   euler_phi
   jordan_totient
   divisor_sum
   znorder
+  liouville
   ExponentialIntegral
   LogarithmicIntegral
   RiemannR
@@ -200,6 +203,7 @@ SKIP: {
   skip "Your 64-bit Perl is broken, skipping bignum factoring tests", scalar(keys %factors) + scalar(keys %allfactors) if $broken64;
   while (my($n, $factors) = each(%factors)) {
     is_deeply( [factor($n)], $factors, "factor($n)" );
+    is_deeply( [factor_exp($n)], [linear_to_exp(@$factors)], "factor_exp($n)" );
   }
   while (my($n, $allfactors) = each(%allfactors)) {
     is_deeply( [all_factors($n)], $allfactors, "all_factors($n)" );
@@ -229,6 +233,10 @@ SKIP: {
 }
 
 ###############################################################################
+is( liouville(      48981631802481400359696467), -1, "liouville(a x b x c) = -1" );
+is( liouville(16091004845064967313564246070637),  1, "liouville(a x b x c x d) = 1" );
+
+###############################################################################
 
 my $randprime;
 
@@ -302,3 +310,9 @@ sub check_pcbounds {
 }
 
 ###############################################################################
+
+sub linear_to_exp {   # Convert factor() output to factor_exp() output
+  my %exponents;
+  my @factors = grep { !$exponents{$_}++ } @_;
+  return (map { [$_, $exponents{$_}] } @factors);
+}

-- 
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