def test_solution_sudoku_hard_08(self): sudoku_test_hard_08 = NorvigAlgorithm("""052400000 000070100 000000000 000802000 300000600 090500000 106030000 000000089 700000000""", "0") sudoku_test_hard_08_solution = {'G7': '2', 'G6': '7', 'G5': '3', 'G4': '9', 'G3': '6', 'G2': '8', 'G1': '1', 'G9': '5', 'G8': '4', 'C9': '4', 'C8': '6', 'C3': '1', 'C2': '7', 'C1': '9', 'C7': '8', 'C6': '5', 'C5': '2', 'C4': '3', 'A9': '7', 'A8': '3', 'F1': '2', 'F2': '9', 'F3': '8', 'F4': '5', 'F5': '6', 'F6': '3', 'F7': '4', 'F8': '7', 'F9': '1', 'B4': '6', 'B5': '7', 'B6': '9', 'B7': '1', 'B1': '8', 'B2': '3', 'B3': '4', 'B8': '5', 'B9': '2', 'I9': '6', 'I8': '1', 'I1': '7', 'I3': '9', 'I2': '4', 'I5': '5', 'I4': '2', 'I7': '3', 'I6': '8', 'A1': '6', 'A3': '2', 'A2': '5', 'E9': '8', 'A4': '4', 'A7': '9', 'A6': '1', 'E5': '9', 'E4': '7', 'E7': '6', 'E6': '4', 'E1': '3', 'E3': '5', 'E2': '1', 'E8': '2', 'A5': '8', 'H8': '8', 'H9': '9', 'H2': '2', 'H3': '3', 'H1': '5', 'H6': '6', 'H7': '7', 'H4': '1', 'H5': '4', 'D8': '9', 'D9': '3', 'D6': '2', 'D7': '5', 'D4': '8', 'D5': '1', 'D2': '6', 'D3': '7', 'D1': '4'} self.assertEquals(sudoku_test_hard_08.solve_sudoku(), sudoku_test_hard_08_solution)
def test_solution_sudoku_easy_02(self): sudoku_test_easy_02 = NorvigAlgorithm("""200080300 060070084 030500209 000105408 000000000 402706000 301007040 720040060 004010003""", "0") sudoku_test_easy_02_solution = {'I6': '2', 'H9': '5', 'I2': '5', 'E8': '2', 'H3': '8', 'H7': '1', 'I7': '7', 'I4': '8', 'H5': '4', 'F9': '1', 'G7': '8', 'G6': '7', 'G5': '5', 'E1': '5', 'G3': '1', 'G2': '9', 'G1': '3', 'I1': '6', 'C8': '1', 'I3': '4', 'E5': '9', 'I5': '1', 'C9': '9', 'G9': '2', 'G8': '4', 'A1': '2', 'A3': '5', 'A2': '4', 'A5': '8', 'A4': '9', 'A7': '3', 'A6': '1', 'C3': '7', 'C2': '3', 'C1': '8', 'E6': '8', 'C7': '2', 'C6': '4', 'C5': '6', 'C4': '5', 'I9': '3', 'D8': '3', 'I8': '9', 'E4': '4', 'D9': '8', 'H8': '6', 'F6': '6', 'A9': '6', 'G4': '6', 'A8': '7', 'E7': '6', 'E3': '3', 'F1': '4', 'F2': '8', 'F3': '2', 'F4': '7', 'F5': '3', 'E2': '1', 'F7': '9', 'F8': '5', 'D2': '7', 'H1': '7', 'H6': '9', 'H2': '2', 'H4': '3', 'D3': '6', 'B4': '2', 'B5': '7', 'B6': '3', 'B7': '5', 'E9': '7', 'B1': '1', 'B2': '6', 'B3': '9', 'D6': '5', 'D7': '4', 'D4': '1', 'D5': '2', 'B8': '8', 'B9': '4', 'D1': '9'} self.assertEquals(sudoku_test_easy_02.solve_sudoku(), sudoku_test_easy_02_solution)
def test_solution_sudoku_easy_03(self): sudoku_test_easy_03 = NorvigAlgorithm("""000000907 000420180 000705026 100904000 050000040 000507009 920108000 034059000 507000000""", "0") sudoku_test_easy_03_solution = {'I6': '3', 'H9': '1', 'I2': '1', 'E8': '4', 'H3': '4', 'H7': '6', 'I7': '8', 'I4': '6', 'H5': '5', 'F9': '9', 'G7': '5', 'G6': '8', 'G5': '7', 'E1': '6', 'G3': '6', 'G2': '2', 'G1': '9', 'I1': '5', 'C8': '2', 'I3': '7', 'E5': '1', 'I5': '4', 'C9': '6', 'G9': '4', 'G8': '3', 'A1': '4', 'A3': '2', 'A2': '6', 'A5': '3', 'A4': '8', 'A7': '9', 'A6': '1', 'C3': '1', 'C2': '8', 'C1': '3', 'E6': '2', 'C7': '4', 'C6': '5', 'C5': '9', 'C4': '7', 'I9': '2', 'D8': '6', 'I8': '9', 'E4': '3', 'D9': '5', 'H8': '7', 'F6': '7', 'A9': '7', 'G4': '1', 'A8': '5', 'E7': '7', 'E3': '9', 'F1': '2', 'F2': '4', 'F3': '8', 'F4': '5', 'F5': '6', 'E2': '5', 'F7': '3', 'F8': '1', 'D2': '7', 'H1': '8', 'H6': '9', 'H2': '3', 'H4': '2', 'D3': '3', 'B4': '4', 'B5': '2', 'B6': '6', 'B7': '1', 'E9': '8', 'B1': '7', 'B2': '9', 'B3': '5', 'D6': '4', 'D7': '2', 'D4': '9', 'D5': '8', 'B8': '8', 'B9': '3', 'D1': '1'} self.assertEquals(sudoku_test_easy_03.solve_sudoku(), sudoku_test_easy_03_solution)
def test_soduku_to_solve_is_invalid_when_contains_less_than_81_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_is_invalid_when_contains_less_than_81_numbers( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
class TestResults(unittest.TestCase): def setUp(self): self.save = Results() self.norvig = NorvigAlgorithm() self.grid1 = '003020600900305001001806400008102900700000008006708200' \ '002609500800203009005010300' def test_save_sudoku_to_txt_file(self): info = self.norvig.parse_sudoku_to_string(self.norvig.solve(self.grid1)) self.save.save_to_file(info) self.assertTrue(os.path.isfile('../game_results/default.txt'))
def test_soduku_to_solve_is_valid_when_characters_to_replace_are_porcentage(self): sudoku_test_only_numbers = NorvigAlgorithm("""%923%%%%% %%%%8%1%% %%%%%%%%% 1%7%4%%%% %%%%%%%65 8%%%%%%%% %6%5%2%%% 4%%%%%7%% %%%9%%%%%""", "%") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_cannot_contain_letters(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000A65 800000000 060502000 400000C00 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_cannot_contain_dot_as_empty_value_if_the_empty_value_is_zero(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 ....80100 ...000000 107040000 ..0..0465 800000000 060502000 400000200 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_not_contain_spaces_as_empty_value_if_the_empty_value_is_zero(self): sudoku_test_only_numbers = NorvigAlgorithm(""" 923 8 1 1 1 7 4 465 8 6 5 2 4 2 9 """, "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_only_contains_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_cannot_contain_letters(self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000A65 800000000 060502000 400000C00 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_only_contains_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_is_valid_when_characters_to_replace_are_porcentage( self): sudoku_test_only_numbers = NorvigAlgorithm( """%923%%%%% %%%%8%1%% %%%%%%%%% 1%7%4%%%% %%%%%%%65 8%%%%%%%% %6%5%2%%% 4%%%%%7%% %%%9%%%%%""", "%") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_cannot_contain_dot_as_empty_value_if_the_empty_value_is_zero( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 ....80100 ...000000 107040000 ..0..0465 800000000 060502000 400000200 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def test_soduku_to_solve_not_contain_spaces_as_empty_value_if_the_empty_value_is_zero( self): sudoku_test_only_numbers = NorvigAlgorithm( """ 923 8 1 1 1 7 4 465 8 6 5 2 4 2 9 """, "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid())
def create_algorith_to_solve_sudoku(self, sudoku_matrix, empty_character): """ Method used for create the algorithm to solve given the expected sudoku matrix and empty character Keyword arguments: sudoku_matrix -- stores the sudoku in the valid matrix ready to be solved empty_character -- stores the selected character for the empty spots """ algorithm_selected = self.configuration.get_algorithm() algoritms = [] for i in range(0, len(sudoku_matrix)): algoritm_to_solve = Algorithm(sudoku_matrix[i][0], empty_character) if algorithm_selected == 'norvig': algoritm_to_solve = NorvigAlgorithm(sudoku_matrix[i][0], empty_character) elif algorithm_selected == 'backtracking': algoritm_to_solve = BacktrakingAlgorithm( sudoku_matrix[i][0], empty_character) elif algorithm_selected == 'brute force': algoritm_to_solve = BruteForceAlgorithm( sudoku_matrix[i][0], empty_character) algoritms.append(algoritm_to_solve) return algoritms
def test_soduku_to_solve_is_valid_when_characters_to_replace_are_dot(self): sudoku_test_only_numbers = NorvigAlgorithm( """.923..... ....8.1.. ......... 1.7.4.... .......65 8........ .6.5.2... 4.....7.. ...9.....""", ".")
def test_soduku_to_solve_is_invalid_when_contains_more_than_81_numbers( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000 000000065 060502000""", "0")
def setUp(self): # Test algorithm Norvig attributes sudoku_test_values = """003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""" self.sudoku_test_attributes = NorvigAlgorithm(sudoku_test_values, "0") self.len_squares = 81 self.len_unitlist = 27 self.units_c2 = [[ 'A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2' ], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']] self.peers_c2 = set([ 'A2', 'B2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'C1', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'A1', 'A3', 'B1', 'B3' ])
def setUp(self): # Test algorithm Norvig attributes sudoku_test_values = """003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""" self.sudoku_test_attributes = NorvigAlgorithm(sudoku_test_values, "0") self.len_squares = 81 self.len_unitlist = 27 self.units_c2 = [['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']] self.peers_c2 = set(['A2', 'B2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'C1', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'A1', 'A3', 'B1', 'B3'])
def test_solution_sudoku_easy_10(self): sudoku_test_easy_10 = NorvigAlgorithm( """001900003 900700160 030005007 050000009 004302600 200000070 600100030 042007006 500006800""", "0") sudoku_test_easy_10_solution = { 'G7': '7', 'G6': '4', 'G5': '5', 'G4': '1', 'G3': '9', 'G2': '8', 'G1': '6', 'G9': '2', 'G8': '3', 'C9': '7', 'C8': '2', 'C3': '8', 'C2': '3', 'C1': '4', 'C7': '9', 'C6': '5', 'C5': '1', 'C4': '6', 'A9': '3', 'A8': '5', 'F1': '2', 'F2': '1', 'F3': '6', 'F4': '5', 'F5': '8', 'F6': '9', 'F7': '3', 'F8': '7', 'F9': '4', 'B4': '7', 'B5': '4', 'B6': '3', 'B7': '1', 'B1': '9', 'B2': '2', 'B3': '5', 'B8': '6', 'B9': '8', 'I9': '1', 'I8': '4', 'I1': '5', 'I3': '3', 'I2': '7', 'I5': '9', 'I4': '2', 'I7': '8', 'I6': '6', 'A1': '7', 'A3': '1', 'A2': '6', 'E9': '5', 'A4': '9', 'A7': '4', 'A6': '8', 'E5': '7', 'E4': '3', 'E7': '6', 'E6': '2', 'E1': '8', 'E3': '4', 'E2': '9', 'E8': '1', 'A5': '2', 'H8': '9', 'H9': '6', 'H2': '4', 'H3': '2', 'H1': '1', 'H6': '7', 'H7': '5', 'H4': '8', 'H5': '3', 'D8': '8', 'D9': '9', 'D6': '1', 'D7': '2', 'D4': '4', 'D5': '6', 'D2': '5', 'D3': '7', 'D1': '3' } self.assertEquals(sudoku_test_easy_10.solve_sudoku(), sudoku_test_easy_10_solution)
def setUp(self): self.save = Results() self.norvig = NorvigAlgorithm() self.grid1 = '003020600900305001001806400008102900700000008006708200' \ '002609500800203009005010300'
class TestNorvigAlgorithm(unittest.TestCase): def setUp(self): # Test algorithm Norvig attributes sudoku_test_values = """003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""" self.sudoku_test_attributes = NorvigAlgorithm(sudoku_test_values, "0") self.len_squares = 81 self.len_unitlist = 27 self.units_c2 = [[ 'A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2' ], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']] self.peers_c2 = set([ 'A2', 'B2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'C1', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'A1', 'A3', 'B1', 'B3' ]) ################ Test correct creation of attributes ################ def test_attributes_len_squares_is_81(self): self.assertEquals(self.len_squares, len(self.sudoku_test_attributes.squares)) def test_attributes_len_unitlist_is_27(self): self.assertEquals(self.len_unitlist, len(self.sudoku_test_attributes.unitlist)) def test_attributes_values_units_c2(self): self.assertEquals(self.units_c2, self.sudoku_test_attributes.units['C2']) def test_attributes_values_peers_c2(self): self.assertEquals(self.peers_c2, self.sudoku_test_attributes.peers['C2']) def test_solution_time_different_than_zero(self): self.sudoku_test_attributes.solve_sudoku() self.assertTrue(self.sudoku_test_attributes.get_time() > 0.0) ################ Test to verify the solution easy sudokus ################ def test_solution_sudoku_easy_01(self): sudoku_test_easy_01 = NorvigAlgorithm( """003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""", "0") sudoku_test_easy_01_solution = { 'I6': '7', 'H9': '9', 'I2': '9', 'E8': '3', 'H3': '4', 'H7': '7', 'I7': '3', 'I4': '4', 'H5': '5', 'F9': '5', 'G7': '5', 'G6': '9', 'G5': '8', 'E1': '7', 'G3': '2', 'G2': '7', 'G1': '3', 'I1': '6', 'C8': '9', 'I3': '5', 'E5': '6', 'I5': '1', 'C9': '3', 'G9': '4', 'G8': '1', 'A1': '4', 'A3': '3', 'A2': '8', 'A5': '2', 'A4': '9', 'A7': '6', 'A6': '1', 'C3': '1', 'C2': '5', 'C1': '2', 'E6': '4', 'C7': '4', 'C6': '6', 'C5': '7', 'C4': '8', 'I9': '2', 'D8': '7', 'I8': '8', 'E4': '5', 'D9': '6', 'H8': '6', 'F6': '8', 'A9': '7', 'G4': '6', 'A8': '5', 'E7': '1', 'E3': '9', 'F1': '1', 'F2': '3', 'F3': '6', 'F4': '7', 'F5': '9', 'E2': '2', 'F7': '2', 'F8': '4', 'D2': '4', 'H1': '8', 'H6': '3', 'H2': '1', 'H4': '2', 'D3': '8', 'B4': '3', 'B5': '4', 'B6': '5', 'B7': '8', 'E9': '8', 'B1': '9', 'B2': '6', 'B3': '7', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '3', 'B8': '2', 'B9': '1', 'D1': '5' } self.assertEquals(sudoku_test_easy_01.solve_sudoku(), sudoku_test_easy_01_solution) def test_solution_sudoku_easy_02(self): sudoku_test_easy_02 = NorvigAlgorithm( """200080300 060070084 030500209 000105408 000000000 402706000 301007040 720040060 004010003""", "0") sudoku_test_easy_02_solution = { 'I6': '2', 'H9': '5', 'I2': '5', 'E8': '2', 'H3': '8', 'H7': '1', 'I7': '7', 'I4': '8', 'H5': '4', 'F9': '1', 'G7': '8', 'G6': '7', 'G5': '5', 'E1': '5', 'G3': '1', 'G2': '9', 'G1': '3', 'I1': '6', 'C8': '1', 'I3': '4', 'E5': '9', 'I5': '1', 'C9': '9', 'G9': '2', 'G8': '4', 'A1': '2', 'A3': '5', 'A2': '4', 'A5': '8', 'A4': '9', 'A7': '3', 'A6': '1', 'C3': '7', 'C2': '3', 'C1': '8', 'E6': '8', 'C7': '2', 'C6': '4', 'C5': '6', 'C4': '5', 'I9': '3', 'D8': '3', 'I8': '9', 'E4': '4', 'D9': '8', 'H8': '6', 'F6': '6', 'A9': '6', 'G4': '6', 'A8': '7', 'E7': '6', 'E3': '3', 'F1': '4', 'F2': '8', 'F3': '2', 'F4': '7', 'F5': '3', 'E2': '1', 'F7': '9', 'F8': '5', 'D2': '7', 'H1': '7', 'H6': '9', 'H2': '2', 'H4': '3', 'D3': '6', 'B4': '2', 'B5': '7', 'B6': '3', 'B7': '5', 'E9': '7', 'B1': '1', 'B2': '6', 'B3': '9', 'D6': '5', 'D7': '4', 'D4': '1', 'D5': '2', 'B8': '8', 'B9': '4', 'D1': '9' } self.assertEquals(sudoku_test_easy_02.solve_sudoku(), sudoku_test_easy_02_solution) def test_solution_sudoku_easy_03(self): sudoku_test_easy_03 = NorvigAlgorithm( """000000907 000420180 000705026 100904000 050000040 000507009 920108000 034059000 507000000""", "0") sudoku_test_easy_03_solution = { 'I6': '3', 'H9': '1', 'I2': '1', 'E8': '4', 'H3': '4', 'H7': '6', 'I7': '8', 'I4': '6', 'H5': '5', 'F9': '9', 'G7': '5', 'G6': '8', 'G5': '7', 'E1': '6', 'G3': '6', 'G2': '2', 'G1': '9', 'I1': '5', 'C8': '2', 'I3': '7', 'E5': '1', 'I5': '4', 'C9': '6', 'G9': '4', 'G8': '3', 'A1': '4', 'A3': '2', 'A2': '6', 'A5': '3', 'A4': '8', 'A7': '9', 'A6': '1', 'C3': '1', 'C2': '8', 'C1': '3', 'E6': '2', 'C7': '4', 'C6': '5', 'C5': '9', 'C4': '7', 'I9': '2', 'D8': '6', 'I8': '9', 'E4': '3', 'D9': '5', 'H8': '7', 'F6': '7', 'A9': '7', 'G4': '1', 'A8': '5', 'E7': '7', 'E3': '9', 'F1': '2', 'F2': '4', 'F3': '8', 'F4': '5', 'F5': '6', 'E2': '5', 'F7': '3', 'F8': '1', 'D2': '7', 'H1': '8', 'H6': '9', 'H2': '3', 'H4': '2', 'D3': '3', 'B4': '4', 'B5': '2', 'B6': '6', 'B7': '1', 'E9': '8', 'B1': '7', 'B2': '9', 'B3': '5', 'D6': '4', 'D7': '2', 'D4': '9', 'D5': '8', 'B8': '8', 'B9': '3', 'D1': '1' } self.assertEquals(sudoku_test_easy_03.solve_sudoku(), sudoku_test_easy_03_solution) def test_solution_sudoku_easy_04(self): sudoku_test_easy_04 = NorvigAlgorithm( """030050040 008010500 460000012 070502080 000603000 040109030 250000098 001020600 080060020""", "0") sudoku_test_easy_04_solution = { 'I6': '5', 'H9': '5', 'I2': '8', 'E8': '5', 'H3': '1', 'H7': '6', 'I7': '1', 'I4': '9', 'H5': '2', 'F9': '6', 'G7': '4', 'G6': '1', 'G5': '3', 'E1': '8', 'G3': '6', 'G2': '5', 'G1': '2', 'I1': '7', 'C8': '1', 'I3': '4', 'E5': '7', 'I5': '6', 'C9': '2', 'G9': '8', 'G8': '9', 'A1': '1', 'A3': '7', 'A2': '3', 'A5': '5', 'A4': '2', 'A7': '8', 'A6': '6', 'C3': '5', 'C2': '6', 'C1': '4', 'E6': '3', 'C7': '3', 'C6': '7', 'C5': '9', 'C4': '8', 'I9': '3', 'D8': '8', 'I8': '2', 'E4': '6', 'D9': '1', 'H8': '7', 'F6': '9', 'A9': '9', 'G4': '7', 'A8': '4', 'E7': '2', 'E3': '9', 'F1': '5', 'F2': '4', 'F3': '2', 'F4': '1', 'F5': '8', 'E2': '1', 'F7': '7', 'F8': '3', 'D2': '7', 'H1': '3', 'H6': '8', 'H2': '9', 'H4': '4', 'D3': '3', 'B4': '3', 'B5': '1', 'B6': '4', 'B7': '5', 'E9': '4', 'B1': '9', 'B2': '2', 'B3': '8', 'D6': '2', 'D7': '9', 'D4': '5', 'D5': '4', 'B8': '6', 'B9': '7', 'D1': '6' } self.assertEquals(sudoku_test_easy_04.solve_sudoku(), sudoku_test_easy_04_solution) def test_solution_sudoku_easy_05(self): sudoku_test_easy_05 = NorvigAlgorithm( """020810740 700003100 090002805 009040087 400208003 160030200 302700060 005600008 076051090""", "0") sudoku_test_easy_05_solution = { 'I6': '1', 'H9': '8', 'I2': '7', 'E8': '1', 'H3': '5', 'H7': '3', 'I7': '4', 'I4': '3', 'H5': '2', 'F9': '4', 'G7': '5', 'G6': '9', 'G5': '8', 'E1': '4', 'G3': '2', 'G2': '4', 'G1': '3', 'I1': '8', 'C8': '3', 'I3': '6', 'E5': '6', 'I5': '5', 'C9': '5', 'G9': '1', 'G8': '6', 'A1': '5', 'A3': '3', 'A2': '2', 'A5': '1', 'A4': '8', 'A7': '7', 'A6': '6', 'C3': '1', 'C2': '9', 'C1': '6', 'E6': '8', 'C7': '8', 'C6': '2', 'C5': '7', 'C4': '4', 'I9': '2', 'D8': '8', 'I8': '9', 'E4': '2', 'D9': '7', 'H8': '7', 'F6': '7', 'A9': '9', 'G4': '7', 'A8': '4', 'E7': '9', 'E3': '7', 'F1': '1', 'F2': '6', 'F3': '8', 'F4': '9', 'F5': '3', 'E2': '5', 'F7': '2', 'F8': '5', 'D2': '3', 'H1': '9', 'H6': '4', 'H2': '1', 'H4': '6', 'D3': '9', 'B4': '5', 'B5': '9', 'B6': '3', 'B7': '1', 'E9': '3', 'B1': '7', 'B2': '8', 'B3': '4', 'D6': '5', 'D7': '6', 'D4': '1', 'D5': '4', 'B8': '2', 'B9': '6', 'D1': '2' } self.assertEquals(sudoku_test_easy_05.solve_sudoku(), sudoku_test_easy_05_solution) def test_solution_sudoku_easy_06(self): sudoku_test_easy_06 = NorvigAlgorithm( """100920000 524010000 000000070 050008102 000000000 402700090 060000000 000030945 000071006""", "0") sudoku_test_easy_06_solution = { 'G7': '7', 'G6': '9', 'G5': '8', 'G4': '4', 'G3': '5', 'G2': '6', 'G1': '2', 'G9': '3', 'G8': '1', 'C9': '1', 'C8': '7', 'C3': '3', 'C2': '9', 'C1': '8', 'C7': '2', 'C6': '4', 'C5': '5', 'C4': '6', 'A9': '4', 'A8': '8', 'F1': '4', 'F2': '1', 'F3': '2', 'F4': '7', 'F5': '6', 'F6': '5', 'F7': '3', 'F8': '9', 'F9': '8', 'B4': '8', 'B5': '1', 'B6': '7', 'B7': '6', 'B1': '5', 'B2': '2', 'B3': '4', 'B8': '3', 'B9': '9', 'I9': '6', 'I8': '2', 'I1': '3', 'I3': '9', 'I2': '4', 'I5': '7', 'I4': '5', 'I7': '8', 'I6': '1', 'A1': '1', 'A3': '6', 'A2': '7', 'E9': '7', 'A4': '9', 'A7': '5', 'A6': '3', 'E5': '9', 'E4': '1', 'E7': '4', 'E6': '2', 'E1': '6', 'E3': '8', 'E2': '3', 'E8': '5', 'A5': '2', 'H8': '4', 'H9': '5', 'H2': '8', 'H3': '1', 'H1': '7', 'H6': '6', 'H7': '9', 'H4': '2', 'H5': '3', 'D8': '6', 'D9': '2', 'D6': '8', 'D7': '1', 'D4': '3', 'D5': '4', 'D2': '5', 'D3': '7', 'D1': '9' } self.assertEquals(sudoku_test_easy_06.solve_sudoku(), sudoku_test_easy_06_solution) def test_solution_sudoku_easy_07(self): sudoku_test_easy_07 = NorvigAlgorithm( """043080250 600000000 000001094 900004070 000608000 010200003 820500000 000000005 034090710""", "0") sudoku_test_easy_07_solution = { 'G7': '4', 'G6': '7', 'G5': '6', 'G4': '5', 'G3': '1', 'G2': '2', 'G1': '8', 'G9': '9', 'G8': '3', 'C9': '4', 'C8': '9', 'C3': '5', 'C2': '8', 'C1': '2', 'C7': '6', 'C6': '1', 'C5': '3', 'A4': '9', 'A9': '7', 'A8': '5', 'F1': '4', 'F2': '1', 'F3': '8', 'F4': '2', 'F5': '7', 'F6': '9', 'F7': '5', 'F8': '6', 'F9': '3', 'B4': '4', 'B5': '2', 'B6': '5', 'B7': '3', 'E9': '2', 'B1': '6', 'B2': '7', 'B3': '9', 'C4': '7', 'B8': '8', 'B9': '1', 'I9': '6', 'I8': '1', 'I1': '5', 'I3': '4', 'I2': '3', 'I5': '9', 'I4': '8', 'I7': '7', 'I6': '2', 'A1': '1', 'A3': '3', 'A2': '4', 'A5': '8', 'E8': '4', 'A7': '2', 'A6': '6', 'E5': '1', 'E4': '6', 'E7': '9', 'E6': '8', 'E1': '3', 'E3': '7', 'E2': '5', 'H8': '2', 'H9': '5', 'H2': '9', 'H3': '6', 'H1': '7', 'H6': '3', 'H7': '8', 'H4': '1', 'H5': '4', 'D8': '7', 'D9': '8', 'D6': '4', 'D7': '1', 'D4': '3', 'D5': '5', 'D2': '6', 'D3': '2', 'D1': '9' } self.assertEquals(sudoku_test_easy_07.solve_sudoku(), sudoku_test_easy_07_solution) def test_solution_sudoku_easy_08(self): sudoku_test_easy_08 = NorvigAlgorithm( """480006902 002008001 900370060 840010200 003704100 001060049 020085007 700900600 609200018""", "0") sudoku_test_easy_08_solution = { 'I6': '7', 'H9': '5', 'I2': '5', 'E8': '8', 'H3': '8', 'H7': '6', 'I7': '4', 'I4': '2', 'H5': '4', 'F9': '9', 'G7': '3', 'G6': '5', 'G5': '8', 'E1': '5', 'G3': '4', 'G2': '2', 'G1': '1', 'I1': '6', 'C8': '6', 'I3': '9', 'E5': '2', 'I5': '3', 'C9': '4', 'G9': '7', 'G8': '9', 'A1': '4', 'A3': '7', 'A2': '8', 'A5': '5', 'A4': '1', 'A7': '9', 'A6': '6', 'C3': '5', 'C2': '1', 'C1': '9', 'E6': '4', 'C7': '8', 'C6': '2', 'C5': '7', 'C4': '3', 'I9': '8', 'D8': '7', 'I8': '1', 'E4': '7', 'D9': '3', 'H8': '2', 'F6': '3', 'A9': '2', 'G4': '6', 'A8': '3', 'E7': '1', 'E3': '3', 'F1': '2', 'F2': '7', 'F3': '1', 'F4': '8', 'F5': '6', 'E2': '9', 'F7': '5', 'F8': '4', 'D2': '4', 'H1': '7', 'H6': '1', 'H2': '3', 'H4': '9', 'D3': '6', 'B4': '4', 'B5': '9', 'B6': '8', 'B7': '7', 'E9': '6', 'B1': '3', 'B2': '6', 'B3': '2', 'D6': '9', 'D7': '2', 'D4': '5', 'D5': '1', 'B8': '5', 'B9': '1', 'D1': '8' } self.assertEquals(sudoku_test_easy_08.solve_sudoku(), sudoku_test_easy_08_solution) def test_solution_sudoku_easy_09(self): sudoku_test_easy_09 = NorvigAlgorithm( """000900002 050123400 030000160 908000000 070000090 000000205 091000050 007439020 400007000""", "0") sudoku_test_easy_09_solution = { 'I6': '7', 'H9': '1', 'I2': '2', 'E8': '9', 'H3': '7', 'H7': '6', 'I7': '9', 'I4': '5', 'H5': '3', 'F9': '5', 'G7': '7', 'G6': '2', 'G5': '8', 'E1': '2', 'G3': '1', 'G2': '9', 'G1': '3', 'I1': '4', 'C8': '6', 'I3': '6', 'E5': '4', 'I5': '1', 'C9': '9', 'G9': '4', 'G8': '5', 'A1': '8', 'A3': '4', 'A2': '1', 'A5': '7', 'A4': '9', 'A7': '5', 'A6': '6', 'C3': '2', 'C2': '3', 'C1': '7', 'E6': '1', 'C7': '1', 'C6': '4', 'C5': '5', 'C4': '8', 'I9': '3', 'D8': '1', 'I8': '8', 'E4': '3', 'D9': '7', 'H8': '2', 'F6': '8', 'A9': '2', 'G4': '6', 'A8': '3', 'E7': '8', 'E3': '5', 'F1': '1', 'F2': '6', 'F3': '3', 'F4': '7', 'F5': '9', 'E2': '7', 'F7': '2', 'F8': '4', 'D2': '4', 'H1': '5', 'H6': '9', 'H2': '8', 'H4': '4', 'D3': '8', 'B4': '1', 'B5': '2', 'B6': '3', 'B7': '4', 'E9': '6', 'B1': '6', 'B2': '5', 'B3': '9', 'D6': '5', 'D7': '3', 'D4': '2', 'D5': '6', 'B8': '7', 'B9': '8', 'D1': '9' } self.assertEquals(sudoku_test_easy_09.solve_sudoku(), sudoku_test_easy_09_solution) def test_solution_sudoku_easy_10(self): sudoku_test_easy_10 = NorvigAlgorithm( """001900003 900700160 030005007 050000009 004302600 200000070 600100030 042007006 500006800""", "0") sudoku_test_easy_10_solution = { 'G7': '7', 'G6': '4', 'G5': '5', 'G4': '1', 'G3': '9', 'G2': '8', 'G1': '6', 'G9': '2', 'G8': '3', 'C9': '7', 'C8': '2', 'C3': '8', 'C2': '3', 'C1': '4', 'C7': '9', 'C6': '5', 'C5': '1', 'C4': '6', 'A9': '3', 'A8': '5', 'F1': '2', 'F2': '1', 'F3': '6', 'F4': '5', 'F5': '8', 'F6': '9', 'F7': '3', 'F8': '7', 'F9': '4', 'B4': '7', 'B5': '4', 'B6': '3', 'B7': '1', 'B1': '9', 'B2': '2', 'B3': '5', 'B8': '6', 'B9': '8', 'I9': '1', 'I8': '4', 'I1': '5', 'I3': '3', 'I2': '7', 'I5': '9', 'I4': '2', 'I7': '8', 'I6': '6', 'A1': '7', 'A3': '1', 'A2': '6', 'E9': '5', 'A4': '9', 'A7': '4', 'A6': '8', 'E5': '7', 'E4': '3', 'E7': '6', 'E6': '2', 'E1': '8', 'E3': '4', 'E2': '9', 'E8': '1', 'A5': '2', 'H8': '9', 'H9': '6', 'H2': '4', 'H3': '2', 'H1': '1', 'H6': '7', 'H7': '5', 'H4': '8', 'H5': '3', 'D8': '8', 'D9': '9', 'D6': '1', 'D7': '2', 'D4': '4', 'D5': '6', 'D2': '5', 'D3': '7', 'D1': '3' } self.assertEquals(sudoku_test_easy_10.solve_sudoku(), sudoku_test_easy_10_solution) ################ Test to verify the solution hard sudokus ################ def test_solution_sudoku_hard_01(self): sudoku_test_hard_01 = NorvigAlgorithm( """400000805 030000000 000700000 020000060 000080400 000010000 000603070 500200000 104000000""", "0") sudoku_test_hard_01_solution = { 'G7': '5', 'G6': '3', 'G5': '4', 'G4': '6', 'G3': '9', 'G2': '8', 'G1': '2', 'G9': '1', 'G8': '7', 'C9': '6', 'C8': '1', 'C3': '8', 'C2': '5', 'C1': '9', 'C7': '3', 'C6': '4', 'C5': '2', 'C4': '7', 'E5': '8', 'E4': '5', 'F1': '3', 'F2': '4', 'F3': '6', 'F4': '9', 'F5': '1', 'F6': '2', 'F7': '7', 'F8': '5', 'F9': '8', 'B4': '1', 'B5': '5', 'B6': '8', 'B7': '9', 'B1': '6', 'B2': '3', 'B3': '2', 'B8': '4', 'B9': '7', 'I9': '3', 'I8': '9', 'I1': '1', 'I3': '4', 'I2': '6', 'I5': '7', 'I4': '8', 'I7': '2', 'I6': '5', 'A1': '4', 'A3': '7', 'A2': '1', 'E9': '2', 'A4': '3', 'A7': '8', 'A6': '9', 'A9': '5', 'A8': '2', 'E7': '4', 'E6': '6', 'E1': '7', 'E3': '1', 'E2': '9', 'E8': '3', 'A5': '6', 'H8': '8', 'H9': '4', 'H2': '7', 'H3': '3', 'H1': '5', 'H6': '1', 'H7': '6', 'H4': '2', 'H5': '9', 'D8': '6', 'D9': '9', 'D6': '7', 'D7': '1', 'D4': '4', 'D5': '3', 'D2': '2', 'D3': '5', 'D1': '8' } self.assertEquals(sudoku_test_hard_01.solve_sudoku(), sudoku_test_hard_01_solution) def test_solution_sudoku_hard_02(self): sudoku_test_hard_02 = NorvigAlgorithm( """520006000 000000701 300000000 000400800 600000050 000000000 041800000 000030020 008700000""", "0") sudoku_test_hard_02_solution = { 'G7': '6', 'G6': '5', 'G5': '2', 'G4': '8', 'G3': '1', 'G2': '4', 'G1': '9', 'G9': '3', 'G8': '7', 'C9': '2', 'C8': '6', 'C3': '4', 'C2': '1', 'C1': '3', 'C7': '5', 'C6': '7', 'C5': '8', 'C4': '9', 'E5': '7', 'E4': '2', 'F1': '4', 'F2': '5', 'F3': '3', 'F4': '6', 'F5': '9', 'F6': '8', 'F7': '2', 'F8': '1', 'F9': '7', 'B4': '5', 'B5': '4', 'B6': '2', 'B7': '7', 'B1': '8', 'B2': '9', 'B3': '6', 'B8': '3', 'B9': '1', 'I9': '5', 'I8': '4', 'I1': '2', 'I3': '8', 'I2': '3', 'I5': '6', 'I4': '7', 'I7': '1', 'I6': '9', 'A1': '5', 'A3': '7', 'A2': '2', 'E9': '4', 'A4': '3', 'A7': '4', 'A6': '6', 'A9': '9', 'A8': '8', 'E7': '3', 'E6': '1', 'E1': '6', 'E3': '9', 'E2': '8', 'E8': '5', 'A5': '1', 'H8': '2', 'H9': '8', 'H2': '6', 'H3': '5', 'H1': '7', 'H6': '4', 'H7': '9', 'H4': '1', 'H5': '3', 'D8': '9', 'D9': '6', 'D6': '3', 'D7': '8', 'D4': '4', 'D5': '5', 'D2': '7', 'D3': '2', 'D1': '1' } self.assertEquals(sudoku_test_hard_02.solve_sudoku(), sudoku_test_hard_02_solution) def test_solution_sudoku_hard_03(self): sudoku_test_hard_03 = NorvigAlgorithm( """600000803 040700000 000000000 000504070 300200000 106000000 020000050 000080600 000010000""", "0") sudoku_test_hard_03_solution = { 'G7': '1', 'G6': '7', 'G5': '4', 'G4': '6', 'G3': '3', 'G2': '2', 'G1': '8', 'G9': '9', 'G8': '5', 'C9': '7', 'C8': '6', 'C3': '9', 'C2': '3', 'C1': '5', 'C7': '4', 'C6': '8', 'C5': '2', 'C4': '1', 'E5': '9', 'E4': '2', 'F1': '1', 'F2': '5', 'F3': '6', 'F4': '8', 'F5': '7', 'F6': '3', 'F7': '2', 'F8': '9', 'F9': '4', 'B4': '7', 'B5': '3', 'B6': '6', 'B7': '9', 'B1': '2', 'B2': '4', 'B3': '8', 'B8': '1', 'B9': '5', 'I9': '8', 'I8': '3', 'I1': '4', 'I3': '5', 'I2': '6', 'I5': '1', 'I4': '9', 'I7': '7', 'I6': '2', 'A1': '6', 'A3': '7', 'A2': '1', 'E9': '6', 'A4': '4', 'A7': '8', 'A6': '9', 'A9': '3', 'A8': '2', 'E7': '5', 'E6': '1', 'E1': '3', 'E3': '4', 'E2': '7', 'E8': '8', 'A5': '5', 'H8': '4', 'H9': '2', 'H2': '9', 'H3': '1', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '3', 'H5': '8', 'D8': '7', 'D9': '1', 'D6': '4', 'D7': '3', 'D4': '5', 'D5': '6', 'D2': '8', 'D3': '2', 'D1': '9' } self.assertEquals(sudoku_test_hard_03.solve_sudoku(), sudoku_test_hard_03_solution) def test_solution_sudoku_hard_04(self): sudoku_test_hard_04 = NorvigAlgorithm( """480300000 000000071 020000000 705000060 000200800 000000000 001076000 300000400 000050000""", "0") sudoku_test_hard_04_solution = { 'G7': '9', 'G6': '6', 'G5': '7', 'G4': '4', 'G3': '1', 'G2': '5', 'G1': '8', 'G9': '3', 'G8': '2', 'C9': '4', 'C8': '8', 'C3': '6', 'C2': '2', 'C1': '1', 'C7': '3', 'C6': '7', 'C5': '9', 'C4': '5', 'E5': '6', 'E4': '2', 'F1': '2', 'F2': '6', 'F3': '8', 'F4': '7', 'F5': '3', 'F6': '1', 'F7': '5', 'F8': '4', 'F9': '9', 'B4': '6', 'B5': '8', 'B6': '4', 'B7': '2', 'B1': '5', 'B2': '9', 'B3': '3', 'B8': '7', 'B9': '1', 'I9': '8', 'I8': '1', 'I1': '6', 'I3': '2', 'I2': '4', 'I5': '5', 'I4': '9', 'I7': '7', 'I6': '3', 'A1': '4', 'A3': '7', 'A2': '8', 'E9': '7', 'A4': '3', 'A7': '6', 'A6': '2', 'A9': '5', 'A8': '9', 'E7': '8', 'E6': '5', 'E1': '9', 'E3': '4', 'E2': '1', 'E8': '3', 'A5': '1', 'H8': '5', 'H9': '6', 'H2': '7', 'H3': '9', 'H1': '3', 'H6': '8', 'H7': '4', 'H4': '1', 'H5': '2', 'D8': '6', 'D9': '2', 'D6': '9', 'D7': '1', 'D4': '8', 'D5': '4', 'D2': '3', 'D3': '5', 'D1': '7' } self.assertEquals(sudoku_test_hard_04.solve_sudoku(), sudoku_test_hard_04_solution) def test_solution_sudoku_hard_05(self): sudoku_test_hard_05 = NorvigAlgorithm( """000014000 030000200 070000000 000900030 601000000 000000080 200000104 000050600 000708000""", "0") sudoku_test_hard_05_solution = { 'G7': '1', 'G6': '9', 'G5': '3', 'G4': '6', 'G3': '5', 'G2': '8', 'G1': '2', 'G9': '4', 'G8': '7', 'C9': '3', 'C8': '1', 'C3': '8', 'C2': '7', 'C1': '5', 'C7': '4', 'C6': '6', 'C5': '9', 'C4': '2', 'A9': '7', 'A8': '5', 'F1': '3', 'F2': '2', 'F3': '9', 'F4': '1', 'F5': '4', 'F6': '5', 'F7': '7', 'F8': '8', 'F9': '6', 'B4': '5', 'B5': '8', 'B6': '7', 'B7': '2', 'B1': '1', 'B2': '3', 'B3': '4', 'B8': '6', 'B9': '9', 'I9': '5', 'I8': '9', 'I1': '4', 'I3': '6', 'I2': '1', 'I5': '2', 'I4': '7', 'I7': '3', 'I6': '8', 'A1': '9', 'A3': '2', 'A2': '6', 'E9': '2', 'A4': '3', 'A7': '8', 'A6': '4', 'E5': '7', 'E4': '8', 'E7': '9', 'E6': '3', 'E1': '6', 'E3': '1', 'E2': '5', 'E8': '4', 'A5': '1', 'H8': '2', 'H9': '8', 'H2': '9', 'H3': '3', 'H1': '7', 'H6': '1', 'H7': '6', 'H4': '4', 'H5': '5', 'D8': '3', 'D9': '1', 'D6': '2', 'D7': '5', 'D4': '9', 'D5': '6', 'D2': '4', 'D3': '7', 'D1': '8' } self.assertEquals(sudoku_test_hard_05.solve_sudoku(), sudoku_test_hard_05_solution) def test_solution_sudoku_hard_06(self): sudoku_test_hard_06 = NorvigAlgorithm( """000000520 080400000 030009000 501000600 200700000 000300000 600010000 000000704 000000030""", "0") sudoku_test_hard_06_solution = { 'G7': '8', 'G6': '3', 'G5': '1', 'G4': '9', 'G3': '7', 'G2': '4', 'G1': '6', 'G9': '2', 'G8': '5', 'C9': '8', 'C8': '6', 'C3': '5', 'C2': '3', 'C1': '7', 'C7': '4', 'C6': '9', 'C5': '2', 'C4': '1', 'A9': '9', 'A8': '2', 'F1': '8', 'F2': '6', 'F3': '4', 'F4': '3', 'F5': '5', 'F6': '1', 'F7': '2', 'F8': '9', 'F9': '7', 'B4': '4', 'B5': '6', 'B6': '5', 'B7': '3', 'B1': '9', 'B2': '8', 'B3': '2', 'B8': '7', 'B9': '1', 'I9': '6', 'I8': '3', 'I1': '1', 'I3': '8', 'I2': '2', 'I5': '7', 'I4': '5', 'I7': '9', 'I6': '4', 'A1': '4', 'A3': '6', 'A2': '1', 'E9': '5', 'A4': '8', 'A7': '5', 'A6': '7', 'E5': '4', 'E4': '7', 'E7': '1', 'E6': '6', 'E1': '2', 'E3': '3', 'E2': '9', 'E8': '8', 'A5': '3', 'H8': '1', 'H9': '4', 'H2': '5', 'H3': '9', 'H1': '3', 'H6': '2', 'H7': '7', 'H4': '6', 'H5': '8', 'D8': '4', 'D9': '3', 'D6': '8', 'D7': '6', 'D4': '2', 'D5': '9', 'D2': '7', 'D3': '1', 'D1': '5' } self.assertEquals(sudoku_test_hard_06.solve_sudoku(), sudoku_test_hard_06_solution) def test_solution_sudoku_hard_07(self): sudoku_test_hard_07 = NorvigAlgorithm( """602050000 000003040 000000000 430008000 010000200 000000700 500270000 000000081 000600000""", "0") sudoku_test_hard_07_solution = { 'G7': '4', 'G6': '1', 'G5': '7', 'G4': '2', 'G3': '8', 'G2': '6', 'G1': '5', 'G9': '3', 'G8': '9', 'C9': '5', 'C8': '6', 'C3': '4', 'C2': '7', 'C1': '3', 'C7': '1', 'C6': '2', 'C5': '9', 'C4': '8', 'A9': '9', 'A8': '7', 'F1': '2', 'F2': '9', 'F3': '5', 'F4': '4', 'F5': '1', 'F6': '6', 'F7': '7', 'F8': '3', 'F9': '8', 'B4': '7', 'B5': '6', 'B6': '3', 'B7': '8', 'B1': '9', 'B2': '5', 'B3': '1', 'B8': '4', 'B9': '2', 'I9': '7', 'I8': '2', 'I1': '1', 'I3': '3', 'I2': '4', 'I5': '8', 'I4': '6', 'I7': '5', 'I6': '9', 'A1': '6', 'A3': '2', 'A2': '8', 'E9': '4', 'A4': '1', 'A7': '3', 'A6': '4', 'E5': '3', 'E4': '9', 'E7': '2', 'E6': '7', 'E1': '8', 'E3': '6', 'E2': '1', 'E8': '5', 'A5': '5', 'H8': '8', 'H9': '1', 'H2': '2', 'H3': '9', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '3', 'H5': '4', 'D8': '1', 'D9': '6', 'D6': '8', 'D7': '9', 'D4': '5', 'D5': '2', 'D2': '3', 'D3': '7', 'D1': '4' } self.assertEquals(sudoku_test_hard_07.solve_sudoku(), sudoku_test_hard_07_solution) def test_solution_sudoku_hard_08(self): sudoku_test_hard_08 = NorvigAlgorithm( """052400000 000070100 000000000 000802000 300000600 090500000 106030000 000000089 700000000""", "0") sudoku_test_hard_08_solution = { 'G7': '2', 'G6': '7', 'G5': '3', 'G4': '9', 'G3': '6', 'G2': '8', 'G1': '1', 'G9': '5', 'G8': '4', 'C9': '4', 'C8': '6', 'C3': '1', 'C2': '7', 'C1': '9', 'C7': '8', 'C6': '5', 'C5': '2', 'C4': '3', 'A9': '7', 'A8': '3', 'F1': '2', 'F2': '9', 'F3': '8', 'F4': '5', 'F5': '6', 'F6': '3', 'F7': '4', 'F8': '7', 'F9': '1', 'B4': '6', 'B5': '7', 'B6': '9', 'B7': '1', 'B1': '8', 'B2': '3', 'B3': '4', 'B8': '5', 'B9': '2', 'I9': '6', 'I8': '1', 'I1': '7', 'I3': '9', 'I2': '4', 'I5': '5', 'I4': '2', 'I7': '3', 'I6': '8', 'A1': '6', 'A3': '2', 'A2': '5', 'E9': '8', 'A4': '4', 'A7': '9', 'A6': '1', 'E5': '9', 'E4': '7', 'E7': '6', 'E6': '4', 'E1': '3', 'E3': '5', 'E2': '1', 'E8': '2', 'A5': '8', 'H8': '8', 'H9': '9', 'H2': '2', 'H3': '3', 'H1': '5', 'H6': '6', 'H7': '7', 'H4': '1', 'H5': '4', 'D8': '9', 'D9': '3', 'D6': '2', 'D7': '5', 'D4': '8', 'D5': '1', 'D2': '6', 'D3': '7', 'D1': '4' } self.assertEquals(sudoku_test_hard_08.solve_sudoku(), sudoku_test_hard_08_solution) def test_solution_sudoku_hard_09(self): sudoku_test_hard_09 = NorvigAlgorithm( """602050000 000004030 000000000 430008000 010000200 000000700 500270000 000000081 000600000""", "0") sudoku_test_hard_09_solution = { 'G7': '3', 'G6': '1', 'G5': '7', 'G4': '2', 'G3': '8', 'G2': '6', 'G1': '5', 'G9': '4', 'G8': '9', 'C9': '5', 'C8': '6', 'C3': '4', 'C2': '7', 'C1': '3', 'C7': '1', 'C6': '2', 'C5': '9', 'C4': '8', 'A9': '9', 'A8': '7', 'F1': '2', 'F2': '9', 'F3': '5', 'F4': '3', 'F5': '1', 'F6': '6', 'F7': '7', 'F8': '4', 'F9': '8', 'B4': '7', 'B5': '6', 'B6': '4', 'B7': '8', 'B1': '9', 'B2': '5', 'B3': '1', 'B8': '3', 'B9': '2', 'I9': '7', 'I8': '2', 'I1': '1', 'I3': '3', 'I2': '4', 'I5': '8', 'I4': '6', 'I7': '5', 'I6': '9', 'A1': '6', 'A3': '2', 'A2': '8', 'E9': '3', 'A4': '1', 'A7': '4', 'A6': '3', 'E5': '4', 'E4': '9', 'E7': '2', 'E6': '7', 'E1': '8', 'E3': '6', 'E2': '1', 'E8': '5', 'A5': '5', 'H8': '8', 'H9': '1', 'H2': '2', 'H3': '9', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '4', 'H5': '3', 'D8': '1', 'D9': '6', 'D6': '8', 'D7': '9', 'D4': '5', 'D5': '2', 'D2': '3', 'D3': '7', 'D1': '4' } self.assertEquals(sudoku_test_hard_09.solve_sudoku(), sudoku_test_hard_09_solution) def test_solution_sudoku_hard_10(self): sudoku_test_hard_10 = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") sudoku_test_hard_10_solution = { 'G7': '9', 'G6': '2', 'G5': '7', 'G4': '5', 'G3': '8', 'G2': '6', 'G1': '3', 'G9': '4', 'G8': '1', 'C9': '7', 'C8': '3', 'C3': '1', 'C2': '8', 'C1': '6', 'C7': '5', 'C6': '9', 'C5': '2', 'C4': '4', 'A9': '8', 'A8': '4', 'F1': '8', 'F2': '3', 'F3': '6', 'F4': '2', 'F5': '9', 'F6': '5', 'F7': '4', 'F8': '7', 'F9': '1', 'B4': '7', 'B5': '8', 'B6': '6', 'B7': '1', 'B1': '5', 'B2': '4', 'B3': '3', 'B8': '2', 'B9': '9', 'I9': '6', 'I8': '8', 'I1': '2', 'I3': '5', 'I2': '7', 'I5': '1', 'I4': '9', 'I7': '3', 'I6': '4', 'A1': '7', 'A3': '2', 'A2': '9', 'E9': '5', 'A4': '3', 'A7': '6', 'A6': '1', 'E5': '3', 'E4': '1', 'E7': '8', 'E6': '7', 'E1': '9', 'E3': '4', 'E2': '2', 'E8': '6', 'A5': '5', 'H8': '5', 'H9': '2', 'H2': '1', 'H3': '9', 'H1': '4', 'H6': '3', 'H7': '7', 'H4': '8', 'H5': '6', 'D8': '9', 'D9': '3', 'D6': '8', 'D7': '2', 'D4': '6', 'D5': '4', 'D2': '5', 'D3': '7', 'D1': '1' } self.assertEquals(sudoku_test_hard_10.solve_sudoku(), sudoku_test_hard_10_solution) ################ Test validation correct format sudoku data ################ def test_soduku_to_solve_only_contains_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_cannot_contain_letters(self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000A65 800000000 060502000 400000C00 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_cannot_contain_dot_as_empty_value_if_the_empty_value_is_zero( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 ....80100 ...000000 107040000 ..0..0465 800000000 060502000 400000200 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_not_contain_spaces_as_empty_value_if_the_empty_value_is_zero( self): sudoku_test_only_numbers = NorvigAlgorithm( """ 923 8 1 1 1 7 4 465 8 6 5 2 4 2 9 """, "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_valid_when_contains_81_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_invalid_when_contains_less_than_81_numbers( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_invalid_when_contains_more_than_81_numbers( self): sudoku_test_only_numbers = NorvigAlgorithm( """092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000 000000065 060502000""", "0") def test_soduku_to_solve_is_valid_when_characters_to_replace_are_dot(self): sudoku_test_only_numbers = NorvigAlgorithm( """.923..... ....8.1.. ......... 1.7.4.... .......65 8........ .6.5.2... 4.....7.. ...9.....""", ".") def test_soduku_to_solve_is_valid_when_characters_to_replace_are_porcentage( self): sudoku_test_only_numbers = NorvigAlgorithm( """%923%%%%% %%%%8%1%% %%%%%%%%% 1%7%4%%%% %%%%%%%65 8%%%%%%%% %6%5%2%%% 4%%%%%7%% %%%9%%%%%""", "%") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())
class TestNorvigAlgorithm(unittest.TestCase): def setUp(self): # Test algorithm Norvig attributes sudoku_test_values = """003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""" self.sudoku_test_attributes = NorvigAlgorithm(sudoku_test_values, "0") self.len_squares = 81 self.len_unitlist = 27 self.units_c2 = [['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'], ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']] self.peers_c2 = set(['A2', 'B2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2', 'C1', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'A1', 'A3', 'B1', 'B3']) ################ Test correct creation of attributes ################ def test_attributes_len_squares_is_81(self): self.assertEquals(self.len_squares,len(self.sudoku_test_attributes.squares)) def test_attributes_len_unitlist_is_27(self): self.assertEquals(self.len_unitlist,len(self.sudoku_test_attributes.unitlist)) def test_attributes_values_units_c2(self): self.assertEquals(self.units_c2,self.sudoku_test_attributes.units['C2']) def test_attributes_values_peers_c2(self): self.assertEquals(self.peers_c2,self.sudoku_test_attributes.peers['C2']) def test_solution_time_different_than_zero(self): self.sudoku_test_attributes.solve_sudoku() self.assertTrue(self.sudoku_test_attributes.get_time()> 0.0) ################ Test to verify the solution easy sudokus ################ def test_solution_sudoku_easy_01(self): sudoku_test_easy_01 = NorvigAlgorithm("""003020600 900305001 001806400 008102900 700000008 006708200 002609500 800203009 005010300""", "0") sudoku_test_easy_01_solution = {'I6': '7', 'H9': '9', 'I2': '9', 'E8': '3', 'H3': '4', 'H7': '7', 'I7': '3', 'I4': '4', 'H5': '5', 'F9': '5', 'G7': '5', 'G6': '9', 'G5': '8', 'E1': '7', 'G3': '2', 'G2': '7', 'G1': '3', 'I1': '6', 'C8': '9', 'I3': '5', 'E5': '6', 'I5': '1', 'C9': '3', 'G9': '4', 'G8': '1', 'A1': '4', 'A3': '3', 'A2': '8', 'A5': '2', 'A4': '9', 'A7': '6', 'A6': '1', 'C3': '1', 'C2': '5', 'C1': '2', 'E6': '4', 'C7': '4', 'C6': '6', 'C5': '7', 'C4': '8', 'I9': '2', 'D8': '7', 'I8': '8', 'E4': '5', 'D9': '6', 'H8': '6', 'F6': '8', 'A9': '7', 'G4': '6', 'A8': '5', 'E7': '1', 'E3': '9', 'F1': '1', 'F2': '3', 'F3': '6', 'F4': '7', 'F5': '9', 'E2': '2', 'F7': '2', 'F8': '4', 'D2': '4', 'H1': '8', 'H6': '3', 'H2': '1', 'H4': '2', 'D3': '8', 'B4': '3', 'B5': '4', 'B6': '5', 'B7': '8', 'E9': '8', 'B1': '9', 'B2': '6', 'B3': '7', 'D6': '2', 'D7': '9', 'D4': '1', 'D5': '3', 'B8': '2', 'B9': '1', 'D1': '5'} self.assertEquals(sudoku_test_easy_01.solve_sudoku(), sudoku_test_easy_01_solution) def test_solution_sudoku_easy_02(self): sudoku_test_easy_02 = NorvigAlgorithm("""200080300 060070084 030500209 000105408 000000000 402706000 301007040 720040060 004010003""", "0") sudoku_test_easy_02_solution = {'I6': '2', 'H9': '5', 'I2': '5', 'E8': '2', 'H3': '8', 'H7': '1', 'I7': '7', 'I4': '8', 'H5': '4', 'F9': '1', 'G7': '8', 'G6': '7', 'G5': '5', 'E1': '5', 'G3': '1', 'G2': '9', 'G1': '3', 'I1': '6', 'C8': '1', 'I3': '4', 'E5': '9', 'I5': '1', 'C9': '9', 'G9': '2', 'G8': '4', 'A1': '2', 'A3': '5', 'A2': '4', 'A5': '8', 'A4': '9', 'A7': '3', 'A6': '1', 'C3': '7', 'C2': '3', 'C1': '8', 'E6': '8', 'C7': '2', 'C6': '4', 'C5': '6', 'C4': '5', 'I9': '3', 'D8': '3', 'I8': '9', 'E4': '4', 'D9': '8', 'H8': '6', 'F6': '6', 'A9': '6', 'G4': '6', 'A8': '7', 'E7': '6', 'E3': '3', 'F1': '4', 'F2': '8', 'F3': '2', 'F4': '7', 'F5': '3', 'E2': '1', 'F7': '9', 'F8': '5', 'D2': '7', 'H1': '7', 'H6': '9', 'H2': '2', 'H4': '3', 'D3': '6', 'B4': '2', 'B5': '7', 'B6': '3', 'B7': '5', 'E9': '7', 'B1': '1', 'B2': '6', 'B3': '9', 'D6': '5', 'D7': '4', 'D4': '1', 'D5': '2', 'B8': '8', 'B9': '4', 'D1': '9'} self.assertEquals(sudoku_test_easy_02.solve_sudoku(), sudoku_test_easy_02_solution) def test_solution_sudoku_easy_03(self): sudoku_test_easy_03 = NorvigAlgorithm("""000000907 000420180 000705026 100904000 050000040 000507009 920108000 034059000 507000000""", "0") sudoku_test_easy_03_solution = {'I6': '3', 'H9': '1', 'I2': '1', 'E8': '4', 'H3': '4', 'H7': '6', 'I7': '8', 'I4': '6', 'H5': '5', 'F9': '9', 'G7': '5', 'G6': '8', 'G5': '7', 'E1': '6', 'G3': '6', 'G2': '2', 'G1': '9', 'I1': '5', 'C8': '2', 'I3': '7', 'E5': '1', 'I5': '4', 'C9': '6', 'G9': '4', 'G8': '3', 'A1': '4', 'A3': '2', 'A2': '6', 'A5': '3', 'A4': '8', 'A7': '9', 'A6': '1', 'C3': '1', 'C2': '8', 'C1': '3', 'E6': '2', 'C7': '4', 'C6': '5', 'C5': '9', 'C4': '7', 'I9': '2', 'D8': '6', 'I8': '9', 'E4': '3', 'D9': '5', 'H8': '7', 'F6': '7', 'A9': '7', 'G4': '1', 'A8': '5', 'E7': '7', 'E3': '9', 'F1': '2', 'F2': '4', 'F3': '8', 'F4': '5', 'F5': '6', 'E2': '5', 'F7': '3', 'F8': '1', 'D2': '7', 'H1': '8', 'H6': '9', 'H2': '3', 'H4': '2', 'D3': '3', 'B4': '4', 'B5': '2', 'B6': '6', 'B7': '1', 'E9': '8', 'B1': '7', 'B2': '9', 'B3': '5', 'D6': '4', 'D7': '2', 'D4': '9', 'D5': '8', 'B8': '8', 'B9': '3', 'D1': '1'} self.assertEquals(sudoku_test_easy_03.solve_sudoku(), sudoku_test_easy_03_solution) def test_solution_sudoku_easy_04(self): sudoku_test_easy_04 = NorvigAlgorithm("""030050040 008010500 460000012 070502080 000603000 040109030 250000098 001020600 080060020""", "0") sudoku_test_easy_04_solution = {'I6': '5', 'H9': '5', 'I2': '8', 'E8': '5', 'H3': '1', 'H7': '6', 'I7': '1', 'I4': '9', 'H5': '2', 'F9': '6', 'G7': '4', 'G6': '1', 'G5': '3', 'E1': '8', 'G3': '6', 'G2': '5', 'G1': '2', 'I1': '7', 'C8': '1', 'I3': '4', 'E5': '7', 'I5': '6', 'C9': '2', 'G9': '8', 'G8': '9', 'A1': '1', 'A3': '7', 'A2': '3', 'A5': '5', 'A4': '2', 'A7': '8', 'A6': '6', 'C3': '5', 'C2': '6', 'C1': '4', 'E6': '3', 'C7': '3', 'C6': '7', 'C5': '9', 'C4': '8', 'I9': '3', 'D8': '8', 'I8': '2', 'E4': '6', 'D9': '1', 'H8': '7', 'F6': '9', 'A9': '9', 'G4': '7', 'A8': '4', 'E7': '2', 'E3': '9', 'F1': '5', 'F2': '4', 'F3': '2', 'F4': '1', 'F5': '8', 'E2': '1', 'F7': '7', 'F8': '3', 'D2': '7', 'H1': '3', 'H6': '8', 'H2': '9', 'H4': '4', 'D3': '3', 'B4': '3', 'B5': '1', 'B6': '4', 'B7': '5', 'E9': '4', 'B1': '9', 'B2': '2', 'B3': '8', 'D6': '2', 'D7': '9', 'D4': '5', 'D5': '4', 'B8': '6', 'B9': '7', 'D1': '6'} self.assertEquals(sudoku_test_easy_04.solve_sudoku(), sudoku_test_easy_04_solution) def test_solution_sudoku_easy_05(self): sudoku_test_easy_05 = NorvigAlgorithm("""020810740 700003100 090002805 009040087 400208003 160030200 302700060 005600008 076051090""", "0") sudoku_test_easy_05_solution = {'I6': '1', 'H9': '8', 'I2': '7', 'E8': '1', 'H3': '5', 'H7': '3', 'I7': '4', 'I4': '3', 'H5': '2', 'F9': '4', 'G7': '5', 'G6': '9', 'G5': '8', 'E1': '4', 'G3': '2', 'G2': '4', 'G1': '3', 'I1': '8', 'C8': '3', 'I3': '6', 'E5': '6', 'I5': '5', 'C9': '5', 'G9': '1', 'G8': '6', 'A1': '5', 'A3': '3', 'A2': '2', 'A5': '1', 'A4': '8', 'A7': '7', 'A6': '6', 'C3': '1', 'C2': '9', 'C1': '6', 'E6': '8', 'C7': '8', 'C6': '2', 'C5': '7', 'C4': '4', 'I9': '2', 'D8': '8', 'I8': '9', 'E4': '2', 'D9': '7', 'H8': '7', 'F6': '7', 'A9': '9', 'G4': '7', 'A8': '4', 'E7': '9', 'E3': '7', 'F1': '1', 'F2': '6', 'F3': '8', 'F4': '9', 'F5': '3', 'E2': '5', 'F7': '2', 'F8': '5', 'D2': '3', 'H1': '9', 'H6': '4', 'H2': '1', 'H4': '6', 'D3': '9', 'B4': '5', 'B5': '9', 'B6': '3', 'B7': '1', 'E9': '3', 'B1': '7', 'B2': '8', 'B3': '4', 'D6': '5', 'D7': '6', 'D4': '1', 'D5': '4', 'B8': '2', 'B9': '6', 'D1': '2'} self.assertEquals(sudoku_test_easy_05.solve_sudoku(), sudoku_test_easy_05_solution) def test_solution_sudoku_easy_06(self): sudoku_test_easy_06 = NorvigAlgorithm("""100920000 524010000 000000070 050008102 000000000 402700090 060000000 000030945 000071006""", "0") sudoku_test_easy_06_solution = {'G7': '7', 'G6': '9', 'G5': '8', 'G4': '4', 'G3': '5', 'G2': '6', 'G1': '2', 'G9': '3', 'G8': '1', 'C9': '1', 'C8': '7', 'C3': '3', 'C2': '9', 'C1': '8', 'C7': '2', 'C6': '4', 'C5': '5', 'C4': '6', 'A9': '4', 'A8': '8', 'F1': '4', 'F2': '1', 'F3': '2', 'F4': '7', 'F5': '6', 'F6': '5', 'F7': '3', 'F8': '9', 'F9': '8', 'B4': '8', 'B5': '1', 'B6': '7', 'B7': '6', 'B1': '5', 'B2': '2', 'B3': '4', 'B8': '3', 'B9': '9', 'I9': '6', 'I8': '2', 'I1': '3', 'I3': '9', 'I2': '4', 'I5': '7', 'I4': '5', 'I7': '8', 'I6': '1', 'A1': '1', 'A3': '6', 'A2': '7', 'E9': '7', 'A4': '9', 'A7': '5', 'A6': '3', 'E5': '9', 'E4': '1', 'E7': '4', 'E6': '2', 'E1': '6', 'E3': '8', 'E2': '3', 'E8': '5', 'A5': '2', 'H8': '4', 'H9': '5', 'H2': '8', 'H3': '1', 'H1': '7', 'H6': '6', 'H7': '9', 'H4': '2', 'H5': '3', 'D8': '6', 'D9': '2', 'D6': '8', 'D7': '1', 'D4': '3', 'D5': '4', 'D2': '5', 'D3': '7', 'D1': '9'} self.assertEquals(sudoku_test_easy_06.solve_sudoku(), sudoku_test_easy_06_solution) def test_solution_sudoku_easy_07(self): sudoku_test_easy_07 = NorvigAlgorithm("""043080250 600000000 000001094 900004070 000608000 010200003 820500000 000000005 034090710""", "0") sudoku_test_easy_07_solution = {'G7': '4', 'G6': '7', 'G5': '6', 'G4': '5', 'G3': '1', 'G2': '2', 'G1': '8', 'G9': '9', 'G8': '3', 'C9': '4', 'C8': '9', 'C3': '5', 'C2': '8', 'C1': '2', 'C7': '6', 'C6': '1', 'C5': '3', 'A4': '9', 'A9': '7', 'A8': '5', 'F1': '4', 'F2': '1', 'F3': '8', 'F4': '2', 'F5': '7', 'F6': '9', 'F7': '5', 'F8': '6', 'F9': '3', 'B4': '4', 'B5': '2', 'B6': '5', 'B7': '3', 'E9': '2', 'B1': '6', 'B2': '7', 'B3': '9', 'C4': '7', 'B8': '8', 'B9': '1', 'I9': '6', 'I8': '1', 'I1': '5', 'I3': '4', 'I2': '3', 'I5': '9', 'I4': '8', 'I7': '7', 'I6': '2', 'A1': '1', 'A3': '3', 'A2': '4', 'A5': '8', 'E8': '4', 'A7': '2', 'A6': '6', 'E5': '1', 'E4': '6', 'E7': '9', 'E6': '8', 'E1': '3', 'E3': '7', 'E2': '5', 'H8': '2', 'H9': '5', 'H2': '9', 'H3': '6', 'H1': '7', 'H6': '3', 'H7': '8', 'H4': '1', 'H5': '4', 'D8': '7', 'D9': '8', 'D6': '4', 'D7': '1', 'D4': '3', 'D5': '5', 'D2': '6', 'D3': '2', 'D1': '9'} self.assertEquals(sudoku_test_easy_07.solve_sudoku(), sudoku_test_easy_07_solution) def test_solution_sudoku_easy_08(self): sudoku_test_easy_08 = NorvigAlgorithm("""480006902 002008001 900370060 840010200 003704100 001060049 020085007 700900600 609200018""", "0") sudoku_test_easy_08_solution = {'I6': '7', 'H9': '5', 'I2': '5', 'E8': '8', 'H3': '8', 'H7': '6', 'I7': '4', 'I4': '2', 'H5': '4', 'F9': '9', 'G7': '3', 'G6': '5', 'G5': '8', 'E1': '5', 'G3': '4', 'G2': '2', 'G1': '1', 'I1': '6', 'C8': '6', 'I3': '9', 'E5': '2', 'I5': '3', 'C9': '4', 'G9': '7', 'G8': '9', 'A1': '4', 'A3': '7', 'A2': '8', 'A5': '5', 'A4': '1', 'A7': '9', 'A6': '6', 'C3': '5', 'C2': '1', 'C1': '9', 'E6': '4', 'C7': '8', 'C6': '2', 'C5': '7', 'C4': '3', 'I9': '8', 'D8': '7', 'I8': '1', 'E4': '7', 'D9': '3', 'H8': '2', 'F6': '3', 'A9': '2', 'G4': '6', 'A8': '3', 'E7': '1', 'E3': '3', 'F1': '2', 'F2': '7', 'F3': '1', 'F4': '8', 'F5': '6', 'E2': '9', 'F7': '5', 'F8': '4', 'D2': '4', 'H1': '7', 'H6': '1', 'H2': '3', 'H4': '9', 'D3': '6', 'B4': '4', 'B5': '9', 'B6': '8', 'B7': '7', 'E9': '6', 'B1': '3', 'B2': '6', 'B3': '2', 'D6': '9', 'D7': '2', 'D4': '5', 'D5': '1', 'B8': '5', 'B9': '1', 'D1': '8'} self.assertEquals(sudoku_test_easy_08.solve_sudoku(), sudoku_test_easy_08_solution) def test_solution_sudoku_easy_09(self): sudoku_test_easy_09 = NorvigAlgorithm("""000900002 050123400 030000160 908000000 070000090 000000205 091000050 007439020 400007000""", "0") sudoku_test_easy_09_solution = {'I6': '7', 'H9': '1', 'I2': '2', 'E8': '9', 'H3': '7', 'H7': '6', 'I7': '9', 'I4': '5', 'H5': '3', 'F9': '5', 'G7': '7', 'G6': '2', 'G5': '8', 'E1': '2', 'G3': '1', 'G2': '9', 'G1': '3', 'I1': '4', 'C8': '6', 'I3': '6', 'E5': '4', 'I5': '1', 'C9': '9', 'G9': '4', 'G8': '5', 'A1': '8', 'A3': '4', 'A2': '1', 'A5': '7', 'A4': '9', 'A7': '5', 'A6': '6', 'C3': '2', 'C2': '3', 'C1': '7', 'E6': '1', 'C7': '1', 'C6': '4', 'C5': '5', 'C4': '8', 'I9': '3', 'D8': '1', 'I8': '8', 'E4': '3', 'D9': '7', 'H8': '2', 'F6': '8', 'A9': '2', 'G4': '6', 'A8': '3', 'E7': '8', 'E3': '5', 'F1': '1', 'F2': '6', 'F3': '3', 'F4': '7', 'F5': '9', 'E2': '7', 'F7': '2', 'F8': '4', 'D2': '4', 'H1': '5', 'H6': '9', 'H2': '8', 'H4': '4', 'D3': '8', 'B4': '1', 'B5': '2', 'B6': '3', 'B7': '4', 'E9': '6', 'B1': '6', 'B2': '5', 'B3': '9', 'D6': '5', 'D7': '3', 'D4': '2', 'D5': '6', 'B8': '7', 'B9': '8', 'D1': '9'} self.assertEquals(sudoku_test_easy_09.solve_sudoku(), sudoku_test_easy_09_solution) def test_solution_sudoku_easy_10(self): sudoku_test_easy_10 = NorvigAlgorithm("""001900003 900700160 030005007 050000009 004302600 200000070 600100030 042007006 500006800""", "0") sudoku_test_easy_10_solution = {'G7': '7', 'G6': '4', 'G5': '5', 'G4': '1', 'G3': '9', 'G2': '8', 'G1': '6', 'G9': '2', 'G8': '3', 'C9': '7', 'C8': '2', 'C3': '8', 'C2': '3', 'C1': '4', 'C7': '9', 'C6': '5', 'C5': '1', 'C4': '6', 'A9': '3', 'A8': '5', 'F1': '2', 'F2': '1', 'F3': '6', 'F4': '5', 'F5': '8', 'F6': '9', 'F7': '3', 'F8': '7', 'F9': '4', 'B4': '7', 'B5': '4', 'B6': '3', 'B7': '1', 'B1': '9', 'B2': '2', 'B3': '5', 'B8': '6', 'B9': '8', 'I9': '1', 'I8': '4', 'I1': '5', 'I3': '3', 'I2': '7', 'I5': '9', 'I4': '2', 'I7': '8', 'I6': '6', 'A1': '7', 'A3': '1', 'A2': '6', 'E9': '5', 'A4': '9', 'A7': '4', 'A6': '8', 'E5': '7', 'E4': '3', 'E7': '6', 'E6': '2', 'E1': '8', 'E3': '4', 'E2': '9', 'E8': '1', 'A5': '2', 'H8': '9', 'H9': '6', 'H2': '4', 'H3': '2', 'H1': '1', 'H6': '7', 'H7': '5', 'H4': '8', 'H5': '3', 'D8': '8', 'D9': '9', 'D6': '1', 'D7': '2', 'D4': '4', 'D5': '6', 'D2': '5', 'D3': '7', 'D1': '3'} self.assertEquals(sudoku_test_easy_10.solve_sudoku(), sudoku_test_easy_10_solution) ################ Test to verify the solution hard sudokus ################ def test_solution_sudoku_hard_01(self): sudoku_test_hard_01 = NorvigAlgorithm("""400000805 030000000 000700000 020000060 000080400 000010000 000603070 500200000 104000000""", "0") sudoku_test_hard_01_solution = {'G7': '5', 'G6': '3', 'G5': '4', 'G4': '6', 'G3': '9', 'G2': '8', 'G1': '2', 'G9': '1', 'G8': '7', 'C9': '6', 'C8': '1', 'C3': '8', 'C2': '5', 'C1': '9', 'C7': '3', 'C6': '4', 'C5': '2', 'C4': '7', 'E5': '8', 'E4': '5', 'F1': '3', 'F2': '4', 'F3': '6', 'F4': '9', 'F5': '1', 'F6': '2', 'F7': '7', 'F8': '5', 'F9': '8', 'B4': '1', 'B5': '5', 'B6': '8', 'B7': '9', 'B1': '6', 'B2': '3', 'B3': '2', 'B8': '4', 'B9': '7', 'I9': '3', 'I8': '9', 'I1': '1', 'I3': '4', 'I2': '6', 'I5': '7', 'I4': '8', 'I7': '2', 'I6': '5', 'A1': '4', 'A3': '7', 'A2': '1', 'E9': '2', 'A4': '3', 'A7': '8', 'A6': '9', 'A9': '5', 'A8': '2', 'E7': '4', 'E6': '6', 'E1': '7', 'E3': '1', 'E2': '9', 'E8': '3', 'A5': '6', 'H8': '8', 'H9': '4', 'H2': '7', 'H3': '3', 'H1': '5', 'H6': '1', 'H7': '6', 'H4': '2', 'H5': '9', 'D8': '6', 'D9': '9', 'D6': '7', 'D7': '1', 'D4': '4', 'D5': '3', 'D2': '2', 'D3': '5', 'D1': '8'} self.assertEquals(sudoku_test_hard_01.solve_sudoku(), sudoku_test_hard_01_solution) def test_solution_sudoku_hard_02(self): sudoku_test_hard_02 = NorvigAlgorithm("""520006000 000000701 300000000 000400800 600000050 000000000 041800000 000030020 008700000""", "0") sudoku_test_hard_02_solution = {'G7': '6', 'G6': '5', 'G5': '2', 'G4': '8', 'G3': '1', 'G2': '4', 'G1': '9', 'G9': '3', 'G8': '7', 'C9': '2', 'C8': '6', 'C3': '4', 'C2': '1', 'C1': '3', 'C7': '5', 'C6': '7', 'C5': '8', 'C4': '9', 'E5': '7', 'E4': '2', 'F1': '4', 'F2': '5', 'F3': '3', 'F4': '6', 'F5': '9', 'F6': '8', 'F7': '2', 'F8': '1', 'F9': '7', 'B4': '5', 'B5': '4', 'B6': '2', 'B7': '7', 'B1': '8', 'B2': '9', 'B3': '6', 'B8': '3', 'B9': '1', 'I9': '5', 'I8': '4', 'I1': '2', 'I3': '8', 'I2': '3', 'I5': '6', 'I4': '7', 'I7': '1', 'I6': '9', 'A1': '5', 'A3': '7', 'A2': '2', 'E9': '4', 'A4': '3', 'A7': '4', 'A6': '6', 'A9': '9', 'A8': '8', 'E7': '3', 'E6': '1', 'E1': '6', 'E3': '9', 'E2': '8', 'E8': '5', 'A5': '1', 'H8': '2', 'H9': '8', 'H2': '6', 'H3': '5', 'H1': '7', 'H6': '4', 'H7': '9', 'H4': '1', 'H5': '3', 'D8': '9', 'D9': '6', 'D6': '3', 'D7': '8', 'D4': '4', 'D5': '5', 'D2': '7', 'D3': '2', 'D1': '1'} self.assertEquals(sudoku_test_hard_02.solve_sudoku(), sudoku_test_hard_02_solution) def test_solution_sudoku_hard_03(self): sudoku_test_hard_03 = NorvigAlgorithm("""600000803 040700000 000000000 000504070 300200000 106000000 020000050 000080600 000010000""", "0") sudoku_test_hard_03_solution = {'G7': '1', 'G6': '7', 'G5': '4', 'G4': '6', 'G3': '3', 'G2': '2', 'G1': '8', 'G9': '9', 'G8': '5', 'C9': '7', 'C8': '6', 'C3': '9', 'C2': '3', 'C1': '5', 'C7': '4', 'C6': '8', 'C5': '2', 'C4': '1', 'E5': '9', 'E4': '2', 'F1': '1', 'F2': '5', 'F3': '6', 'F4': '8', 'F5': '7', 'F6': '3', 'F7': '2', 'F8': '9', 'F9': '4', 'B4': '7', 'B5': '3', 'B6': '6', 'B7': '9', 'B1': '2', 'B2': '4', 'B3': '8', 'B8': '1', 'B9': '5', 'I9': '8', 'I8': '3', 'I1': '4', 'I3': '5', 'I2': '6', 'I5': '1', 'I4': '9', 'I7': '7', 'I6': '2', 'A1': '6', 'A3': '7', 'A2': '1', 'E9': '6', 'A4': '4', 'A7': '8', 'A6': '9', 'A9': '3', 'A8': '2', 'E7': '5', 'E6': '1', 'E1': '3', 'E3': '4', 'E2': '7', 'E8': '8', 'A5': '5', 'H8': '4', 'H9': '2', 'H2': '9', 'H3': '1', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '3', 'H5': '8', 'D8': '7', 'D9': '1', 'D6': '4', 'D7': '3', 'D4': '5', 'D5': '6', 'D2': '8', 'D3': '2', 'D1': '9'} self.assertEquals(sudoku_test_hard_03.solve_sudoku(), sudoku_test_hard_03_solution) def test_solution_sudoku_hard_04(self): sudoku_test_hard_04 = NorvigAlgorithm("""480300000 000000071 020000000 705000060 000200800 000000000 001076000 300000400 000050000""", "0") sudoku_test_hard_04_solution = {'G7': '9', 'G6': '6', 'G5': '7', 'G4': '4', 'G3': '1', 'G2': '5', 'G1': '8', 'G9': '3', 'G8': '2', 'C9': '4', 'C8': '8', 'C3': '6', 'C2': '2', 'C1': '1', 'C7': '3', 'C6': '7', 'C5': '9', 'C4': '5', 'E5': '6', 'E4': '2', 'F1': '2', 'F2': '6', 'F3': '8', 'F4': '7', 'F5': '3', 'F6': '1', 'F7': '5', 'F8': '4', 'F9': '9', 'B4': '6', 'B5': '8', 'B6': '4', 'B7': '2', 'B1': '5', 'B2': '9', 'B3': '3', 'B8': '7', 'B9': '1', 'I9': '8', 'I8': '1', 'I1': '6', 'I3': '2', 'I2': '4', 'I5': '5', 'I4': '9', 'I7': '7', 'I6': '3', 'A1': '4', 'A3': '7', 'A2': '8', 'E9': '7', 'A4': '3', 'A7': '6', 'A6': '2', 'A9': '5', 'A8': '9', 'E7': '8', 'E6': '5', 'E1': '9', 'E3': '4', 'E2': '1', 'E8': '3', 'A5': '1', 'H8': '5', 'H9': '6', 'H2': '7', 'H3': '9', 'H1': '3', 'H6': '8', 'H7': '4', 'H4': '1', 'H5': '2', 'D8': '6', 'D9': '2', 'D6': '9', 'D7': '1', 'D4': '8', 'D5': '4', 'D2': '3', 'D3': '5', 'D1': '7'} self.assertEquals(sudoku_test_hard_04.solve_sudoku(), sudoku_test_hard_04_solution) def test_solution_sudoku_hard_05(self): sudoku_test_hard_05 = NorvigAlgorithm("""000014000 030000200 070000000 000900030 601000000 000000080 200000104 000050600 000708000""", "0") sudoku_test_hard_05_solution = {'G7': '1', 'G6': '9', 'G5': '3', 'G4': '6', 'G3': '5', 'G2': '8', 'G1': '2', 'G9': '4', 'G8': '7', 'C9': '3', 'C8': '1', 'C3': '8', 'C2': '7', 'C1': '5', 'C7': '4', 'C6': '6', 'C5': '9', 'C4': '2', 'A9': '7', 'A8': '5', 'F1': '3', 'F2': '2', 'F3': '9', 'F4': '1', 'F5': '4', 'F6': '5', 'F7': '7', 'F8': '8', 'F9': '6', 'B4': '5', 'B5': '8', 'B6': '7', 'B7': '2', 'B1': '1', 'B2': '3', 'B3': '4', 'B8': '6', 'B9': '9', 'I9': '5', 'I8': '9', 'I1': '4', 'I3': '6', 'I2': '1', 'I5': '2', 'I4': '7', 'I7': '3', 'I6': '8', 'A1': '9', 'A3': '2', 'A2': '6', 'E9': '2', 'A4': '3', 'A7': '8', 'A6': '4', 'E5': '7', 'E4': '8', 'E7': '9', 'E6': '3', 'E1': '6', 'E3': '1', 'E2': '5', 'E8': '4', 'A5': '1', 'H8': '2', 'H9': '8', 'H2': '9', 'H3': '3', 'H1': '7', 'H6': '1', 'H7': '6', 'H4': '4', 'H5': '5', 'D8': '3', 'D9': '1', 'D6': '2', 'D7': '5', 'D4': '9', 'D5': '6', 'D2': '4', 'D3': '7', 'D1': '8'} self.assertEquals(sudoku_test_hard_05.solve_sudoku(), sudoku_test_hard_05_solution) def test_solution_sudoku_hard_06(self): sudoku_test_hard_06 = NorvigAlgorithm("""000000520 080400000 030009000 501000600 200700000 000300000 600010000 000000704 000000030""", "0") sudoku_test_hard_06_solution = {'G7': '8', 'G6': '3', 'G5': '1', 'G4': '9', 'G3': '7', 'G2': '4', 'G1': '6', 'G9': '2', 'G8': '5', 'C9': '8', 'C8': '6', 'C3': '5', 'C2': '3', 'C1': '7', 'C7': '4', 'C6': '9', 'C5': '2', 'C4': '1', 'A9': '9', 'A8': '2', 'F1': '8', 'F2': '6', 'F3': '4', 'F4': '3', 'F5': '5', 'F6': '1', 'F7': '2', 'F8': '9', 'F9': '7', 'B4': '4', 'B5': '6', 'B6': '5', 'B7': '3', 'B1': '9', 'B2': '8', 'B3': '2', 'B8': '7', 'B9': '1', 'I9': '6', 'I8': '3', 'I1': '1', 'I3': '8', 'I2': '2', 'I5': '7', 'I4': '5', 'I7': '9', 'I6': '4', 'A1': '4', 'A3': '6', 'A2': '1', 'E9': '5', 'A4': '8', 'A7': '5', 'A6': '7', 'E5': '4', 'E4': '7', 'E7': '1', 'E6': '6', 'E1': '2', 'E3': '3', 'E2': '9', 'E8': '8', 'A5': '3', 'H8': '1', 'H9': '4', 'H2': '5', 'H3': '9', 'H1': '3', 'H6': '2', 'H7': '7', 'H4': '6', 'H5': '8', 'D8': '4', 'D9': '3', 'D6': '8', 'D7': '6', 'D4': '2', 'D5': '9', 'D2': '7', 'D3': '1', 'D1': '5'} self.assertEquals(sudoku_test_hard_06.solve_sudoku(), sudoku_test_hard_06_solution) def test_solution_sudoku_hard_07(self): sudoku_test_hard_07 = NorvigAlgorithm("""602050000 000003040 000000000 430008000 010000200 000000700 500270000 000000081 000600000""", "0") sudoku_test_hard_07_solution = {'G7': '4', 'G6': '1', 'G5': '7', 'G4': '2', 'G3': '8', 'G2': '6', 'G1': '5', 'G9': '3', 'G8': '9', 'C9': '5', 'C8': '6', 'C3': '4', 'C2': '7', 'C1': '3', 'C7': '1', 'C6': '2', 'C5': '9', 'C4': '8', 'A9': '9', 'A8': '7', 'F1': '2', 'F2': '9', 'F3': '5', 'F4': '4', 'F5': '1', 'F6': '6', 'F7': '7', 'F8': '3', 'F9': '8', 'B4': '7', 'B5': '6', 'B6': '3', 'B7': '8', 'B1': '9', 'B2': '5', 'B3': '1', 'B8': '4', 'B9': '2', 'I9': '7', 'I8': '2', 'I1': '1', 'I3': '3', 'I2': '4', 'I5': '8', 'I4': '6', 'I7': '5', 'I6': '9', 'A1': '6', 'A3': '2', 'A2': '8', 'E9': '4', 'A4': '1', 'A7': '3', 'A6': '4', 'E5': '3', 'E4': '9', 'E7': '2', 'E6': '7', 'E1': '8', 'E3': '6', 'E2': '1', 'E8': '5', 'A5': '5', 'H8': '8', 'H9': '1', 'H2': '2', 'H3': '9', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '3', 'H5': '4', 'D8': '1', 'D9': '6', 'D6': '8', 'D7': '9', 'D4': '5', 'D5': '2', 'D2': '3', 'D3': '7', 'D1': '4'} self.assertEquals(sudoku_test_hard_07.solve_sudoku(), sudoku_test_hard_07_solution) def test_solution_sudoku_hard_08(self): sudoku_test_hard_08 = NorvigAlgorithm("""052400000 000070100 000000000 000802000 300000600 090500000 106030000 000000089 700000000""", "0") sudoku_test_hard_08_solution = {'G7': '2', 'G6': '7', 'G5': '3', 'G4': '9', 'G3': '6', 'G2': '8', 'G1': '1', 'G9': '5', 'G8': '4', 'C9': '4', 'C8': '6', 'C3': '1', 'C2': '7', 'C1': '9', 'C7': '8', 'C6': '5', 'C5': '2', 'C4': '3', 'A9': '7', 'A8': '3', 'F1': '2', 'F2': '9', 'F3': '8', 'F4': '5', 'F5': '6', 'F6': '3', 'F7': '4', 'F8': '7', 'F9': '1', 'B4': '6', 'B5': '7', 'B6': '9', 'B7': '1', 'B1': '8', 'B2': '3', 'B3': '4', 'B8': '5', 'B9': '2', 'I9': '6', 'I8': '1', 'I1': '7', 'I3': '9', 'I2': '4', 'I5': '5', 'I4': '2', 'I7': '3', 'I6': '8', 'A1': '6', 'A3': '2', 'A2': '5', 'E9': '8', 'A4': '4', 'A7': '9', 'A6': '1', 'E5': '9', 'E4': '7', 'E7': '6', 'E6': '4', 'E1': '3', 'E3': '5', 'E2': '1', 'E8': '2', 'A5': '8', 'H8': '8', 'H9': '9', 'H2': '2', 'H3': '3', 'H1': '5', 'H6': '6', 'H7': '7', 'H4': '1', 'H5': '4', 'D8': '9', 'D9': '3', 'D6': '2', 'D7': '5', 'D4': '8', 'D5': '1', 'D2': '6', 'D3': '7', 'D1': '4'} self.assertEquals(sudoku_test_hard_08.solve_sudoku(), sudoku_test_hard_08_solution) def test_solution_sudoku_hard_09(self): sudoku_test_hard_09 = NorvigAlgorithm("""602050000 000004030 000000000 430008000 010000200 000000700 500270000 000000081 000600000""", "0") sudoku_test_hard_09_solution = {'G7': '3', 'G6': '1', 'G5': '7', 'G4': '2', 'G3': '8', 'G2': '6', 'G1': '5', 'G9': '4', 'G8': '9', 'C9': '5', 'C8': '6', 'C3': '4', 'C2': '7', 'C1': '3', 'C7': '1', 'C6': '2', 'C5': '9', 'C4': '8', 'A9': '9', 'A8': '7', 'F1': '2', 'F2': '9', 'F3': '5', 'F4': '3', 'F5': '1', 'F6': '6', 'F7': '7', 'F8': '4', 'F9': '8', 'B4': '7', 'B5': '6', 'B6': '4', 'B7': '8', 'B1': '9', 'B2': '5', 'B3': '1', 'B8': '3', 'B9': '2', 'I9': '7', 'I8': '2', 'I1': '1', 'I3': '3', 'I2': '4', 'I5': '8', 'I4': '6', 'I7': '5', 'I6': '9', 'A1': '6', 'A3': '2', 'A2': '8', 'E9': '3', 'A4': '1', 'A7': '4', 'A6': '3', 'E5': '4', 'E4': '9', 'E7': '2', 'E6': '7', 'E1': '8', 'E3': '6', 'E2': '1', 'E8': '5', 'A5': '5', 'H8': '8', 'H9': '1', 'H2': '2', 'H3': '9', 'H1': '7', 'H6': '5', 'H7': '6', 'H4': '4', 'H5': '3', 'D8': '1', 'D9': '6', 'D6': '8', 'D7': '9', 'D4': '5', 'D5': '2', 'D2': '3', 'D3': '7', 'D1': '4'} self.assertEquals(sudoku_test_hard_09.solve_sudoku(), sudoku_test_hard_09_solution) def test_solution_sudoku_hard_10(self): sudoku_test_hard_10 = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") sudoku_test_hard_10_solution = {'G7': '9', 'G6': '2', 'G5': '7', 'G4': '5', 'G3': '8', 'G2': '6', 'G1': '3', 'G9': '4', 'G8': '1', 'C9': '7', 'C8': '3', 'C3': '1', 'C2': '8', 'C1': '6', 'C7': '5', 'C6': '9', 'C5': '2', 'C4': '4', 'A9': '8', 'A8': '4', 'F1': '8', 'F2': '3', 'F3': '6', 'F4': '2', 'F5': '9', 'F6': '5', 'F7': '4', 'F8': '7', 'F9': '1', 'B4': '7', 'B5': '8', 'B6': '6', 'B7': '1', 'B1': '5', 'B2': '4', 'B3': '3', 'B8': '2', 'B9': '9', 'I9': '6', 'I8': '8', 'I1': '2', 'I3': '5', 'I2': '7', 'I5': '1', 'I4': '9', 'I7': '3', 'I6': '4', 'A1': '7', 'A3': '2', 'A2': '9', 'E9': '5', 'A4': '3', 'A7': '6', 'A6': '1', 'E5': '3', 'E4': '1', 'E7': '8', 'E6': '7', 'E1': '9', 'E3': '4', 'E2': '2', 'E8': '6', 'A5': '5', 'H8': '5', 'H9': '2', 'H2': '1', 'H3': '9', 'H1': '4', 'H6': '3', 'H7': '7', 'H4': '8', 'H5': '6', 'D8': '9', 'D9': '3', 'D6': '8', 'D7': '2', 'D4': '6', 'D5': '4', 'D2': '5', 'D3': '7', 'D1': '1'} self.assertEquals(sudoku_test_hard_10.solve_sudoku(), sudoku_test_hard_10_solution) ################ Test validation correct format sudoku data ################ def test_soduku_to_solve_only_contains_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_cannot_contain_letters(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000A65 800000000 060502000 400000C00 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_cannot_contain_dot_as_empty_value_if_the_empty_value_is_zero(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 ....80100 ...000000 107040000 ..0..0465 800000000 060502000 400000200 000900000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_not_contain_spaces_as_empty_value_if_the_empty_value_is_zero(self): sudoku_test_only_numbers = NorvigAlgorithm(""" 923 8 1 1 1 7 4 465 8 6 5 2 4 2 9 """, "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_valid_when_contains_81_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000""", "0") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_invalid_when_contains_less_than_81_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000""", "0") self.assertFalse(sudoku_test_only_numbers.sudoku_data_is_valid()) def test_soduku_to_solve_is_invalid_when_contains_more_than_81_numbers(self): sudoku_test_only_numbers = NorvigAlgorithm("""092300000 000080100 000000000 107040000 000000065 800000000 060502000 400000700 000900000 000000065 060502000""", "0") def test_soduku_to_solve_is_valid_when_characters_to_replace_are_dot(self): sudoku_test_only_numbers = NorvigAlgorithm(""".923..... ....8.1.. ......... 1.7.4.... .......65 8........ .6.5.2... 4.....7.. ...9.....""", ".") def test_soduku_to_solve_is_valid_when_characters_to_replace_are_porcentage(self): sudoku_test_only_numbers = NorvigAlgorithm("""%923%%%%% %%%%8%1%% %%%%%%%%% 1%7%4%%%% %%%%%%%65 8%%%%%%%% %6%5%2%%% 4%%%%%7%% %%%9%%%%%""", "%") self.assertTrue(sudoku_test_only_numbers.sudoku_data_is_valid())