Esempio n. 1
0
def test_spacing(small_hex_shape):
    """Test spacing of nodes."""
    graph = TriGraph(small_hex_shape)
    assert_array_almost_equal(graph.length_of_link, 1.0)

    graph = TriGraph(small_hex_shape, spacing=2)
    assert_array_almost_equal(graph.length_of_link, 2.0)
Esempio n. 2
0
def test_orientation():
    """Test vertical and horizontal orientation."""
    graph = TriGraph((3, 3), orientation="vertical")
    assert_array_almost_equal(graph.y_of_node,
                              [0.0, 0.0, 0.5, 1.0, 1.0, 1.5, 2.0, 2.0, 2.5])

    graph = TriGraph((3, 3), orientation="horizontal")
    assert_array_almost_equal(graph.x_of_node,
                              [0.0, 1.0, 2.0, 0.5, 1.5, 2.5, 0.0, 1.0, 2.0])
Esempio n. 3
0
def test_origin_keyword(node_layout, orientation, small_hex_shape):
    """Test setting the origin."""
    graph = TriGraph(small_hex_shape)

    assert np.min(graph.x_of_node) == approx(0.0)
    assert np.min(graph.y_of_node) == approx(0.0)

    graph = TriGraph(small_hex_shape, xy_of_lower_left=(0.5, 0.25))

    assert np.min(graph.x_of_node[0]) == approx(0.5)
    assert np.min(graph.y_of_node[0]) == approx(0.25)
Esempio n. 4
0
def test_create_hex():
    """Test creating a hex graph with hex layout."""
    graph = TriGraph((3, 2), node_layout="hex", sort=True)

    assert graph.number_of_nodes == 7
    assert graph.number_of_links == 12
    assert graph.number_of_patches == 6
Esempio n. 5
0
def test_create_rect():
    """Test creating a hex graph with rectangular layout."""
    graph = TriGraph((3, 2), node_layout="rect", sort=True)

    assert graph.number_of_nodes == 6
    assert graph.number_of_links == 9
    assert graph.number_of_patches == 4
Esempio n. 6
0
def test_patches_at_node():
    grid = TriGraph((3, 3), node_layout="hex", sort=True)
    assert_array_equal(
        grid.patches_at_node,
        [
            [0, 2, -1, -1, -1, -1],
            [1, 3, 0, -1, -1, -1],
            [4, 1, -1, -1, -1, -1],
            [5, 2, -1, -1, -1, -1],
            [6, 8, 5, 2, 0, 3],
            [7, 9, 6, 3, 1, 4],
            [7, 4, -1, -1, -1, -1],
            [5, 8, -1, -1, -1, -1],
            [8, 6, 9, -1, -1, -1],
            [9, 7, -1, -1, -1, -1],
        ],
    )
Esempio n. 7
0
def test_adjacent_nodes_at_node():
    graph = TriGraph((3, 3), node_layout="hex", sort=True)
    assert_array_equal(
        graph.adjacent_nodes_at_node,
        [
            [1, 4, 3, -1, -1, -1],
            [2, 5, 4, 0, -1, -1],
            [6, 5, 1, -1, -1, -1],
            [4, 7, 0, -1, -1, -1],
            [5, 8, 7, 3, 0, 1],
            [6, 9, 8, 4, 1, 2],
            [9, 5, 2, -1, -1, -1],
            [8, 3, 4, -1, -1, -1],
            [9, 7, 4, 5, -1, -1],
            [8, 5, 6, -1, -1, -1],
        ],
    )
Esempio n. 8
0
def test_create_hex_graph(n_rows, node_layout, orientation, at):
    expected = {
        "rect": {
            "horizontal": {
                "nodes": 6,
                "links": 9,
                "patches": 4
            },
            "vertical": {
                "nodes": 6,
                "links": 9,
                "patches": 4
            },
        },
        "hex": {
            "horizontal": {
                "nodes": 7,
                "links": 12,
                "patches": 6
            },
            "vertical": {
                "nodes": 7,
                "links": 12,
                "patches": 6
            },
        },
    }
    if orientation == "vertical":
        shape = (2, n_rows)
    else:
        shape = (n_rows, 2)
    graph = TriGraph(shape,
                     node_layout=node_layout,
                     orientation=orientation,
                     sort=True)
    assert (getattr(graph, "number_of_{at}".format(
        at=at)) == expected[node_layout][orientation][at])
Esempio n. 9
0
def test_perimeter_nodes_hex():
    graph = TriGraph((4, 2), node_layout="hex")
    assert_array_equal(graph.perimeter_nodes, [8, 11, 10, 9, 5, 2, 0, 1, 4])
Esempio n. 10
0
def test_perimeter_nodes_rect():
    graph = TriGraph((3, 4), node_layout="rect")
    assert_array_equal(graph.perimeter_nodes, [3, 7, 11, 10, 9, 8, 4, 0, 1, 2])