def test_unique_states_seen(self): astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3, 4, 5, 6, 7, 8, 0]), Board(3, [1, 2, 0, 4, 5, 3, 7, 8, 6])) self.assertEqual(19, astar.unique_states_seen())
def test_shortest_moves(self): astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3, 4, 5, 6, 7, 8, 0]), Board(3, [1, 2, 0, 4, 5, 3, 7, 8, 6])) self.assertEqual([Board.Move.UP, Board.Move.UP], astar.moves())
def solution(self): astar = AStar(lambda x, y: 1, lambda x, y: 1, Board(self._n, self._root), Board.goal(self._n)) moves_str = "".join(str(move) for move in astar.moves()) return rapport_tiles(self._n, self._root) + \ f"Solution: {len(astar.moves())}, " + moves_str + "\n" + \ f"States seen: {astar.unique_states_seen()}\n"
def test_shortest_max_moves_needed(self): astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3, 4, 5, 6, 7, 8, 0]), Board(3, [1, 2, 3, 4, 0, 8, 7, 6, 5])) self.assertEqual([Board.Move.UP, Board.Move.LEFT, Board.Move.DOWN, Board.Move.RIGHT, Board.Move.UP, Board.Move.LEFT, ], astar.moves())
def test_init(self): self.assertIsNotNone(AStar(lambda x: 1, manhattan, Board(3, [1,2,3,4,5,6,7,8,0]), Board(3, [1,2,3,4,5,6,7,8,0])))
def test_shortest_with_one_move_needed(self): astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3, 4, 5, 6, 7, 8, 0]), Board(3, [1, 2, 3, 4, 5, 6, 7, 0, 8])) self.assertEqual([Board.Move.LEFT], astar.moves())