Пример #1
0
def preparePerfectTree():

    tree = LLBinaryTree.Tree()
    tree.setRoot(LLBinaryTree.Position(1))
    tree.getRoot().setLeft(LLBinaryTree.Position(2))
    tree.getRoot().setRight(LLBinaryTree.Position(3))

    tree.getRoot().getLeft().setLeft(LLBinaryTree.Position(4))
    tree.getRoot().getLeft().setRight(LLBinaryTree.Position(5))
    tree.getRoot().getRight().setLeft(LLBinaryTree.Position(6))
    tree.getRoot().getRight().setRight(LLBinaryTree.Position(7))

    return tree
Пример #2
0
def prepareMixTree():
    tree = LLBinaryTree.Tree()

    tree.setRoot(LLBinaryTree.Position(1))

    # LHS
    tree.getRoot().setLeft(LLBinaryTree.Position(2))
    tree.getRoot().getLeft().setLeft(LLBinaryTree.Position(4))
    tree.getRoot().getLeft().getLeft().setLeft(LLBinaryTree.Position(6))
    tree.getRoot().getLeft().getLeft().setRight(LLBinaryTree.Position(7))

    # RHS
    tree.getRoot().setRight(LLBinaryTree.Position(3))
    tree.getRoot().getRight().setLeft(LLBinaryTree.Position(5))
    tree.getRoot().getRight().getLeft().setRight(LLBinaryTree.Position(8))

    return tree
Пример #3
0
def test_sizeIsEmpty():

    treeBase = prepareEmptyTree()

    assert treeBase.isEmpty() == True
    assert treeBase.size() == 0

    treeBase.setRoot(LLBinaryTree.Position(1))

    assert treeBase.isEmpty() == False
    assert treeBase.size() == 1

    treeBase.setRoot(None)

    assert treeBase.isEmpty() == True
    assert treeBase.size() == 0

    treeBase = prepareRootTree()

    assert treeBase.isEmpty() == False
    assert treeBase.size() == 1

    treePerf = preparePerfectTree()

    assert treePerf.isEmpty() == False
    assert treePerf.size() == 7

    treeOnlyLeft = prepareOnlyLeftTree()

    assert treeOnlyLeft.isEmpty() == False
    assert treeOnlyLeft.size() == 6

    treeOnlyRight = prepareOnlyRightTree()

    assert treeOnlyRight.isEmpty() == False
    assert treeOnlyRight.size() == 7

    treeMix = prepareMixTree()

    assert treeMix.isEmpty() == False
    assert treeMix.size() == 8
Пример #4
0
 def __init__(self):
     self.__heap = LLBinaryTree.Tree()
Пример #5
0
def prepareRootTree():
    tree = LLBinaryTree.Tree()
    tree.setRoot(LLBinaryTree.Position("root"))
    return tree
Пример #6
0
def prepareEmptyTree():
    tree = LLBinaryTree.Tree()
    return tree