public void ValidateGroupOfNine_ShouldReturnTrue_IfArrayIsValid()
        {
            var validGroup = new int[] { 3, 2, 1, 4, 5, 6, 7, 8, 9 };
            var result     = new SudokuChecker().ValidateGroupOfNine(validGroup);

            Assert.IsTrue(result);
        }
        public void ValidateGroupOfNine_ShouldReturnFalse_IfArrayDoesNotContainAllDigits()
        {
            var invalidGroup = new int[] { 1, 2, 3, 3, 5, 6, 7, 8, 9 };
            var result       = new SudokuChecker().ValidateGroupOfNine(invalidGroup);

            Assert.IsFalse(result);
        }
        public void ValidateGroupOfNine_ShouldReturnFalse_IfArrayIsTooLong()
        {
            var tooLong = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var result  = new SudokuChecker().ValidateGroupOfNine(tooLong);

            Assert.IsFalse(result);
        }
        public void ValidateGroupOfNine_ShouldReturnFalse_IfArrayIsTooShort()
        {
            var tooShort = new int[] { 1, 2 };
            var result   = new SudokuChecker().ValidateGroupOfNine(tooShort);

            Assert.IsFalse(result);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            char[,] grid =
            {
                { '5', '3', '4', '6', '7', '8', '9', '1', '2' },
                { '6', '7', '2', '1', '9', '5', '3', '4', '8' },
                { '1', '9', '8', '3', '4', '2', '5', '6', '7' },
                { '8', '5', '9', '7', '6', '1', '4', '2', '3' },
                { '4', '2', '6', '8', '5', '3', '7', '9', '1' },
                { '7', '1', '3', '9', '2', '4', '8', '5', '6' },
                { '9', '6', '1', '5', '3', '7', '2', '8', '4' },
                { '2', '8', '7', '4', '1', '9', '6', '3', '5' },
                { '3', '4', '5', '2', '8', '6', '1', '7', '9' }
            };

            var sudokuBoard = new SudokuChecker(grid);

            bool ValidBoard = sudokuBoard.IsValid();

            if (ValidBoard == true)
            {
                Console.WriteLine("Numbers of Sudoku board are correct");
            }
            else
            {
                Console.WriteLine("Numbers of Sudoku board are incorrect, please check your board");
            }
        }
Ejemplo n.º 6
0
        private bool CheckRows(char[][] board)
        {
            for (int i = 0; i < 9; i++)
            {
                var sudokuChecker = new SudokuChecker();
                for (int j = 0; j < 9; j++)
                {
                    if (!sudokuChecker.AddChar(board[i][j]))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public void Test()
        {
            var grid = new[] {
                new [] { ".", "4", ".", ".", ".", ".", ".", ".", "." },
                new [] { ".", ".", "4", ".", ".", ".", ".", ".", "." },
                new [] { ".", ".", ".", "1", ".", ".", "7", ".", "." },
                new [] { ".", ".", ".", ".", ".", ".", ".", ".", "." },
                new [] { ".", ".", ".", "3", ".", ".", ".", "6", "." },
                new [] { ".", ".", ".", ".", ".", "6", ".", "9", "." },
                new [] { ".", ".", ".", ".", "1", ".", ".", ".", "." },
                new [] { ".", ".", ".", ".", ".", ".", "2", ".", "." },
                new [] { ".", ".", ".", "8", ".", ".", ".", ".", "." }
            };

            SudokuChecker.Run(grid);
        }
Ejemplo n.º 8
0
        private bool CheckSquares(char[][] board)
        {
            for (int startIPoint = 0; startIPoint < 9; startIPoint += 3)
            {
                for (int startJPoint = 0; startJPoint < 9; startJPoint += 3)
                {
                    var sudokuChecker = new SudokuChecker();
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            if (!sudokuChecker.AddChar(board[startIPoint + i][startJPoint + j]))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
        public void ValidateGridShape_ShouldReturnTrue_IfGridIsValid()
        {
            var result = new SudokuChecker().ValidateGridShape(validGrid);

            Assert.IsTrue(result);
        }
        public void ValidateGridShape_ShouldReturnFalse_IfTooFewRows()
        {
            var result = new SudokuChecker().ValidateGridShape(gridTooFewRows);

            Assert.IsFalse(result);
        }