Ejemplo n.º 1
0
 def test_delete_notExist(self):
     arbol = BST()
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(38)
Ejemplo n.º 2
0
def solve():
    map, reserved, separators, operands = loadCodificationTable()
    text = loadProgramText()
    ignorable = [" ", "\n"]
    pif = []
    bstIdentifiers = BST()
    bstConstants = BST()
    i = 0
    length = len(text)
    while i < length:
        word = ""
        while text[i] not in separators:
            word += text[i]
            i += 1
        if word in reserved:
            code = map[word]
            pif.append((code, -1))
        elif validIdentifier(word):
            position = bstIdentifiers.addElem(word)
            pif.append((1, position))
        elif validNumber(word):
            position = bstConstants.addElem(word)
            pif.append((2, position))
        else:
            raise Exception("Invalid token!")
        sep = ""
        while i < length and text[i] in separators:
            if text[i] == "'":
                if sep != '':
                    pif.append((map[sep], -1))
                    sep = ""
                assert (text[i + 2] == "'")
                position = bstConstants.addElem("'" + text[i + 1] + "'")
                pif.append((2, position))
                print('then branch', position, text[i + 1])
                i += 2
            else:
                if text[i] not in ignorable:
                    if possibleSeparator(sep + text[i], operands):
                        sep += text[i]
                    else:
                        if sep != '':
                            code = map[sep]
                            pif.append((code, -1))
                        sep = text[i]
            i += 1
        if sep in operands:
            pif.append((map[sep], -1))
    print('IDENTIFIERS:')
    printBST(bstIdentifiers.getRoot())
    print('CONSTANTS')
    printBST(bstConstants.getRoot())
    print('PIF')
    for x in pif:
        print(x[0])
    return pif, bstIdentifiers, bstConstants
Ejemplo n.º 3
0
    def test_deleteNodeRightChildren(self):
        arbol = BST()
        arbol.add(10)
        arbol.add(50)
        arbol.add(20)
        arbol.add(80)

        arbol.delete(50)
Ejemplo n.º 4
0
 def test_deleteRoot_onlyRight(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(50)
     arbol.delete(5)
Ejemplo n.º 5
0
 def test_deleteRoot_onlyLeft(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(1)
     arbol.delete(5)
Ejemplo n.º 6
0
 def test_onlyRoot(self):
     arbol = BST()
     arbol.add(5)
     arbol.delete(5)
Ejemplo n.º 7
0
 def test_findEmpty(self):
     BST().find(60)
Ejemplo n.º 8
0
from BinaryTree import BST

my_tree = BST.BinarySearchTree()

my_tree.display()

my_tree.insert(5, "five")
my_tree.insert(6, "six")
my_tree.insert(3, "three")
my_tree.insert(8, "eight")
my_tree.insert(2, "two")
my_tree.insert(9, "nine")
my_tree.insert(7, "seven")

my_tree.display()

print(my_tree.find(9))
Ejemplo n.º 9
0
 def test_insert(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
Ejemplo n.º 10
0
 def test_min(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find_min() == 5
Ejemplo n.º 11
0
 def test_preorderEmpty(self):
     BST().preorder()
Ejemplo n.º 12
0
 def test_postorder(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.postorder()
Ejemplo n.º 13
0
 def test_insertRepeated(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(5)
Ejemplo n.º 14
0
 def test_inorderEmpty(self):
     BST().inorder()
Ejemplo n.º 15
0
 def test_minEmpty(self):
     arbol = BST()
     arbol.find_min()
Ejemplo n.º 16
0
    def test_deleteRoot_twoChildren(self):
        arbol = BST()
        arbol.add(10)
        arbol.add(50)
        arbol.add(20)
        arbol.add(7)
        arbol.add(8)
        arbol.add(5)
        arbol.add(1)

        arbol.delete(10)
Ejemplo n.º 17
0
 def test_deleteEmpty(self):
     BST().delete(5)
Ejemplo n.º 18
0
 def test_postorderEmpty(self):
     BST().postorder()
Ejemplo n.º 19
0
 def test_maxEmpty(self):
     arbol = BST()
     arbol.find_max()
Ejemplo n.º 20
0
 def test_deleteRootMoreNodes(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(5)
Ejemplo n.º 21
0
 def test_find(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find(8) == True
Ejemplo n.º 22
0
 def test_deleteNodeLeftChildren(self):
     arbol = BST()
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(5)
     arbol.add(1)
     arbol.delete(5)
Ejemplo n.º 23
0
 def test_findUnexist(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     assert arbol.find(666) == False
Ejemplo n.º 24
0
from BinaryTree.Material import User
from BinaryTree.BST import *

u1 = User(22, "April Mayo")
u2 = User(46, "Diego Diaz")
u3 = User(15, "Carlos Casas")
u4 = User(10, "Juan Muros")
u5 = User(25, "Miluzca Milan")
u6 = User(36, "Erick Tucto")

tree = BST()
tree.insert(u1)
tree.insert(u2)
tree.insert(u3)
tree.insert(u6)
print(tree.right.left.root.full_name)
Ejemplo n.º 25
0
 def test_delete(self):
     arbol = BST()
     arbol.add(5)
     arbol.add(10)
     arbol.add(50)
     arbol.add(20)
     arbol.add(7)
     arbol.add(8)
     arbol.add(90)
     arbol.delete(5)