예제 #1
0
        public void FermatTest()
        {
            const long value = 16769023;

            var isPrime = PrimalityTest.Fermat(value);

            Assert.IsTrue(isPrime, "Fermat Primality Test has an incorrect result");
        }
예제 #2
0
        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;
        }
예제 #3
0
        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");
        }