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()); }
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"); }
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"); }
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"); }
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"); }
public bool IsSolutionRequestValid(SudokuSolutionRequest solutionRequest) { SudokuValue[,] board = solutionRequest.currentBoard; return(board.GetLength(0) == 9 && board.GetLength(1) == 9); }