Exemplo n.º 1
0
def test_node_remove_children_sequentially():
    """Test removing children one after the other"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

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

    parent.drop_children(child1)

    assert len(parent.children) == 1
    assert child1.parent is None
    assert parent.children[0] is child2
    assert child2.parent is parent

    parent.drop_children(child2)

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None
Exemplo n.º 2
0
def test_node_add_child():
    """Test assignement of child"""
    parent = TreeNode("test")
    child = TreeNode("test")

    parent.add_children(child)

    assert parent.children[0] is child
    assert child.parent is parent
Exemplo n.º 3
0
def test_node_add_children():
    """Test assignement of children"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

    assert parent.children[0] is child1
    assert parent.children[1] is child2
    assert child1.parent is parent
    assert child2.parent is parent
Exemplo n.º 4
0
def test_node_remove_child():
    """Test removing child"""
    parent = TreeNode("test")
    child = TreeNode("test")

    parent.add_children(child)

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

    parent.drop_children(child)

    assert len(parent.children) == 0
    assert child.parent is None
Exemplo n.º 5
0
def test_node_remove_all_children():
    """Test drop_children() drops all of them"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

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

    parent.drop_children()

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None
Exemplo n.º 6
0
def test_node_remove_children_in_batch():
    """Test removing children all at the same time"""
    parent = TreeNode("test")
    child1 = TreeNode("test1")
    child2 = TreeNode("test2")

    parent.add_children(child1, child2)

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

    parent.drop_children(child1, child2)

    assert len(parent.children) == 0
    assert child1.parent is None
    assert child2.parent is None
Exemplo n.º 7
0
def test_node_add_children_drop_children():
    """Test that replacing a children removes the node from previous 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...
    grand_parent.add_children(child)

    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
Exemplo n.º 8
0
def test_node_children_reinsertion():
    """Test that replacing a children 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

    parent.add_children(child1)

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

    parent.add_children(child2)

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