Exemplo n.º 1
0
def test_node_remove_neighbour(test_node: Node):
    """test that we correctly remove nodes from neighbours"""
    other = Node(x=1.5, y=0)
    test_node.add_neighbour(other)
    test_node.remove_neighbour(other)
    assert other not in test_node.neighbours
    assert other not in test_node._ordered_neighbours
Exemplo n.º 2
0
def test_node_order_neighbours():
    """test that we order neighbours correctly"""
    node0 = Node(x=0, y=0, label="node0")
    node1 = Node(x=1, y=0, label="node1")
    node2 = Node(x=1, y=1, label="node2")
    node3 = Node(x=0, y=1, label="node3")
    # add the nodes out of order
    node0.add_neighbour(node3)
    node0.add_neighbour(node1)
    node0.add_neighbour(node2)
    # check that it keeps them ordered
    assert ["node1", "node2",
            "node3"] == [node.label for node in node0._ordered_neighbours]
Exemplo n.º 3
0
def test_node_get_adjacent_neighbours():
    """test that we retrieve the right neighbours"""
    node0 = Node(x=0, y=0, label="node0")
    node1 = Node(x=1, y=0, label="node1")
    node2 = Node(x=1, y=1, label="node2")
    node3 = Node(x=0, y=1, label="node3")
    # add a single node
    node0.add_neighbour(node1)
    before, after = node0._get_adjacent_neighbours(node1)
    assert before == node1
    assert after == node1
    # add a second node
    node0.add_neighbour(node2)
    before, after = node0._get_adjacent_neighbours(node2)
    assert before == node1
    assert after == node1
    # add a third node
    node0.add_neighbour(node3)
    before, after = node0._get_adjacent_neighbours(node2)
    assert before == node1
    assert after == node3
Exemplo n.º 4
0
def test_node_add_neighbour(test_node: Node):
    """test that we add nodes"""
    other = Node(x=1.5, y=0)
    test_node.add_neighbour(other)
    assert other in test_node.neighbours
    assert other in test_node._ordered_neighbours