File: 30-relations.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 (33 lines) | stat: -rw-r--r-- 1,022 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
#!/usr/bin/env perl
use strict;
use warnings;

use Test::More;
use Math::Prime::Util qw/primes
                         nth_prime nth_prime_lower nth_prime_upper nth_prime_approx
                         prime_count prime_count_lower prime_count_upper prime_count_approx
                         next_prime prev_prime
                        /;


my @trials = qw/1 2 3 4 5 6 7 17 57 89 102 1337 8573 84763 784357 1000001 2573622/;

plan tests => 5 * scalar @trials;

my $last = 0;
foreach my $n (@trials) {

  is( prime_count($n), scalar @{primes($n)}, "Prime count and scalar primes agree for $n" );

  is( prime_count($n) - prime_count($last),
      scalar @{primes( $last+1, $n )},
      "scalar primes($last+1,$n) = prime_count($n) - prime_count($last)" );

  is( prime_count(nth_prime($n)), $n, "Pi(pn)) = n for $n");

  is( nth_prime(prime_count($n)+1), next_prime($n), "p(Pi(n)+1) = next_prime(n) for $n" );

  is( nth_prime(prime_count($n)), prev_prime($n+1), "p(Pi(n)) = prev_prime(n) for $n" );

  $last = $n;
}