Exemple #1
0
 def test_convertToSets(self):
     problem = sudoku.read_sudoku("./data/data1.txt")  #read the puzzle
     sets = sudoku.read_sudoku("./data/convertToSetsTest.txt")  #read the coverted sets
     emptySets = sudoku.read_sudoku("./data/emptySets.txt")
     self.assertEqual(emptySets, sudoku.convertToSets([[0] * 9] * 9))
     self.assertEqual([sets[0]], sudoku.convertToSets([problem[0]]))
     self.assertEqual(sets, sudoku.convertToSets(problem))
Exemple #2
0
 def test_isSolved(self):
     problem = sudoku.read_sudoku("./data/data1.txt")  #read the puzzle
     result = sudoku.read_sudoku("./data/result.txt")   #read the result 
     emptySets = sudoku.read_sudoku("./data/emptySets.txt")
     self.assertFalse(sudoku.isSolved(emptySets))
     self.assertFalse(sudoku.isSolved(sudoku.convertToSets(problem)))
     self.assertTrue(sudoku.isSolved(sudoku.convertToSets(result)))
Exemple #3
0
def testConvertToSets():
    ary = [[0, 1, 2], [1, 0, 2], [0, 1, 0]]
    s = set(range(1, 10))
    assert sudoku.convertToSets(ary) == [[s, {1}, {2}], [{1}, s, {2}],
                                         [s, {1}, s]]
    assert type(
        ary[0][0]) is set, print("The original array has been changed.")
Exemple #4
0
 def test_eliminate(self):
     loc0 = (0,1)
     eliminate = sudoku.read_sudoku("./data/eliminateTest.txt")    #read the eliminate result
     problem = sudoku.read_sudoku("./data/data1.txt")  #read the puzzle
     problemSets = sudoku.convertToSets(problem)
     listOfLocation = sudoku.getRowLocations(loc0[0]) + sudoku.getColumnLocations(loc0[1]) \
                         + sudoku.getBoxLocations(loc0) 
     self.assertEqual(12, sudoku.eliminate(problemSets, loc0, listOfLocation))
     self.assertEqual(eliminate, problemSets)
Exemple #5
0
    def test_grid_to_set(self):
        grid_3 = [[7, 0, 0],
                  [6, 0, 0],
                  [9, 3, 0]]

        grid3_as_sets = [[{7}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}],
                         [{6}, {1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 2, 3, 4, 5, 6, 7, 8, 9}],
                         [{9}, {3}, {1, 2, 3, 4, 5, 6, 7, 8, 9}]]

        self.assertTrue(grid3_as_sets == sudoku.convertToSets(grid_3))
Exemple #6
0
def test_solve(sets):
    assert solve(sets) is True
    assert solve(convertToSets([[0, 0, 0, 7, 0, 0, 6, 8, 9],
                                [3, 0, 8, 0, 0, 0, 2, 0, 0],
                                [0, 0, 0, 8, 1, 0, 0, 4, 0],

                                [6, 0, 0, 0, 0, 0, 8, 0, 4],
                                [8, 0, 0, 3, 4, 9, 0, 0, 5],
                                [7, 0, 5, 0, 0, 0, 0, 0, 3],

                                [0, 8, 0, 0, 7, 6, 0, 0, 0],
                                [0, 0, 7, 0, 0, 0, 1, 0, 8],
                                [9, 5, 1, 0, 0, 8, 0, 0, 0]])) is True
    assert solve(convertToSets([[9, 0, 0, 0, 0, 8, 0, 0, 0],
                                [0, 0, 0, 0, 3, 2, 0, 0, 0],
                                [6, 8, 0, 9, 0, 1, 0, 7, 0],

                                [8, 0, 9, 5, 2, 0, 0, 3, 0],
                                [2, 0, 0, 0, 0, 0, 0, 0, 5],
                                [0, 4, 0, 0, 9, 3, 7, 0, 8],

                                [0, 2, 0, 3, 0, 9, 0, 6, 4],
                                [0, 0, 0, 2, 8, 0, 0, 0, 0],
                                [0, 0, 0, 6, 0, 0, 0, 0, 3]])) is False
Exemple #7
0
def sets(problem):
    return convertToSets(problem)
Exemple #8
0
 def test_solve(self):        
     result = sudoku.read_sudoku("./data/result.txt")   #read the result 
     problem = sudoku.read_sudoku("./data/data1.txt")  #read the puzzle
     problemSets = sudoku.convertToSets(problem)
     self.assertTrue(sudoku.solve(problemSets))
     self.assertEqual(result, sudoku.convertToInts(problemSets))