예제 #1
0
        public void AddNext_EmptyList()
        {
            var prime = new PrimeNumberCheck();

            prime.AddNext();
            Assert.AreEqual("2", prime.GetPrimeNumbers());
        }
예제 #2
0
        public void AddNext_ListNotEmpty()
        {
            var prime = new PrimeNumberCheck();

            prime.AddPrime(11);
            prime.AddPrime(2);
            prime.AddPrime(3);
            prime.AddNext();
            Assert.AreEqual("2, 3, 11, 13", prime.GetPrimeNumbers());
        }
예제 #3
0
        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");
                }
            }
        }