예제 #1
0
        public SudokuSolution FindSolution(SudokuSolutionRequest solutionRequest)
        {
            SudokuValue[,] board = solutionRequest.currentBoard;

            bool hasFoundSolution = UseBackTrackingAlgorithmToFindSolution(board);

            return(new SudokuSolution()
            {
                isSuccessful = hasFoundSolution, solution = board
            });
        }
        public ActionResult <SudokuSolution> GetSolution(SudokuSolutionRequest solutionRequest)
        {
            if (_service.IsSolutionRequestValid(solutionRequest))
            {
                SudokuSolution solution = _service.FindSolution(solutionRequest);

                return(solution);
            }

            return(BadRequest());
        }
예제 #3
0
        public void IsSolutionRequestValid_RequestWillBeValid_ReturnsTrue()
        {
            // Arrange
            SudokuSolutionRequest request = new SudokuSolutionRequest()
            {
                currentBoard = new SudokuValue[9, 9]
            };

            // Act
            bool actual = _service.IsSolutionRequestValid(request);

            // Assert
            Assert.IsTrue(actual, "Should return true");
        }
예제 #4
0
        public void FindSolution_NoSolutionFound_ReturnsFalse()
        {
            // Arrange
            SudokuSolutionRequest request = new SudokuSolutionRequest()
            {
                currentBoard = GetInvalidFormattedBoard()
            };

            // Act
            SudokuSolution solution = _service.FindSolution(request);

            // Assert
            Assert.IsFalse(solution.isSuccessful, "Should return false");
        }
예제 #5
0
        public void IsSolutionRequestValid_RequestWillBeInvalid_ReturnsFalse()
        {
            // Arrange
            SudokuSolutionRequest request = new SudokuSolutionRequest()
            {
                currentBoard = new SudokuValue[2, 2]
            };

            // Act
            bool actual = _service.IsSolutionRequestValid(request);

            // Assert
            Assert.IsFalse(actual, "Should return false");
        }
예제 #6
0
        public void IsAnswerCorrect_AnswerShouldBeCorrect_ReturnsTrue()
        {
            // Arrange
            SudokuAnswerRequest answerRequest = new SudokuAnswerRequest();

            answerRequest.originalBoard = GetValidFormattedBoard();

            SudokuSolutionRequest solutionRequest = new SudokuSolutionRequest()
            {
                currentBoard = GetValidFormattedBoard()
            };

            answerRequest.edittedBoard = _service.FindSolution(solutionRequest).solution;

            // Act
            bool actual = _service.IsAnswerCorrect(answerRequest);

            // Assert
            Assert.IsTrue(actual, "Should return true");
        }
예제 #7
0
        public bool IsSolutionRequestValid(SudokuSolutionRequest solutionRequest)
        {
            SudokuValue[,] board = solutionRequest.currentBoard;

            return(board.GetLength(0) == 9 && board.GetLength(1) == 9);
        }