class TestValidate(unittest.TestCase): def testValidate(self): self.grid = numpy.array([['_', '_', '_', '4', '5', '1'], ['_', '2', '3', '4', '5', '2'], ['_', '2', '3', '4', '5', '3'], ['_', '2', '3', '4', '5', '4'], ['_', '2', '3', '4', '5', '5'], ['_', '_', '_', '_', '5', '6']]) self.grid2 = numpy.array([['1', '_', '_', '4'], ['_', '2', '3', '4'], ['1', '2', '3', '4'], ['_', '_', '_', '_']]) print(self.grid) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 6 self.solver2.puzzleSize = 6 self.solver1.puzzle = self.grid self.solver2.puzzle = self.grid self.assertTrue(self.solver2.validate(5,5)) self.assertTrue(self.solver1.validate(5,5)) self.assertFalse(self.solver2.validate(4,4)) self.assertFalse(self.solver1.validate(4,4)) self.assertTrue(self.solver2.validate(0,0)) self.assertTrue(self.solver1.validate(0,0)) self.assertFalse(self.solver2.validate(1,1)) self.assertFalse(self.solver1.validate(1,1))
class TestFindEmptyCells(unittest.TestCase): def testFindEmptyCells(self): self.grid2 = numpy.array([['1', '1', '_', '4', '5', '6'], ['_', '2', '_', '4', '5', '6'], ['_', '2', '3', '4', '5', '6'], ['_', '2', '3', '4', '5', '6'], ['1', '2', '3', '4', '5', '6'], ['_', '_', '_', '_', '5', '6']]) self.grid = numpy.array([['4', '2', '_', '1'], ['_', '_', '_', '2'], ['3', '_', '2', '_'], ['_', '4', '_', '3']]) print(self.grid) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid self.solver2.puzzle = self.grid result2 = self.solver2.getEmptyCells() result1 = self.solver1.getEmptyCells() print(result1) print(result2) self.assertEqual(result1, result2) print(self.grid2) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 6 self.solver2.puzzleSize = 6 self.solver1.puzzle = self.grid2 self.solver2.puzzle = self.grid2 result2 = self.solver2.getEmptyCells() result1 = self.solver1.getEmptyCells() print(result1) print(result2) self.assertEqual(result1, result2) self.grid = numpy.array([['4', '2', '5', '1'], ['6', 'q', '5', '2'], ['3', '5', '2', '0'], ['_', '4', '%', '3']]) print(self.grid) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid self.solver2.puzzle = self.grid result2 = self.solver2.getEmptyCells() result1 = self.solver1.getEmptyCells() self.assertEqual(result1, result2) print(result1) print(result2)
def testGetBox(self): self.grid = numpy.array([['1', '_', '_', '4', '5', '6'], ['_', '2', '3', '4', '5', '6'], ['_', '2', '3', '4', '5', '6'], ['_', '2', '3', '4', '5', '6'], ['1', '2', '3', '4', '5', '6'], ['_', '_', '_', '_', '5', '6']]) self.grid2 = numpy.array([['1', '_', '_', '4'], ['_', '2', '3', '4'], ['1', '2', '3', '4'], ['_', '_', '_', '_']]) print(self.grid) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 6 self.solver2.puzzleSize = 6 self.solver1.puzzle = self.grid self.solver2.puzzle = self.grid result2 = self.solver2.getBox(5,5) result1 = self.solver1.getBox(5,5) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, result2) print(self.grid2) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid2 self.solver2.puzzle = self.grid2 result2 = self.solver2.getBox(2,3) result1 = self.solver1.getBox(2,3) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, result2) print(self.grid2) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid2 self.solver2.puzzle = self.grid2 result2 = self.solver2.getBox(3,3) result1 = self.solver1.getBox(3,3) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, result2) print(self.grid2) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid2 self.solver2.puzzle = self.grid2 result2 = self.solver2.getBox(0,0) result1 = self.solver1.getBox(0,0) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, result2) self.grid3 = numpy.array([['_', '_', '_', '_'], ['_', '_', '_', '_'], ['_', '_', '_', '_'], ['_', '_', '_', '_']]) print(self.grid3) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid3 self.solver2.puzzle = self.grid3 result2 = self.solver2.getBox(1,1) result1 = self.solver1.getBox(3,3) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, set()) self.assertEqual(result2, set()) self.grid4 = numpy.array([['X', '_', '_', '_'], ['_', '_', '_', '_'], ['Y', 'J', '_', 'T'], ['_', '_', '_', '_']]) print(self.grid4) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid4 self.solver2.puzzle = self.grid4 result2 = self.solver2.getBox(1,1) result1 = self.solver1.getBox(0,3) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result1, set(['Y','J'])) self.assertEqual(result2, set(['X'])) self.grid4 = numpy.array([['X', '_', '_', '_'], ['_', '_', '_', '_'], ['Y', 'J', '_', 'T'], ['_', '_', '_', '_']]) print(self.grid4) self.solver2 = SudokuSolverTwo() self.solver1 = SudokuSolverOne() self.solver1.puzzleSize = 4 self.solver2.puzzleSize = 4 self.solver1.puzzle = self.grid4 self.solver2.puzzle = self.grid4 result2 = self.solver1.getBox(0,3) result1 = self.solver2.getBox(1,1) print("Solver1 =>",result1) print("Solver2 =>",result2) self.assertEqual(result2, set(['Y','J'])) self.assertEqual(result1, set(['X']))