public void FermatTest() { const long value = 16769023; var isPrime = PrimalityTest.Fermat(value); Assert.IsTrue(isPrime, "Fermat Primality Test has an incorrect result"); }
private long GetRandomPrime(uint[] primeNumbers, Random random) { var index = random.Next(2, primeNumbers.Length - 1); var result = primeNumbers[index]; if (!PrimalityTest.Fermat(result)) throw new InvalidOperationException($"The number is not prime: {result}"); return result; }
public void PrimeTestFirst10000000ItemsTest() { var result = SieveAtkin.GetPrimeNumbers(limit: 10000000).ToArray(); var valid = true; for (int i = 0; i < result.Length; i++) { if (!PrimalityTest.Fermat(result[i])) { valid = false; break; } } Assert.IsTrue(valid, "Not prime found"); }