Beispiel #1
0
        public void GetPrimes_ReturnsPrimeNumbersUpToAndIncludingInput()
        {
            var expectedResult = new[] { 2, 3, 5, 7, 11, 13 };

            var actualResult = PrimesHelper.GetPrimesUpTo(13);

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string input;

            do
            {
                Console.WriteLine("Input a valid number (type EXIT to terminate): ");
                input = Console.ReadLine();

                if (int.TryParse(input, out var value))
                {
                    var table = PrimesHelper.GetPrimesTable(value);
                    Console.WriteLine();
                    Console.WriteLine(PrimesTableParser.ParseToString(table));
                    Console.WriteLine();
                }
            } while (input.ToUpper() != "EXIT");
        }
Beispiel #3
0
        public void GetPrimesTable_ReturnsTableWithCorrectPrimeNumbersProducts()
        {
            var actualResult = PrimesHelper.GetPrimesTable(13);

            int rowId    = 0;
            int columnId = 0;

            foreach (var row in actualResult.Products)
            {
                foreach (var column in row)
                {
                    Assert.Equal(column, actualResult.Primes[rowId] * actualResult.Primes[columnId]);

                    columnId++;
                }
                columnId = 0;
                rowId++;
            }
        }
Beispiel #4
0
        public void GetPrimesTable_ReturnsTableWithCorrectPrimeNumbers()
        {
            var actualResult = PrimesHelper.GetPrimesTable(3);

            Assert.Equal(actualResult.Primes, new[] { 2, 3 });
        }
Beispiel #5
0
 public void IsPrime_ReturnsCorrectValue(int number, bool expectedResult)
 {
     Assert.Equal(expectedResult, PrimesHelper.IsPrime(number));
 }