Exemplo n.º 1
0
def test_unbind_parent():
    node_1 = Node(name="I", altitude=100)
    node_2 = Node(name="II", altitude=200)

    node_1.bind_parent(node_2)
    assert node_1.parent is node_2

    node_1.unbind_parent()
    assert node_1.parent is None
    assert node_2.left is None

    #   Try to unbind a parent to a node who don't hve a parent => work
    node_1.unbind_parent()
    node_2.unbind_parent()
Exemplo n.º 2
0
def test_bind_parent():
    node_1 = Node(name="III", altitude=300)
    node_2 = Node(name="IV", altitude=400)
    node_3 = Node(name="V", altitude=500)

    node_3.bind_parent(node_2)
    assert node_3.parent == node_2
    assert node_2.left == node_3

    #   Try to bind a parent to a node who already have a parent
    with pytest.raises(AssertionError):
        node_3.bind_parent(node_1)

    node_4 = Node()
    with pytest.raises(AssertionError):
        node_4.bind_parent(node_4)