예제 #1
0
def test_reachable_locations():
    """ Tests reachable_locations """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    reachable = graph.reachable_locations(BoardLocation(0, 1))
    expected = {BoardLocation(*coord) for coord in [(0, 1), (0, 2), (0, 3), (1, 3)]}
    assert set(reachable) == expected
예제 #2
0
def test_is_reachable_for_connected_neighbors():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert graph.is_reachable(BoardLocation(2, 4), BoardLocation(1, 4))
    assert graph.is_reachable(BoardLocation(2, 4), BoardLocation(2, 3))
    assert graph.is_reachable(BoardLocation(2, 4), BoardLocation(3, 4))
예제 #3
0
def test_is_reachable_for_swapped_locations():
    """ Tests is_reachable. Re-runs all of the above tests with swapped locations. """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert not graph.is_reachable(BoardLocation(1, 0), BoardLocation(0, 0))
    assert not graph.is_reachable(BoardLocation(0, 1), BoardLocation(0, 0))
    assert not graph.is_reachable(BoardLocation(2, 5), BoardLocation(2, 4))

    assert graph.is_reachable(BoardLocation(1, 4), BoardLocation(2, 4))
    assert graph.is_reachable(BoardLocation(2, 3), BoardLocation(2, 4))
    assert graph.is_reachable(BoardLocation(3, 4), BoardLocation(2, 4))

    assert graph.is_reachable(BoardLocation(3, 2), BoardLocation(3, 1))

    assert graph.is_reachable(BoardLocation(5, 0), BoardLocation(1, 4))

    assert not graph.is_reachable(BoardLocation(4, 4), BoardLocation(1, 0))

    assert graph.is_reachable(BoardLocation(6, 3), BoardLocation(5, 0))
    assert graph.is_reachable(BoardLocation(2, 6), BoardLocation(0, 6))
예제 #4
0
def _assert_valid_action(action, board, previous_shift_location, piece):
    shift, move_location = action
    shift_location, shift_rotation = shift
    assert shift_location in board.shift_locations
    if previous_shift_location:
        opposing_shift_location = board.opposing_border_location(
            previous_shift_location)
        assert shift_location != opposing_shift_location
    assert shift_rotation in [0, 90, 180, 270]
    board.shift(shift_location, shift_rotation)
    piece_location = board.maze.maze_card_location(piece.maze_card)
    assert Graph(board.maze).is_reachable(piece_location, move_location)
예제 #5
0
 def _validate_move_location(self, piece_location, target_location):
     if not Graph(self._maze).is_reachable(piece_location, target_location):
         raise exceptions.MoveUnreachableException(
             "Locations {} and {} are not connected".format(
                 piece_location, target_location))
예제 #6
0
def test_is_reachable_for_same_location():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert graph.is_reachable(BoardLocation(0, 0), BoardLocation(0, 0))
예제 #7
0
def test_is_reachable_for_paths_on_border():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert graph.is_reachable(BoardLocation(5, 0), BoardLocation(6, 3))
    assert graph.is_reachable(BoardLocation(0, 6), BoardLocation(2, 6))
예제 #8
0
def test_is_reachable_for_unconnected_cards_with_only_one_wall():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert not graph.is_reachable(BoardLocation(1, 0), BoardLocation(4, 4))
예제 #9
0
def test_is_reachable_for_connected_distant_cards():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert graph.is_reachable(BoardLocation(1, 4), BoardLocation(5, 0))
예제 #10
0
def test_is_reachable_for_connected_neighbors_wo_direct_path():
    """ Tests is_reachable """
    maze = create_maze(MAZE_STRING)
    graph = Graph(maze)
    assert graph.is_reachable(BoardLocation(3, 1), BoardLocation(3, 2))