Exemplo n.º 1
0
def test_breadth_blocked_in():
    def _point_is_water(point):
        return stage.get_tile_at(*point) == 3

    stage = Stage('maps/test-valley.tmx')
    path = find_path_to_matching(stage, (3, 12), _point_is_water)
    assert path is None
Exemplo n.º 2
0
def test_partition_size():
    stage = Stage('maps/test-valley.tmx')
    result = partition(stage, (3, 11))

    assert len(result) == stage.height
    for row in result:
        assert len(row) == stage.width
Exemplo n.º 3
0
def test_breadth_on_object():
    def _point_is_fish(point):
        return stage.entity_at(point).kind == 'fish'

    stage = Stage('maps/test-valley.tmx')
    path = find_path_to_matching(stage, (5, 12), _point_is_fish)
    assert path is not None
    assert len(path) == 1
Exemplo n.º 4
0
def test_path_is_walkable_0():
    # This was a path that broke during play---a penguin walked
    # straight into the river instead of walking over the bridge.
    # Let's make sure it doesn't break any more.
    stage = Stage('maps/test-river.tmx')
    path = astar(stage, (27, 31), (6, 1))
    assert path is not None
    _ensure_path_is_legal(stage, path)
Exemplo n.º 5
0
def test_partition_equality():
    stage = Stage('maps/test-valley.tmx')
    result1 = partition(stage, (4, 7))
    result2 = partition(stage, (10, 6))

    for y in range(len(result1)):
        for x in range(len(result1[0])):
            assert result1[y][x] == result2[y][x]
Exemplo n.º 6
0
def test_breadth_search_correct_results():
    def _point_is_water(point):
        return stage.get_tile_at(*point) == 3

    stage = Stage('maps/test-valley.tmx')
    path = find_path_to_matching(stage, (9, 3), _point_is_water)
    assert path is not None
    assert len(path) == 6
    assert path[0] == (9, 3)
    assert path[-1] == (14, 8)
Exemplo n.º 7
0
def test_partition_inequality():
    stage = Stage('maps/test-valley.tmx')
    result1 = partition(stage, (3, 11))
    result2 = partition(stage, (10, 6))

    all_equal = True
    for y in range(len(result1)):
        for x in range(len(result1[0])):
            if result1[y][x] != result2[y][x]:
                all_equal = False
                break
        if not all_equal:
            break

    assert not all_equal
Exemplo n.º 8
0
def test_path_returns_endpoints():
    stage = Stage('maps/tuxville.tmx')
    path = astar(stage, (50, 50), (50, 51))
    assert path[0] == (50, 50)
    assert path[-1] == (50, 51)
Exemplo n.º 9
0
def test_path_correct_results_0():
    stage = Stage('maps/tuxville.tmx')
    path = astar(stage, (50, 50), (50, 51))
    assert path is not None
Exemplo n.º 10
0
def test_path_is_walkable_2():
    stage = Stage('maps/test-river.tmx')
    path = astar(stage, (30, 23), (6, 1))
    assert path is not None
    _ensure_path_is_legal(stage, path)
Exemplo n.º 11
0
def test_big_map_has_trues():
    stage = Stage('maps/tuxville.tmx')
    result = partition(stage, (26, 59))
    _assert_has_trues(result)
Exemplo n.º 12
0
def test_partition_has_trues_2():
    stage = Stage('maps/test-valley.tmx')
    result = partition(stage, (10, 6))
    _assert_has_trues(result)