def setUp(self): valid_grid_0_chars = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' self.valid_grid_0 = make_grid_from_string(valid_grid_0_chars) self._all_possible_values = {'Gh': '123456789', 'Fe': '123456789', 'Ab': '123456789', 'Db': '123456789', 'Ei': '123456789', 'Ba': '123456789', 'Ac': '123456789', 'Eh': '123456789', 'Ih': '123456789', 'He': '123456789', 'Eg': '123456789', 'Hd': '123456789', 'Bi': '123456789', 'Cg': '123456789', 'Cc': '123456789', 'Hi': '123456789', 'Af': '123456789', 'Aa': '123456789', 'Ia': '123456789', 'Bg': '123456789', 'Gf': '123456789', 'Ai': '123456789', 'Hb': '123456789', 'Ae': '123456789', 'Fa': '123456789', 'Ge': '123456789', 'Hh': '123456789', 'Cd': '123456789', 'Ha': '123456789', 'Fi': '123456789', 'Hf': '123456789', 'Gg': '123456789', 'De': '123456789', 'Df': '123456789', 'Hg': '123456789', 'Dd': '123456789', 'Da': '123456789', 'Ga': '123456789', 'Ic': '123456789', 'Bc': '123456789', 'Ci': '123456789', 'Dh': '123456789', 'Bd': '123456789', 'Di': '123456789', 'Bf': '123456789', 'Id': '123456789', 'Cb': '123456789', 'Gd': '123456789', 'Hc': '123456789', 'Gi': '123456789', 'Ch': '123456789', 'Ee': '123456789', 'Ea': '123456789', 'Ff': '123456789', 'Fg': '123456789', 'Fc': '123456789', 'Bb': '123456789', 'Ie': '123456789', 'If': '123456789', 'Ad': '123456789', 'Eb': '123456789', 'Gb': '123456789', 'Ib': '123456789', 'Cf': '123456789', 'Ef': '123456789', 'Ig': '123456789', 'Dg': '123456789', 'Ah': '123456789', 'Ed': '123456789', 'Fb': '123456789', 'Gc': '123456789', 'Fd': '123456789', 'Bh': '123456789', 'Ce': '123456789', 'Ag': '123456789', 'Dc': '123456789', 'Ii': '123456789', 'Ec': '123456789', 'Ca': '123456789', 'Fh': '123456789', 'Be': '123456789'} solved_puzzle_string = '437256189569183742812794536673921458985467321241538697124379865798645213356812974' self.solved_puzzle = make_grid_from_string(solved_puzzle_string) self.solved_puzzle.parse_grid_candidates()
def test_repr_4(self): """tests that the __repr__ returns the proper string """ puzzle_string = '769123485812456937534789216381964752426517893975238641143872569697345128258691374' puzzle = make_grid_from_string(puzzle_string) result = repr(puzzle) self.assertEqual(result, puzzle_string)
def test_repr_3(self): """tests that the __repr__ returns the proper string """ puzzle_string = '.................................................................................' puzzle = make_grid_from_string(puzzle_string) result = repr(puzzle) self.assertEqual(result, puzzle_string)
def test_repr_2(self): """tests that the __repr__ returns the proper string """ puzzle_string = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' puzzle = make_grid_from_string(puzzle_string) result = repr(puzzle) self.assertEqual(result, puzzle_string)
def test_repr_1(self): """tests that the __repr__ returns the proper string """ puzzle_string = '.6..7.4..5......12...1....7..5.4.27..3.....4..19.6.8...4...1...79.6....8..1.5..2.' puzzle = make_grid_from_string(puzzle_string) result = repr(puzzle) self.assertEqual(result, puzzle_string)
def test_is_solved_invalid_full_puzzle(self): """tests that calling is_solved() on a solved puzzle returns True """ invalid_full_puzzle_string = '444444444569183742812794536673921458985467321241538697124379865798645213356812974' full_invalid_puzzle = make_grid_from_string(invalid_full_puzzle_string) unsolved = full_invalid_puzzle.is_solved() self.assertFalse(unsolved)
def test_parse_grid_1_in_Aa(self): """ tests whether the possible remaining values assigned for a given puzzle are correct """ grid_chars_w_1_in_Aa = '1................................................................................' valid_grid_w_1_in_Aa = make_grid_from_string(grid_chars_w_1_in_Aa) is_valid = valid_grid_w_1_in_Aa.is_valid() self.assertTrue(is_valid) _expected_candidates = {'Gh': '123456789', 'Fe': '123456789', 'Ab': '123456789', 'Db': '123456789', 'Ei': '123456789', 'Ba': '123456789', 'Ac': '123456789', 'Eh': '123456789', 'Ih': '123456789', 'He': '123456789', 'Eg': '123456789', 'Hd': '123456789', 'Bi': '123456789', 'Cg': '123456789', 'Cc': '123456789', 'Hi': '123456789', 'Af': '123456789', 'Aa': '1........', 'Ia': '123456789', 'Bg': '123456789', 'Gf': '123456789', 'Ai': '123456789', 'Hb': '123456789', 'Ae': '123456789', 'Fa': '123456789', 'Ge': '123456789', 'Hh': '123456789', 'Cd': '123456789', 'Ha': '123456789', 'Fi': '123456789', 'Hf': '123456789', 'Gg': '123456789', 'De': '123456789', 'Df': '123456789', 'Hg': '123456789', 'Dd': '123456789', 'Da': '123456789', 'Ga': '123456789', 'Ic': '123456789', 'Bc': '123456789', 'Ci': '123456789', 'Dh': '123456789', 'Bd': '123456789', 'Di': '123456789', 'Bf': '123456789', 'Id': '123456789', 'Cb': '123456789', 'Gd': '123456789', 'Hc': '123456789', 'Gi': '123456789', 'Ch': '123456789', 'Ee': '123456789', 'Ea': '123456789', 'Ff': '123456789', 'Fg': '123456789', 'Fc': '123456789', 'Bb': '123456789', 'Ie': '123456789', 'If': '123456789', 'Ad': '123456789', 'Eb': '123456789', 'Gb': '123456789', 'Ib': '123456789', 'Cf': '123456789', 'Ef': '123456789', 'Ig': '123456789', 'Dg': '123456789', 'Ah': '123456789', 'Ed': '123456789', 'Fb': '123456789', 'Gc': '123456789', 'Fd': '123456789', 'Bh': '123456789', 'Ce': '123456789', 'Ag': '123456789', 'Dc': '123456789', 'Ii': '123456789', 'Ec': '123456789', 'Ca': '123456789', 'Fh': '123456789', 'Be': '123456789'} valid_grid_w_1_in_Aa.parse_grid_candidates() result = valid_grid_w_1_in_Aa.candidates self.assertEqual(result.keys(), self._all_possible_values.keys()) self.assertTrue(all(result[square] == _expected_candidates[square] for square in SQUARES))
def test_is_solved_invalid_puzzle(self): """tests that calling is_solved() on a solved puzzle returns True """ invalid_puzzle_string = '4444448.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' unfinished_puzzle = make_grid_from_string(invalid_puzzle_string) unsolved = unfinished_puzzle.is_solved() self.assertFalse(unsolved)
def test_is_solved_empty_puzzle(self): """tests that calling is_solved() on a solved puzzle returns True """ empty_puzzle_string = '.................................................................................' empty_puzzle = make_grid_from_string(empty_puzzle_string) unsolved = empty_puzzle.is_solved() self.assertFalse(unsolved)
def test_PuzzleSolver_object(self): """tests if a PuzzleSolver object is created """ puzzle_string = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' puzzle = make_grid_from_string(puzzle_string) puzzle_clone = puzzle.clone() solver = PuzzleSolver(puzzle_clone) self.assertIsInstance(solver, PuzzleSolver)
def _run_random_data_against_expected(self, data, num_tests): """de-duplicate the testing code""" for idx in self.picked_tests: if idx >= num_tests: continue else: puzzle = make_grid_from_string(data[idx]) result = puzzle.is_valid() self.assertTrue(result)
def _make_and_solve_puzzle(self, puzzle_string): """ takes a string makes a puzzle, and clones it :return: PuzzleSolver from that cloned puzzle """ puzzle = make_grid_from_string(puzzle_string) puzzle_clone = puzzle.clone() puzzle_solver = PuzzleSolver(puzzle_clone) puzzle_solver.solve() return puzzle_solver
def _apply_solve(puzzle_string): """ :return: a tuple containing the result of the solve() on the provided string, and a repr of the "solved" puzzle """ grid = make_grid_from_string(puzzle_string) grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) result = solver.solve() return result
def _apply_eliminate_propagate_fill(puzzle_string): """ :return: a tuple containing the result of eliminate_propagate_fill() on the provided string, and a repr of the "solved" puzzle """ grid = make_grid_from_string(puzzle_string) grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) result = solver.eliminate_propagate_fill() return result, repr(solver._puzzle)
def test_grid_instance_factory_from_string_block(self): my_string1 = """ 400000805 030000000 000700000 020000060 000080400 000010000 000603070 500200000 104000000""" grid1_from_string = make_grid_from_string(my_string1) self.assertIsInstance(grid1_from_string, Puzzle)
def setUp(self): grid_string_0 = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' self.grid_0 = make_grid_from_string(grid_string_0) self.grid_0.parse_grid_candidates() grid_string_1 = '1...895..5....7819........72.4..8.7.9.71.54.8.8.7..3.531.4..78.4682....3..985...1' self.grid_1 = make_grid_from_string(grid_string_1) self.grid_1.parse_grid_candidates() grid_string_2 = '003020600900305001001806400008102900700000008006708200002609500800203009005010300' self.grid_2 = make_grid_from_string(grid_string_2) self.grid_2.parse_grid_candidates() grid_string_3 = '.82...59....8.1..3..52...78...37842...........27945...91...68..2..7.9....73...95.' self.grid_3 = make_grid_from_string(grid_string_3) self.grid_3.parse_grid_candidates() grid_string_4 = '437...189.6.183.......9.536.73..1...9..4.7..1...5..69.124.7.......645.1.356...974' self.grid_4 = make_grid_from_string(grid_string_4) self.grid_4.parse_grid_candidates() # Not so hard - no search needed self.g3 = '003020600900305001001806400008102900700000008006708200002609500800203009005010300' self.s3 = '483921657967345821251876493548132976729564138136798245372689514814253769695417382' self.ps3 = self._make_and_solve_puzzle(self.s3) self.g4 = '.82...59....8.1..3..52...78...37842...........27945...91...68..2..7.9....73...95.' self.s4 = '382467591796851243145293678561378429439612785827945316914526837258739164673184952' self.ps4 = self._make_and_solve_puzzle(self.s4) self.g5 = '437...189.6.183.......9.536.73..1...9..4.7..1...5..69.124.7.......645.1.356...974' self.s5 = '437256189569183742812794536673921458985467321241538697124379865798645213356812974' self.ps5 = self._make_and_solve_puzzle(self.s5) self.gEmpty = '.................................................................................' self.sEmpty = '.................................................................................' self.psEmpty = self._make_and_solve_puzzle(self.sEmpty)
def test_grid_instance_factory_from_string_formatted(self): my_string2 = """ 4 . . |. . . |8 . 5 . 3 . |. . . |. . . . . . |7 . . |. . . ------+------+------ . 2 . |. . . |. 6 . . . . |. 8 . |4 . . . . . |. 1 . |. . . ------+------+------ . . . |6 . 3 |. 7 . 5 . . |2 . . |. . . 1 . 4 |. . . |. . . """ grid2_from_string = make_grid_from_string(my_string2) self.assertIsInstance(grid2_from_string, Puzzle)
def test_eliminate_candidates_grid_solved(self): """tests that eliminate candidates does not change the state of an empty puzzle """ grid_string = '437256189569183742812794536673921458985467321241538697124379865798645213356812974' grid = make_grid_from_string(grid_string) grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) pre_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | ...4..... ..3...... ......7.. | .2....... ....5.... .....6... | 1........ .......8. ........9 |\n\ B | ....5.... .....6... ........9 | 1........ .......8. ..3...... | ......7.. ...4..... .2....... |\n\ C | .......8. 1........ .2....... | ......7.. ........9 ...4..... | ....5.... ..3...... .....6... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | .....6... ......7.. ..3...... | ........9 .2....... 1........ | ...4..... ....5.... .......8. |\n\ E | ........9 .......8. ....5.... | ...4..... .....6... ......7.. | ..3...... .2....... 1........ |\n\ F | .2....... ...4..... 1........ | ....5.... ..3...... .......8. | .....6... ........9 ......7.. |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 1........ .2....... ...4..... | ..3...... ......7.. ........9 | .......8. .....6... ....5.... |\n\ H | ......7.. ........9 .......8. | .....6... ...4..... ....5.... | .2....... 1........ ..3...... |\n\ I | ..3...... ....5.... .....6... | .......8. 1........ .2....... | ........9 ......7.. ...4..... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), pre_candidates) solver.eliminate_candidates() post_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | ...4..... ..3...... ......7.. | .2....... ....5.... .....6... | 1........ .......8. ........9 |\n\ B | ....5.... .....6... ........9 | 1........ .......8. ..3...... | ......7.. ...4..... .2....... |\n\ C | .......8. 1........ .2....... | ......7.. ........9 ...4..... | ....5.... ..3...... .....6... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | .....6... ......7.. ..3...... | ........9 .2....... 1........ | ...4..... ....5.... .......8. |\n\ E | ........9 .......8. ....5.... | ...4..... .....6... ......7.. | ..3...... .2....... 1........ |\n\ F | .2....... ...4..... 1........ | ....5.... ..3...... .......8. | .....6... ........9 ......7.. |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 1........ .2....... ...4..... | ..3...... ......7.. ........9 | .......8. .....6... ....5.... |\n\ H | ......7.. ........9 .......8. | .....6... ...4..... ....5.... | .2....... 1........ ..3...... |\n\ I | ..3...... ....5.... .....6... | .......8. 1........ .2....... | ........9 ......7.. ...4..... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), post_candidates)
def test_eliminate_candidates_grid_empty(self): """tests that eliminate candidates does not change the state of an empty puzzle """ grid_string = '.................................................................................' grid = make_grid_from_string(grid_string) grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) pre_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ B | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ C | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ E | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ F | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ H | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ I | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), pre_candidates) solver.eliminate_candidates() post_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ B | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ C | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ E | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ F | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ H | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ I | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), post_candidates)
def test_prppagate_full(self): """tests that propagation on an empty puzzle does not change the state """ grid_string = '437256189569183742812794536673921458985467321241538697124379865798645213356812974' grid = make_grid_from_string(grid_string) grid.get_puzzle_str() grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) pre_puzzle = """ a b c d e f g h i A 4 3 7|2 5 6|1 8 9 B 5 6 9|1 8 3|7 4 2 C 8 1 2|7 9 4|5 3 6 -----+-----+----- D 6 7 3|9 2 1|4 5 8 E 9 8 5|4 6 7|3 2 1 F 2 4 1|5 3 8|6 9 7 -----+-----+----- G 1 2 4|3 7 9|8 6 5 H 7 9 8|6 4 5|2 1 3 I 3 5 6|8 1 2|9 7 4 """ pre_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | ...4..... ..3...... ......7.. | .2....... ....5.... .....6... | 1........ .......8. ........9 |\n\ B | ....5.... .....6... ........9 | 1........ .......8. ..3...... | ......7.. ...4..... .2....... |\n\ C | .......8. 1........ .2....... | ......7.. ........9 ...4..... | ....5.... ..3...... .....6... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | .....6... ......7.. ..3...... | ........9 .2....... 1........ | ...4..... ....5.... .......8. |\n\ E | ........9 .......8. ....5.... | ...4..... .....6... ......7.. | ..3...... .2....... 1........ |\n\ F | .2....... ...4..... 1........ | ....5.... ..3...... .......8. | .....6... ........9 ......7.. |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 1........ .2....... ...4..... | ..3...... ......7.. ........9 | .......8. .....6... ....5.... |\n\ H | ......7.. ........9 .......8. | .....6... ...4..... ....5.... | .2....... 1........ ..3...... |\n\ I | ..3...... ....5.... .....6... | .......8. 1........ .2....... | ........9 ......7.. ...4..... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), pre_candidates) self.assertEqual(solver._puzzle.get_puzzle_str(), pre_puzzle) solver.propagate() post_puzzle = """ a b c d e f g h i A 4 3 7|2 5 6|1 8 9 B 5 6 9|1 8 3|7 4 2 C 8 1 2|7 9 4|5 3 6 -----+-----+----- D 6 7 3|9 2 1|4 5 8 E 9 8 5|4 6 7|3 2 1 F 2 4 1|5 3 8|6 9 7 -----+-----+----- G 1 2 4|3 7 9|8 6 5 H 7 9 8|6 4 5|2 1 3 I 3 5 6|8 1 2|9 7 4 """ post_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | ...4..... ..3...... ......7.. | .2....... ....5.... .....6... | 1........ .......8. ........9 |\n\ B | ....5.... .....6... ........9 | 1........ .......8. ..3...... | ......7.. ...4..... .2....... |\n\ C | .......8. 1........ .2....... | ......7.. ........9 ...4..... | ....5.... ..3...... .....6... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | .....6... ......7.. ..3...... | ........9 .2....... 1........ | ...4..... ....5.... .......8. |\n\ E | ........9 .......8. ....5.... | ...4..... .....6... ......7.. | ..3...... .2....... 1........ |\n\ F | .2....... ...4..... 1........ | ....5.... ..3...... .......8. | .....6... ........9 ......7.. |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 1........ .2....... ...4..... | ..3...... ......7.. ........9 | .......8. .....6... ....5.... |\n\ H | ......7.. ........9 .......8. | .....6... ...4..... ....5.... | .2....... 1........ ..3...... |\n\ I | ..3...... ....5.... .....6... | .......8. 1........ .2....... | ........9 ......7.. ...4..... |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), post_candidates) self.assertEqual(solver._puzzle.get_puzzle_str(), post_puzzle)
def test_prppagate_empty(self): """tests that propagation on an empty puzzle does not change the state """ grid_string = '.................................................................................' grid = make_grid_from_string(grid_string) grid.parse_grid_candidates() solver = PuzzleSolver(grid.clone()) pre_puzzle = """ a b c d e f g h i A . . .|. . .|. . . B . . .|. . .|. . . C . . .|. . .|. . . -----+-----+----- D . . .|. . .|. . . E . . .|. . .|. . . F . . .|. . .|. . . -----+-----+----- G . . .|. . .|. . . H . . .|. . .|. . . I . . .|. . .|. . . """ pre_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ B | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ C | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ E | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ F | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ H | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ I | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), pre_candidates) self.assertEqual(solver._puzzle.get_puzzle_str(), pre_puzzle) solver.propagate() post_puzzle = """ a b c d e f g h i A . . .|. . .|. . . B . . .|. . .|. . . C . . .|. . .|. . . -----+-----+----- D . . .|. . .|. . . E . . .|. . .|. . . F . . .|. . .|. . . -----+-----+----- G . . .|. . .|. . . H . . .|. . .|. . . I . . .|. . .|. . . """ post_candidates = """ a b c d e f g h i \n\ --------------------------------- --------------------------------- --------------------------------- \n\ A | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ B | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ C | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ D | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ E | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ F | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ G | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ H | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ I | 123456789 123456789 123456789 | 123456789 123456789 123456789 | 123456789 123456789 123456789 |\n\ --------------------------------- --------------------------------- --------------------------------- \n\ """ self.assertEqual(str(solver._puzzle), post_candidates) self.assertEqual(solver._puzzle.get_puzzle_str(), post_puzzle)
def test_grid_instance_factory_from_string1(self): my_string0 = '4.... /.8.5.3..## :; ...slskfj.....7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......' grid0_from_string = make_grid_from_string(my_string0) self.assertIsInstance(grid0_from_string, Puzzle)