File: 22-aks-prime.t

package info (click to toggle)
libmath-prime-util-perl 0.73-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,796 kB
  • sloc: perl: 24,676; ansic: 11,471; makefile: 26; python: 24
file content (52 lines) | stat: -rw-r--r-- 1,816 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env perl
use strict;
use warnings;

use Test::More;
use Math::Prime::Util qw/is_aks_prime/;

my $use64 = Math::Prime::Util::prime_get_config->{'maxbits'} > 32;
my $extra = defined $ENV{EXTENDED_TESTING} && $ENV{EXTENDED_TESTING};
my $ispp = !Math::Prime::Util::prime_get_config->{xs};

plan tests =>   6   # range
              + 1   # small number
              + 2   # medium numbers
              + 1*$extra
              + 0;

# Note: AKS testing is *extremely* sparse due to its lack of speed.
#       This does almost nothing to test whether AKS is working properly.
#
# If you are concerned about AKS correctness, you really need to use
# the xt/primality-aks.pl test.

ok(!eval { is_aks_prime(undef); }, "is_prime(undef)");
ok( is_aks_prime(2),  '2 is prime');
ok(!is_aks_prime(1),  '1 is not prime');
ok(!is_aks_prime(0),  '0 is not prime');
ok(!is_aks_prime(-1), '-1 is not prime');
ok(!is_aks_prime(-2), '-2 is not prime');

# Simple number (cought by sqrt test)
is( is_aks_prime(877), 1, "is_aks_prime(877) is true" );

# This test can take a very long time if mulmods are very slow (e.g. on
# UltraSPARC).  With the B+V improvements this should be fast enough for
# the little example that we are ok.

SKIP: {
  # If we're pure Perl, then this is definitely too slow.
  # Arguably we should check to see if they have the GMP code.
  skip "Skipping PP AKS on PP -- just too slow.", 1 if $ispp;
  # The least number that performs the full test with either implementation.
  is( is_aks_prime(69197), 1, "is_aks_prime(69197) is true" );
}

# A small composite that runs the real primality test.
is( is_aks_prime(69199), 0, "is_aks_prime(69199) is false" );

if ($extra) {
  # A composite (product of two 5-digit primes)
  is( is_aks_prime(1262952907), 0, "is_aks_prime(1262952907) is false" );
}