public void TestSudokuGridCopier() { SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver(); SudokuGrid myGrid = new SudokuGrid(); myGrid = sudokuSolver.FromIntArray(input(1)); SudokuGrid myGrid2 = sudokuSolver.Copy(myGrid); Assert.IsTrue(myGrid.ToString().Equals(myGrid2.ToString())); myGrid2[2, 3].solve(2); myGrid[2, 3].solve(3); Assert.IsFalse(myGrid.ToString().Equals(myGrid2.ToString())); }
public void CheckAllStoredLogic() { bool solvedAll = true; //1 to 23, inclusive for (int i = 1; i <= NumStoredSudokus; i++) { SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver(); SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell(); //inputted sudoku int[,] sudokuInputted = input(i); SudokuGrid mySudoku = new SudokuGrid(); //my sudoku to be worked with for (int row = 0; row < 9; row++) { for (int column = 0; column < 9; column++) { mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]); } } sudokuSolver.Solve(mySudoku, true); //bruteForceSolver(mySudoku); //if unsolved if (!sudokuSolver.IsSolved(mySudoku, false)) { solvedAll = false; TestContext.WriteLine("More work on " + i); TestContext.WriteLine("Num unsolved is " + sudokuSolver.numUnsolved(mySudoku)); } //if there was a duplicate in row, column, or box if (sudokuSolver.InvalidMove(mySudoku)) { TestContext.WriteLine("Invalid move on " + i); } } if (solvedAll) { TestContext.WriteLine("All solved"); } Assert.IsTrue(solvedAll, "Not all solved"); }
public void CheckIsValidMethod() { //1 to 23, inclusive //23 broke for (int i = 1; i <= 23; i++) { SudokuLogic.SudokuSolver sudokuSolver = new SudokuLogic.SudokuSolver(); SudokuLogic.sudokCell sudokCell = new SudokuLogic.sudokCell(); //inputted sudoku int[,] sudokuInputted = input(i); SudokuGrid mySudoku = new SudokuGrid(); //my sudoku to be worked with for (int row = 0; row < 9; row++) { for (int column = 0; column < 9; column++) { mySudoku[row, column] = new sudokCell(sudokuInputted[row, column]); } } Assert.IsTrue(mySudoku.IsValid(), $"{i} was said to be not valid"); } SudokuGrid notValid1 = new SudokuGrid(); //my sudoku to be worked with for (int row = 0; row < 9; row++) { for (int column = 0; column < 9; column++) { notValid1[row, column] = new sudokCell(); } } notValid1[1, 1].solve(2); Assert.IsFalse(notValid1.IsValid(), "IsValid said a nonValid Sudoku is validx"); }