public void Verify_Should_Fail_When_CurrentPuzzleState_Length_Is_Not_Equal_To_81() { PuzzleToVerifyDto puzzleToVerifyDto = new PuzzleToVerifyDto { CurrentPuzzleState = "03400700808006500000030007020000070430", OriginalPuzzleState = "034007008080065000000300070200000700710040096005000001050002000000170060600900430" }; PuzzleVerifyDto puzzleVerifyDto = _sudokuPuzzleService.Verify(puzzleToVerifyDto); Assert.IsFalse(puzzleVerifyDto.Success); }
public void Verify_Should_Fail_When_OriginalPuzzleState_Is_Empty() { PuzzleToVerifyDto puzzleToVerifyDto = new PuzzleToVerifyDto { CurrentPuzzleState = "034007008080065666666300070200000700710040096005000001050002000000170060600900430", OriginalPuzzleState = string.Empty }; PuzzleVerifyDto puzzleVerifyDto = _sudokuPuzzleService.Verify(puzzleToVerifyDto); Assert.IsFalse(puzzleVerifyDto.Success); }
public void Verify_Should_Fail_When_OriginalPuzzleState_Is_Not_Solvable() { SudokuPuzzle sudoku = CreateInValidSudokuPuzzle(); PuzzleToVerifyDto puzzleToVerifyDto = new PuzzleToVerifyDto { CurrentPuzzleState = sudoku.PuzzleState.ToString(), OriginalPuzzleState = sudoku.PuzzleState.ToString() }; PuzzleVerifyDto puzzleVerifyDto = _sudokuPuzzleService.Verify(puzzleToVerifyDto); Assert.IsFalse(puzzleVerifyDto.Success); }
public void Verify_Should_Return_28_CorrectIndexes() { PuzzleToVerifyDto puzzleToVerifyDto = new PuzzleToVerifyDto { CurrentPuzzleState = "034007008080065666666300070200000700710040096005000001050002000000170060600900430", OriginalPuzzleState = "034007008080065000000300070200000700710040096005000001050002000000170060600900430" }; PuzzleVerifyDto puzzleVerifyDto = _sudokuPuzzleService.Verify(puzzleToVerifyDto); Assert.IsTrue(puzzleVerifyDto.CorrectIndexes.Count == 28); }
public void Verify_Should_Fail_When_CurrentPuzzleState_Is_Empty() { const string expectedMessage = "PuzzleState is invalid."; PuzzleToVerifyDto puzzleToVerifyDto = new PuzzleToVerifyDto { CurrentPuzzleState = string.Empty, OriginalPuzzleState = "034007008080065000000300070200000700710040096005000001050002000000170060600900430" }; PuzzleVerifyDto puzzleVerifyDto = _sudokuPuzzleService.Verify(puzzleToVerifyDto); Assert.IsFalse(puzzleVerifyDto.Success); Assert.AreEqual(expectedMessage, puzzleVerifyDto.Message); }
public PuzzleVerifyDto Verify(PuzzleToVerifyDto puzzleToVerifyDto) { if (string.IsNullOrWhiteSpace(puzzleToVerifyDto.OriginalPuzzleState) || string.IsNullOrWhiteSpace(puzzleToVerifyDto.CurrentPuzzleState) || puzzleToVerifyDto.OriginalPuzzleState.Length != 81 || puzzleToVerifyDto.CurrentPuzzleState.Length != 81) { return new PuzzleVerifyDto { Message = "PuzzleState is invalid." } } ; byte[] grid = Encoding.Default.GetBytes(puzzleToVerifyDto.OriginalPuzzleState); PuzzleState puzzleState = new PuzzleState(grid); SudokuPuzzle sudoku = new SudokuPuzzle(puzzleState); string actualSolvedPuzzleState; using (SudokuSolver sudokuSolver = new SudokuSolver(sudoku)) { if (!sudokuSolver.Solve()) { return new PuzzleVerifyDto { Message = "Failed to solve puzzle. Verify will not work." } } ; actualSolvedPuzzleState = sudokuSolver.GetSolvedState().ToString(); } List <int> correctIndexes = new List <int>(); for (int i = 0; i < puzzleToVerifyDto.OriginalPuzzleState.Length; i++) { if (actualSolvedPuzzleState[i].Equals(puzzleToVerifyDto.CurrentPuzzleState[i])) { correctIndexes.Add(i); } } return(new PuzzleVerifyDto { Success = true, CorrectIndexes = correctIndexes, Message = "Successfully verified puzzleState." }); }