public void CheckPrime_OnlyNonPrime() { var prime = new PrimeNumberCheck(); prime.CheckPrime("6"); prime.CheckPrime("8"); prime.CheckPrime("12"); Assert.Throws <InvalidOperationException>(() => prime.GetPrimeNumbers()); }
public void CheckPrime_OnlyPrime() { var prime = new PrimeNumberCheck(); prime.CheckPrime("11"); prime.CheckPrime("2"); prime.CheckPrime("3"); Assert.AreEqual("2, 3, 11", prime.GetPrimeNumbers()); }
public static void Main(string[] args) { var prime = new PrimeNumberCheck(); var running = true; while (running) { PrintMenu(); var option = Console.ReadLine(); try { switch (option) { case "1": Console.Write("Number: "); var input = Console.ReadLine(); var result = prime.CheckPrime(input); Console.WriteLine(); Console.WriteLine("Number is " + (result ? "prime" : "not prime")); break; case "2": var str = prime.GetPrimeNumbers(); Console.WriteLine(); Console.WriteLine("Numbers: " + str); break; case "3": prime.AddNext(); break; case "4": running = false; break; default: Console.WriteLine(); Console.WriteLine("Invalid Option"); break; } } catch (ArgumentException aE) { Console.WriteLine(); Console.WriteLine(aE.Message + ", requires a number please try again"); } catch (InvalidOperationException iOe) { Console.WriteLine(); Console.WriteLine(iOe.Message + ", please add some numbers before printing the list"); } } }
public void CheckPrime_Combination() { var prime = new PrimeNumberCheck(); prime.CheckPrime("6"); prime.CheckPrime("3"); prime.CheckPrime("8"); prime.CheckPrime("5"); prime.CheckPrime("2"); prime.CheckPrime("12"); prime.CheckPrime("13"); prime.CheckPrime("9"); Assert.AreEqual("2, 3, 5, 13", prime.GetPrimeNumbers()); }