#!/usr/bin/ruby

# Tests for the Fermat pseudoprime generators.

# Timings:
#   27 feb 2023: 2.811s (with MPU)
#   27 feb 2023: 4.539s (without MPU)

for k in (1..4) {

    say "Testing k = #{k}"

    var lo           = k.pn_primorial*4
    var hi           = lo*100
    var omega_primes = k.omega_primes(lo, hi)

    assert_eq(omega_primes.len, k.omega_prime_count(lo, hi))

    omega_primes.grep!{ .is_composite } if (k == 1)

    for base in (2..50) {

        var this = omega_primes.grep { .is_pseudoprime(base) }
        var that = k.fermat_psp(base, lo, hi)

        this == that ||
            die "[Fermat psp] Error for k = #{k} and base = #{base} with hi = #{hi}\n#{this} != #{that}"

        this = this.grep { .is_strong_pseudoprime(base) }
        that = k.strong_fermat_psp(base, lo, hi)

        this == that ||
            die "[Strong Fermat psp] Error for k = #{k} and base = #{base} with hi = #{hi}\n#{this} != #{that}"
    }
}
