Ejemplo n.º 1
0
def test_init():
    node_1 = Node()
    assert node_1.name is None
    assert node_1.altitude is None
    assert node_1.parent is None
    assert node_1.left is None
    assert node_1.right is None

    node_2 = Node(name="NomTest")
    assert node_2.name is "NomTest"
    assert node_2.altitude is None
    assert node_2.parent is None
    assert node_2.left is None
    assert node_2.right is None

    node_3 = Node(name="NodeTrois", left=node_2)
    assert node_3.name is "NodeTrois"
    assert node_3.left is node_2
    #   Test binds corrects (node_3->node_2)
    assert node_3.left == node_2
    assert node_3.left.name == "NomTest"
    assert node_2.parent is node_3

    node_4 = Node(name="Node4", altitude=42100, parent=node_1, right=node_3)
    assert node_4.parent is node_1
    assert node_4.parent == node_1

    node_5 = Node(name="Node5", altitude=300)
    node_6 = Node(name="NodeSix", altitude=120)
    node_7 = Node(name="Node7ven", altitude=10)
    node_8 = Node(name="Node8",
                  altitude=42,
                  parent=node_5,
                  left=node_6,
                  right=node_7)
    assert node_8.right is node_7
    assert node_7.parent is node_8

    assert node_8.left is node_6
    assert node_6.parent is node_8

    assert node_8.parent is node_5
    assert node_5.left is node_8
    assert node_5.is_leaf() is False and node_6.is_leaf(
    ) is True and node_7.is_leaf() is True
Ejemplo n.º 2
0
def test_is_leaf():
    node_1 = Node(name="I", altitude=100)
    assert node_1.is_leaf() is True
    node_2 = Node(name="II", altitude=13350, left=node_1)
    assert node_2.is_leaf() is False