Beispiel #1
0
def test_node_set_parent():
    """Test assignement of parent"""
    parent = TreeNode("test")
    child = TreeNode("test")

    child.set_parent(parent)

    assert child.parent is parent

    assert parent.children[0] is child
Beispiel #2
0
def test_node_drop_parent():
    """Test dropping parent"""
    parent = TreeNode("test")
    child = TreeNode("test")

    child.set_parent(parent)

    assert child.parent is parent
    assert parent.children[0] is child

    child.drop_parent()

    assert child.parent is None
    assert len(parent.children) == 0
Beispiel #3
0
def test_node_set_no_parent():
    """Test assignement of no parent, meaning droping the parent"""
    parent = TreeNode("test")
    child = TreeNode("test")

    child.set_parent(parent)

    assert child.parent is parent
    assert parent.children[0] is child

    child.set_parent(None)

    assert child.parent is None
    assert len(parent.children) == 0
Beispiel #4
0
def test_node_set_parent_drop_children():
    """Test that replacing a parent removes the node from parent's children"""
    grand_parent = TreeNode("test")
    parent = TreeNode("test", grand_parent)
    child = TreeNode("test", parent)

    assert child.parent is parent
    assert child.parent.parent is grand_parent
    assert grand_parent.children[0] is parent
    assert grand_parent.children[0].children[0] is child

    # That's silly...
    child.set_parent(grand_parent)

    assert child.parent is grand_parent
    assert len(grand_parent.children) == 2
    assert grand_parent.parent is None
    assert len(parent.children) == 0
    assert parent.parent is grand_parent
Beispiel #5
0
def test_node_parent_reinsertion():
    """Test that replacing a parent with the same one does not change anything"""
    parent = TreeNode("test")
    child1 = TreeNode("test", parent)
    child2 = TreeNode("test", parent)

    assert child1.parent is parent
    assert child2.parent is parent
    assert parent.children[0] is child1
    assert parent.children[1] is child2

    child1.set_parent(parent)

    assert child1.parent is parent
    assert child2.parent is parent
    assert parent.children[0] is child1
    assert parent.children[1] is child2

    child2.set_parent(parent)

    assert child1.parent is parent
    assert child2.parent is parent
    assert parent.children[0] is child1
    assert parent.children[1] is child2