def test_delete_notExist(self): arbol = BST() arbol.add(20) arbol.add(7) arbol.add(8) arbol.add(90) arbol.delete(38)
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
def test_deleteNodeRightChildren(self): arbol = BST() arbol.add(10) arbol.add(50) arbol.add(20) arbol.add(80) arbol.delete(50)
def test_deleteRoot_onlyRight(self): arbol = BST() arbol.add(5) arbol.add(50) arbol.delete(5)
def test_deleteRoot_onlyLeft(self): arbol = BST() arbol.add(5) arbol.add(1) arbol.delete(5)
def test_onlyRoot(self): arbol = BST() arbol.add(5) arbol.delete(5)
def test_findEmpty(self): BST().find(60)
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))
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)
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
def test_preorderEmpty(self): BST().preorder()
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()
def test_insertRepeated(self): arbol = BST() arbol.add(5) arbol.add(5)
def test_inorderEmpty(self): BST().inorder()
def test_minEmpty(self): arbol = BST() arbol.find_min()
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)
def test_deleteEmpty(self): BST().delete(5)
def test_postorderEmpty(self): BST().postorder()
def test_maxEmpty(self): arbol = BST() arbol.find_max()
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)
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
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)
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
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)
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)