38# include <gtest/gtest.h>
47using namespace testing;
82TEST(Prime, next_prime_semantics)
92 for (
unsigned long n = 0; n < 2000; ++n)
95 ASSERT_TRUE(
is_prime(p)) <<
"next_prime(" << n <<
") = " << p <<
" is not prime";
96 ASSERT_GE(p, n) <<
"next_prime(" << n <<
") = " << p <<
" < " << n;
100 for (
size_t i = 0; i < 200 && i <
numPrimes; ++i)
104TEST(Prime, next_prime_takes_the_first_prime_of_the_database)
111 for (
unsigned long n =
primeList[0]; n < 20000; ++n)
116TEST(Prime, next_prime_above_the_database_is_the_smallest_prime_not_below_n)
119 for (
unsigned long n = last + 1; n <= last + 40; ++n)
128 EXPECT_THROW(
next_prime(std::numeric_limits<unsigned long>::max()),
132TEST(Prime, next_prime_number_greater_than_gives_the_smallest_prime_above_n)
139 for (
unsigned long n = 0; n < 20000; ++n)
141 unsigned long p = n + 1;
147 const unsigned long max = std::numeric_limits<unsigned long>::max();
148 for (
const unsigned long n : {
max,
max - 1,
max - 2})
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
unsigned long next_prime_number_greater_than(unsigned long n)
Find the next prime strictly greater than n.
const unsigned long primeList[]
Pre-computed array of prime numbers for fast lookup.
const size_t numPrimes
Number of primes in the pre-computed database.
bool check_primes_database()
Verify the order of the prime database.
bool is_prime(unsigned long n)
Test if a number is prime using trial division.
unsigned long next_prime(unsigned long n)
Find a prime >= n in the database, for hash table sizing.
Prime number utilities for hash tables and mathematical operations.