def setUp(self): self.bst = BinaryTree() r = BinaryNode(5) rl = BinaryNode(3) r.right = BinaryNode(6) r.left = rl rl.left = BinaryNode(2) rl.right = BinaryNode(4) self.r = r
class TestAVL(unittest.TestCase): def setUp(self): self.bst = BinaryTree() def tearDown(self): self.bst = None def test_minTrial(self): num = 1000 values = list(range(num)) random.shuffle(values) for _ in values: self.bst.add(_) # always remove MIN for maximum rotations for _ in range(num): t = min(self.bst) self.bst.remove(t) self.assertFalse(t in self.bst) self.assertTrue(self.bst.assertAVLProperty()) def test_maxTrial(self): num = 1000 values = list(range(num)) random.shuffle(values) for _ in values: self.bst.add(_) # always remove Max for maximum rotations for _ in range(num): t = max(self.bst) self.bst.remove(t) self.assertFalse(t in self.bst) self.assertTrue(self.bst.assertAVLProperty())
def constructAVL(aList): bt = BinaryTree() for val in aList: bt.add(val) return bt
def setUp(self): self.bst = BinaryTree()
def __init__(self): BinaryTree.__init__(self, OrderStatTreeNode)
with open(path) as f: for line in f: row = re.split('\t', line.splitlines()[0]) data = MoviesData(int(row[0]), row[1], row[2]) array.append(data) end = time.time() print("Loaded file: " + file + " -> contains " + str(len(array)) + " rows of data") print("Elapsed time: " + str(end - start) + " sec\n") print("Inserting data into BinaryTree") start = time.time() tree = BinaryTree() for data in array: tree.add(data[1], data) end = time.time() print("Elapsed time: " + str(end - start) + " sec\n") arrayOfObjectsToFind = [] for number in range(1000): arrayOfObjectsToFind.append(array[random.randint(0, len(array) - 1)]) print("Find by shortName starting for 1000 random objects") elapsedTime = 0 for data in arrayOfObjectsToFind: start = time.time() tree.findByShortName(data[1])