public void N2_GetAll() { var primes = new PrimeNumbers(2).ToArray(); Assert.Single(primes); Assert.Equal(2, primes[0]); }
public void CountPrimesUpTo10K() { var primes = new PrimeNumbers(10000); Assert.Equal(10000, primes.N); Assert.Equal(1229, primes.Count); }
public void N4_GetAll() { var primes = new PrimeNumbers(4).ToArray(); Assert.Equal(2, primes.Length); Assert.Equal(2, primes[0]); Assert.Equal(3, primes[1]); }
public void N0_TestIfPrime() { var primes = new PrimeNumbers(0); Assert.Equal(0, primes.N); Assert.Equal(0, primes.Count); Assert.False(primes.IsPrime(0)); }
public void T4() { var N = 211; var primeNumbers = new PrimeNumbers(N); // the sieve var largest = primeNumbers.Last(); // using LINQ to get the largest prime less or equal to N. Assert.Equal(211, largest); }
public void T2() { var N = 211; var primeNumbers = new PrimeNumbers(N); // the sieve var numberOfPrimes = primeNumbers.Count; // will be 47 if N = 211 Assert.Equal(47, numberOfPrimes); }
public void T3() { var N = 211; var primeNumbers = new PrimeNumbers(N); // the sieve Assert.True(primeNumbers.IsPrime(101)); // true Assert.False(primeNumbers.IsPrime(210)); // false Assert.True(primeNumbers.IsPrime(211)); // true }
public void IsPrimeTest() { var primes = new PrimeNumbers(10000); for (long i = 0; i <= primes.N; i++) { var expected = primes.IsPrime(i); Assert.Equal(expected, i.IsPrime()); } }
public void N2_TestIfPrime() { var primes = new PrimeNumbers(2); Assert.Equal(2, primes.N); Assert.Equal(1, primes.Count); Assert.False(primes.IsPrime(0)); Assert.False(primes.IsPrime(1)); Assert.True(primes.IsPrime(2)); }
public void N8_GetAll() { var primes = new PrimeNumbers(7).ToArray(); Assert.Equal(4, primes.Length); Assert.Equal(2, primes[0]); Assert.Equal(3, primes[1]); Assert.Equal(5, primes[2]); Assert.Equal(7, primes[3]); }
public void N5_TestIfPrime() { var primes = new PrimeNumbers(5); Assert.Equal(5, primes.N); Assert.Equal(3, primes.Count); Assert.False(primes.IsPrime(0)); Assert.False(primes.IsPrime(1)); Assert.True(primes.IsPrime(2)); Assert.True(primes.IsPrime(3)); Assert.False(primes.IsPrime(4)); Assert.True(primes.IsPrime(5)); }
public void N103_TestIfPrime(long N, long n, bool expected) { var primes = new PrimeNumbers(N); Assert.Equal(expected, primes.IsPrime(n)); }
public void N1_GetAll() { var primes = new PrimeNumbers(1); Assert.Empty(primes); }