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
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
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
def __init__(self): self.__heap = LLBinaryTree.Tree()
def prepareRootTree(): tree = LLBinaryTree.Tree() tree.setRoot(LLBinaryTree.Position("root")) return tree
def prepareEmptyTree(): tree = LLBinaryTree.Tree() return tree