public bool IsAnswerRequestValid(SudokuAnswerRequest answerRequest)
 {
     return(answerRequest.edittedBoard.GetLength(0) == 9 &&
            answerRequest.edittedBoard.GetLength(1) == 9 &&
            answerRequest.originalBoard.GetLength(0) == 9 &&
            answerRequest.originalBoard.GetLength(1) == 9);
 }
        public bool IsAnswerCorrect(SudokuAnswerRequest answerRequest)
        {
            SudokuValue[,] solutionToOriginalBoard = answerRequest.originalBoard;

            bool hasFoundSolution = UseBackTrackingAlgorithmToFindSolution(solutionToOriginalBoard);

            if (hasFoundSolution)
            {
                return(CheckIfSudokuBoardsAreEqual(answerRequest.originalBoard, answerRequest.edittedBoard));
            }

            return(false);
        }
Exemple #3
0
        public void IsAnswerCorrect_AnswerShouldBeIncorrect_ReturnsFalse()
        {
            // Arrange
            SudokuAnswerRequest answerRequest = new SudokuAnswerRequest();

            answerRequest.originalBoard = GetValidFormattedBoard();
            answerRequest.edittedBoard  = GetValidFormattedBoard();

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

            // Assert
            Assert.IsFalse(actual, "Should return false");
        }
        public ActionResult <SudokuSolution> Submit(SudokuAnswerRequest answerRequest)
        {
            if (_service.IsAnswerRequestValid(answerRequest))
            {
                bool isCorrect = _service.IsAnswerCorrect(answerRequest);

                return(new SudokuSolution()
                {
                    isSuccessful = isCorrect
                });
            }

            return(BadRequest());
        }
Exemple #5
0
        public void IsAnswerRequestValid_RequestWillBeInvalid_ReturnsFalse()
        {
            // Arrange
            SudokuAnswerRequest request = new SudokuAnswerRequest()
            {
                edittedBoard  = new SudokuValue[1, 2],
                originalBoard = new SudokuValue[3, 9]
            };

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

            // Assert
            Assert.IsFalse(actual, "Should return false");
        }
Exemple #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");
        }