def test_a_star(self): b = [[4, 1, 2], [0, 5, 3], [7, 8, 6]] p = hw.TilePuzzle(b) self.assertEqual(p.find_solution_a_star(), ['up', 'right', 'right', 'down', 'down'])
def test_a_star2(self): b = [[1, 2, 3], [4, 0, 5], [6, 7, 8]] p = hw.TilePuzzle(b) self.assertEqual(list(p.find_solution_a_star()), ['right', 'down', 'left', 'left', 'up', 'right', 'down', 'right', 'up', 'left', 'left', 'down', 'right', 'right'])
def test_iddfs(self): b = [[4, 1, 2], [0, 5, 3], [7, 8, 6]] p = hw.TilePuzzle(b) solutions = p.find_solutions_iddfs() self.assertEqual(next(solutions), ['up', 'right', 'right', 'down', 'down'])
def test_iddfs2(self): b = [[1, 2, 3], [4, 0, 8], [7, 6, 5]] p = hw.TilePuzzle(b) self.assertEqual(list(p.find_solutions_iddfs()), [['down', 'right', 'up', 'left', 'down', 'right'], ['right', 'down', 'left', 'up', 'right', 'down']])
def test_get_board(self): p = hw.TilePuzzle([[1, 2], [3, 0]]) self.assertEqual(p.get_board(), [[1, 2], [3, 0]])
def test_successors2(self): b = [[1, 2, 3], [4, 0, 5], [6, 7, 8]] p = hw.TilePuzzle(b) for move, new_p in p.successors(): print move, new_p.get_board()
def test_is_solved2(self): p = hw.TilePuzzle([[0, 1], [3, 2]]) self.assertEqual(p.is_solved(), False)
def test_is_solved(self): p = hw.TilePuzzle([[1, 2], [3, 0]]) self.assertEqual(p.is_solved(), True)
def test_get_board2(self): p = hw.TilePuzzle([[0, 1], [3, 2]]) self.assertEqual(p.get_board(), [[0, 1], [3, 2]])