public void FindNthPrimeTest() { MyMathClass target = new MyMathClass(); int index = 1; long expected = 2; long actual; actual = target.FindNthPrime(index); Assert.AreEqual(expected, actual); index = 2; expected = 3; actual = target.FindNthPrime(index); Assert.AreEqual(expected, actual); index = 10; expected = 29; actual = target.FindNthPrime(index); Assert.AreEqual(expected, actual); index = 100; expected = 541; actual = target.FindNthPrime(index); Assert.AreEqual(expected, actual); index = 149; expected = 859; actual = target.FindNthPrime(index); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { MyMathClass mathClass = new MyMathClass(); DateTime start = DateTime.Now; int n; //n = 1; //Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); //n = 2; //Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); //n = 3; //Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); //n = 5; //Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); //n = 8; //Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); n = 10001; Console.WriteLine("Prime number for n = " + n.ToString() + " is: " + mathClass.FindNthPrime(n)); Console.WriteLine("Time it took is: " + (DateTime.Now - start).ToString()); Console.ReadKey(); }
static void Main(string[] args) { Stopwatch stopwatch = Stopwatch.StartNew(); MyMathClass mathClass = new MyMathClass(); long sumOfPrimes = mathClass.GetSumOfPrimesUpTo(TARGET); stopwatch.Stop(); Console.WriteLine("Sum of primes below " + TARGET.ToString() + " is " + sumOfPrimes.ToString()); Console.WriteLine("Elapsed time is: " + stopwatch.ElapsedMilliseconds + " milliseconds"); Console.ReadKey(); }
public void FindNthPrimeInvalidArgumentsFailTest() { MyMathClass target = new MyMathClass(); long actual; try { actual = target.FindNthPrime(0); Assert.Fail("ArgumentOutOfRangeException failed to generate"); } catch (ArgumentOutOfRangeException e) { return; // pass condition reached } catch(Exception) { Assert.Fail("Unknown exception thrown"); } }
public void GetSumOfPrimesUpToTest() { MyMathClass target = new MyMathClass(); long number = 2000000; long expected = 142913828922; long actual; actual = target.GetSumOfPrimesUpTo(number); Assert.AreEqual(expected, actual); }