public void IncludesRequest()
        {
            // Make sure the array includes the prime requested
            const int p     = 5;
            var       upToP = Eratosthenes.Sieve(p);

            Assert.That(upToP[^ 1], Is.GreaterThanOrEqualTo(p));
        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]));
            }
        }
Ejemplo n.º 3
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];
Ejemplo n.º 4
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());
 }