public void AllPrimes()
        {
            // Make sure that all primes and only primes are returned
            var upToOneHundred = Eratosthenes.Sieve(10000);
            var primes         = Eratosthenes.GetPrimes();

            for (var i = 0; i < upToOneHundred.Length; i++)
            {
                Assert.That(upToOneHundred[i], Is.EqualTo(primes[i]));
            }
        }
Example #2
0
 /// <summary>
 /// Test if a number is prime.  For now this function is limited by the length of
 /// the array of known primes (inputs up to maxPrime squared).
 /// </summary>
 /// <param name="value">Number to test.</param>
 /// <returns>True if the number is a prime. </returns>
 public static bool IsPrime(int value)
 {
     var primes   = Eratosthenes.GetPrimes();
     var maxPrime = primes[^ 1];
Example #3
0
 /// <summary>
 /// Return an array of primes up to a given upper limit.
 /// </summary>
 /// <remarks>The getter function returns a clone of the backing field for safety.</remarks>
 public static int[] GetPrimes(int maxPrime)
 {
     return((int[])Eratosthenes.GetPrimes(maxPrime).Clone());
 }