Beispiel #1
0
        public void ListPrimeNumbers_ShouldThrowArgumentException_IfInputIsZero()
        {
            //arrange
            var sut = new PrimeNumberServiceAlgorithm1();


            //act
            //assert
            Assert.Throws(typeof(ArgumentException), () => sut.ListPrimeNumbers(0));
        }
Beispiel #2
0
        public void ListPrimeNumbers_WithNNumberAsInput_ShouldReturnFirstNPrimes(int n)
        {
            //arrange
            var sut = new PrimeNumberServiceAlgorithm1();

            //act
            var primes = sut.ListPrimeNumbers(n);

            //assert
            Assert.AreEqual(n, primes.Count);
        }
Beispiel #3
0
        public void ListPrimeNumbers_With1AsInput_ShouldReturn2AsPrimeNumber()
        {
            //arrange
            var sut = new PrimeNumberServiceAlgorithm1();

            //act
            var primes = sut.ListPrimeNumbers(1);

            //assert
            Assert.AreEqual(1, primes.Count);
            Assert.AreEqual(2, primes[0]);
        }
Beispiel #4
0
        public void ListPrimeNumbers_With5AsInput_ShouldReturnFirst5PrimeNumbers()
        {
            //arrange
            var sut            = new PrimeNumberServiceAlgorithm1();
            var expectedPrimes = new int[] { 2, 3, 5, 7, 11 };

            //act
            var primes = sut.ListPrimeNumbers(5);

            //assert
            Assert.AreEqual(5, primes.Count);
            Assert.That(expectedPrimes, Is.EquivalentTo(primes));
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter number : ");

            try
            {
                int input = GetNumber();
                var primeNumberService = new PrimeNumberServiceAlgorithm1();
                var primes             = primeNumberService.ListPrimeNumbers(input);

                var printString = "\t";

                for (int i = 0; i <= primes.Count; i++)
                {
                    if (i > 0)
                    {
                        printString = $"{primes[i - 1]} \t";
                    }

                    for (int j = 0; j < primes.Count; j++)
                    {
                        if (i == 0)
                        {
                            printString += $"{primes[j]} \t";
                        }
                        else
                        {
                            printString += $"{string.Concat(primes[i - 1] * primes[j])} \t";
                        }
                    }
                    Console.WriteLine(printString);
                    printString = string.Empty;
                }
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected error!");
            }
            Console.Read();
        }