public void BoardCannotBeSolved() { int[,] board = new int[, ] { { 6, 0, 2, 5, 0, 0, 4, 9, 0 }, //first 0 in this row cannot be filled with any valid value (1-9), as all 1-9 exists in either row, col or 3x3 block { 5, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 8, 7, 0, 0, 0, 0, 0, 2 }, { 0, 0, 3, 0, 1, 0, 0, 8, 0 }, { 9, 0, 0, 8, 0, 4, 0, 0, 5 }, { 0, 5, 0, 0, 2, 0, 9, 0, 0 }, { 0, 3, 0, 0, 0, 0, 1, 5, 0 }, { 0, 0, 0, 0, 0, 0, 0, 7, 4 }, { 0, 0, 8, 2, 0, 0, 3, 0, 0 } }; var response = new SudokuSolverService(new SudokuSolverCore()).Solve(new SudokuSolverRequest { Board = board }); Assert.AreEqual(response.Status, SudokuSolverResponseStatus.NotSolved); }
public void BoardProvidedWithNegativeCellValue() { int[,] board = new int[, ] { { 3, 0, 6, 5, 0, 8, 4, 0, 0 }, { 5, 2, 0, 0, 0, 0, 0, 0, 0 }, { 0, 8, 7, 0, 0, 0, 0, -3, 1 }, //-ve cell value (-3) { 0, 0, 3, 0, 1, 0, 0, 8, 0 }, { 9, 0, 0, 8, 6, 3, 0, 0, 5 }, { 0, 5, 0, 0, 9, 0, 6, 0, 0 }, { 1, 3, 0, 0, 0, 0, 2, 5, 0 }, { 0, 0, 0, 0, 0, 0, 0, 7, 4 }, { 0, 0, 5, 2, 0, 6, 3, 0, 0 } }; var response = new SudokuSolverService(new SudokuSolverCore()).Solve(new SudokuSolverRequest { Board = board }); Assert.AreEqual(response.Status, SudokuSolverResponseStatus.Error); Assert.AreEqual(response.ErrorMessage, "Each cell must contain values between 0-9."); }
public void BoardProvidedWithDuplicateBlockValue() { int[,] board = new int[, ] { { 3, 0, 6, 5, 0, 8, 4, 0, 0 }, { 5, 2, 0, 0, 0, 0, 0, 1, 0 }, //1 is duplicate in the 3x3 block { 0, 8, 7, 0, 0, 0, 0, 3, 1 }, { 0, 0, 3, 0, 1, 0, 0, 8, 0 }, { 9, 0, 0, 8, 6, 3, 0, 0, 5 }, { 0, 5, 0, 0, 9, 0, 6, 0, 0 }, { 1, 3, 0, 0, 0, 0, 2, 5, 0 }, { 0, 0, 0, 0, 0, 0, 0, 7, 4 }, { 0, 0, 5, 2, 0, 6, 3, 0, 0 } }; var response = new SudokuSolverService(new SudokuSolverCore()).Solve(new SudokuSolverRequest { Board = board }); Assert.AreEqual(response.Status, SudokuSolverResponseStatus.Error); Assert.AreEqual(response.ErrorMessage, "Each provided input must be unique for the row, column and 3x3 block."); }
public SudokuSolverController(SudokuSolverService sudokuSolverService) { this.sudokuSolverService = sudokuSolverService; }