Esempio n. 1
0
def test_make_dry():

    board = graph.Board.from_string(g2)
    g = graph.Graph.from_board(board)

    dry = graph.make_dry(g)

    # Test that first making it walkable and then dry is the same as making it dry right away
    walkable = graph.make_walkable(g)
    dry2 = graph.make_dry(walkable)
    for y in range(dry.rows):
        for x in range(dry.columns):
            node = dry.get_node(x, y)
            assert node == dry2.get_node(x, y)
            if node is None:
                assert g2.split()[y][x] in (graph.State.flooded, graph.State.drowned)
            else:
                assert node.state in (graph.State.dry, graph.State.redry)

    assert len(dry.nodes) == 3*4

    assert dry.get_node(1, 1).west is None
Esempio n. 2
0
def test_next_to_water():

    board = graph.Board.from_string(g2)
    g = graph.Graph.from_board(board)

    assert g.get_node(1, 1).is_next_to_water
    assert g.get_node(4, 1).is_next_to_water
    assert not g.get_node(2, 2).is_next_to_water

    # flooded or drowned nodes are by definition not next to water
    assert not g.get_node(0, 0).is_next_to_water
    assert not g.get_node(1, 0).is_next_to_water

    dry = graph.split_into_subgraphs(graph.make_dry(g))[0] # get some None nodes in the graph

    assert dry.get_node(1, 1).is_next_to_water
    assert not dry.get_node(2, 2).is_next_to_water
Esempio n. 3
0
def test_subgraphs():

    board = graph.Board.from_string(g_sub)
    g = graph.Graph.from_board(board)

    walkable = graph.make_walkable(g)
    dry = graph.make_dry(g)

    walkable_islands = graph.split_into_subgraphs(walkable)
    dry_islands = graph.split_into_subgraphs(dry)

    assert len(walkable_islands) == 2
    for island in walkable_islands:
        assert len(island.nodes) in (3, 9)

    assert len(dry_islands) == 3
    for island in dry_islands:
        assert len(island.nodes) in (1, 2, 3)
Esempio n. 4
0
def test_contains_subgraph():

    board = graph.Board.from_string(g_sub)
    g = graph.Graph.from_board(board)

    walkable = graph.make_walkable(g)
    dry = graph.make_dry(g)

    walkable_islands = graph.split_into_subgraphs(walkable)
    dry_islands = graph.split_into_subgraphs(dry)

    for walkable_island in walkable_islands:
        if walkable_island.get_node(4, 2) is not None: break

    for dry_island in dry_islands:
        if dry_island.get_node(4, 2) is not None: break

    assert dry_island in walkable_island
    assert walkable_island not in dry_island
Esempio n. 5
0
def test_split_extended_islands_big():

    board = graph.Board.from_string(g_big_cluttered)
    g = graph.Graph.from_board(board)

    walkable = graph.make_walkable(g)

    extended_islands = graph.split_into_extended_islands(walkable)

    assert len(extended_islands) == len(graph.split_into_subgraphs(graph.make_dry(g)))

    for island in extended_islands:
        if island.get_node(18, 6) is not None:
            assert len(island.nodes) == 5
            assert island.get_node(19, 6) is not None
            assert island.get_node(19, 5) is not None
            assert island.get_node(19, 4) is not None
            assert island.get_node(20, 4) is not None

        if island.get_node(5, 9) is not None:
            node = island.get_node(5, 9)
            assert node.distance_to_land == 3

        if island.get_node(8, 9) is not None:
            assert island.get_node(5, 9) is not None
        if island.get_node(5, 13) is not None:
            assert island.get_node(5, 9) is not None

        if island.get_node(17, 2) is not None:
            assert island.get_node(18, 2) is not None
        if island.get_node(18, 1) is not None:
            assert island.get_node(18, 2) is not None
        if island.get_node(19, 2) is not None:
            assert island.get_node(18, 2) is not None


        if island.get_node(30, 3)  is not None:
            assert island.get_node(4, 1) is None
        if island.get_node(4, 1) is not None:
            assert island.get_node(30, 3) is None

        assert island.get_node(31, 0) is None