Exemplo n.º 1
0
        public void New_Grid_Has_Correct_Number_Of_Rows(int size)
        {
            // Given a size
            // When a new grid is created
            ProductGrid productGrid = new ProductGrid(size);

            // Then the number of rows should equal the size
            Assert.AreEqual(productGrid.Cells.GetLength(0), size);
        }
Exemplo n.º 2
0
        public void New_Grid_Returns_Correct_Number_Of_Cells(int size)
        {
            // Given a size
            // When a new grid is created
            ProductGrid productGrid = new ProductGrid(size);

            // Then the number of cells should be the square of the size
            int expectedNumberOfCells = size * size;
            Assert.AreEqual(productGrid.Cells.Length, expectedNumberOfCells);
        }
Exemplo n.º 3
0
        public void First_Row_In_Grid_Contains_Primes(int size, int[] expectedPrimes)
        {
            // Given a grid
            ProductGrid productGrid = new ProductGrid(size);

            // When the first row is extracted
            int[] actualValues = Enumerable.Range(0, size).Select(index => productGrid.Cells[0, index]).ToArray();

            // Then they should be sequential primes
            Assert.AreEqual(actualValues, expectedPrimes);
        }
Exemplo n.º 4
0
        public void Non_Header_Cells_Are_Multiples_Of_Their_First_Row_And_Column(int size, int rowIndex, int columnIndex)
        {
            // Given a grid
            ProductGrid productGrid = new ProductGrid(size);

            // When a particular cell is extracted
            int actualCellValue = productGrid.Cells[rowIndex, columnIndex];

            // Then it is a product of the first column and row
            int expectedValue = productGrid.Cells[0, columnIndex] * productGrid.Cells[rowIndex, 0];
            Assert.AreEqual(expectedValue, actualCellValue);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            int size;
            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Type a size for the grid and press return, 0 or non number to exit");
                int.TryParse(Console.ReadLine(), out size);
                Console.WriteLine();
                if (size < 1) break;

                var productGrid = new ProductGrid(size);
                for (int row = 0; row < productGrid.Cells.GetLength(0); row++)
                {
                    for (int column = 0; column < productGrid.Cells.GetLength(1); column++)
                    {
                        Console.Write(productGrid.Cells[row, column].ToString().PadLeft(8));
                    }
                    Console.WriteLine();
                }
            }
        }