public void ShouldWriteMultiplicationTableToConsole()
        {
            var expected =
            "|    |  2 |  3 |  5 |\r\n" +
            "| -- | -- | -- | -- |\r\n" +
            "|  2 |  4 |  6 | 10 |\r\n" +
            "|  3 |  6 |  9 | 15 |\r\n" +
            "|  5 | 10 | 15 | 25 |\r\n";

            var textWriter = new StringWriter();
            var target = new MultiplicationTableWriter();
            target.Write(textWriter, new MultiplicationTable(new[] { 2, 3, 5 }));

            Assert.Equal(expected, textWriter.ToString());
        }
        public void ShouldWriteMultiplicationTableToConsole()
        {
            var expected =
                "|    |  2 |  3 |  5 |\r\n" +
                "| -- | -- | -- | -- |\r\n" +
                "|  2 |  4 |  6 | 10 |\r\n" +
                "|  3 |  6 |  9 | 15 |\r\n" +
                "|  5 | 10 | 15 | 25 |\r\n";

            var textWriter = new StringWriter();
            var target     = new MultiplicationTableWriter();

            target.Write(textWriter, new MultiplicationTable(new[] { 2, 3, 5 }));

            Assert.Equal(expected, textWriter.ToString());
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.Write("How many prime number do you want to generate: ");
            string numberText = Console.ReadLine();
            int number;
            while (!int.TryParse(numberText, out number) || number < 1)
            {
                Console.Write("Invalid format or incorrect number. Try again: ");
                numberText = Console.ReadLine();
            }

            var generator = new PrimeNumberGenerator();
            var table = new MultiplicationTable(generator.Generate().Take(Math.Min(10, number)).ToArray());
            var writer = new MultiplicationTableWriter();
            writer.Write(Console.Out, table);

            Console.Read();
        }