def test_world_hardest_sudoku(self): # given See http://www.telegraph.co.uk/news/science/science-news/9359579/Worlds-hardest-sudoku-can-you-crack-it.html """ 8 1246 24569 | 2347 12357 1234 | 13569 4579 1345679 12459 124 3 | 6 12578 1248 | 1589 45789 14579 1456 7 456 | 348 9 1348 | 2 458 13456 ------------------------+------------------------+------------------------ 123469 5 2469 | 2389 2368 7 | 1689 2489 12469 12369 12368 269 | 2389 4 5 | 7 289 1269 24679 2468 24679 | 1 268 2689 | 5689 3 24569 ------------------------+------------------------+------------------------ 23457 234 1 | 23479 237 2349 | 359 6 8 23467 2346 8 | 5 2367 23469 | 39 1 2379 23567 9 2567 | 2378 123678 12368 | 4 257 2357 """ grid = '8..........36......7..9.2...5...7.......457.....1...3...1....68..85...1..9....4..' # when values = solution.solve(grid) # then self.assertTrue(solution.is_solved_correctly(values)) print() solution.display(values)
def test_is_solved_correctly_Incorrect(self): # given t_values = solution.grid_values( '483921657967345821251876493548132976729564138136798245372689514814253769695417381' ) # only last char is 1 # then self.assertFalse(solution.is_solved_correctly(t_values))
def test_is_solved_correctly_True(self): # given t_values = solution.grid_values( '483921657967345821251876493548132976729564138136798245372689514814253769695417382' ) # then self.assertTrue(solution.is_solved_correctly(t_values))
def test_is_solved_correctly_False(self): # given t_values = solution.grid_values( '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..' ) # then self.assertFalse(solution.is_solved_correctly(t_values))
def test_solve_positive(self): # given grid = '2.............62....1....7...6..8...3...9...7...6..4...4....8....52.............3' # when values = solution.solve(grid) # then self.assertTrue(solution.is_solved_correctly(values)) solution.display(values)
def test_search(self): # given t_values = solution.grid_values( '.....97..4..7...2...18...39.3....4...769.531...4....9.84...39...1...8..3..26.....' ) # when values = solution.search(t_values) # then self.assertTrue(solution.is_solved_correctly(values)) print() lines = solution.display(values)
def test_reduce_puzzle(self): # given t_values = solution.grid_values( '..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..' ) # when values = solution.reduce_puzzle(t_values) # then self.assertTrue(solution.is_solved_correctly(values)) print() solution.display(values)
def test_performance(self): with open('hard_sudoku.txt') as sudoku_file: sudoku_puzzles = sudoku_file.readlines() for grid in sudoku_puzzles: solution.is_solved_correctly(solution.solve(grid.strip()))