def testSampleTreeConstruct(self): tree = SampleTree(degree=2) assert tree.size() == 0 tree.insert("cat", 3) assert tree.size() == 1 assert tree.weight() == 3 tree.insert("bear", 100) assert tree.size() == 2 assert tree.weight() == 103 tree.insert("rabbit", 100) assert tree.size() == 3 assert tree.weight() == 203
def testNodes(self): tree = SampleTree(degree=2) for i in range(0,1000): tree.insert(str(i), i) assert tree.size() == 1000 assert tree.weight() == (999 * 1000) / 2 count = 0 weight = 0 for node in tree.nodes(): if node.data is not None: count += 1 weight += node.weight assert count == tree.size() assert weight == tree.weight()
def testSampleTreeIterate(self): tree = SampleTree(degree=5) for i in range(0,1000): tree.insert(str(i), i) assert tree.size() == 1000 assert tree.weight() == (999 * 1000) / 2 count = 0 for elem in tree.dataElements(): assert int(elem) >= 0 and int(elem) < 1000 count += 1 assert count == 1000
def testRemove(self): tree = SampleTree(degree=5) for i in range(0,1000): tree.insert(str(i), i) for node in tree.nodes(): if node.weight == 100: tree.remove(node) break for node in tree.nodes(): if node.weight == 3: tree.remove(node) break assert tree.size() == 998 assert tree.weight() == (999 * 1000) / 2 - 103
def testSampleTreeBigger(self): tree = SampleTree(degree=5) for i in range(0,10000): tree.insert(str(i), i) assert tree.size() == 10000 assert tree.weight() == (9999 * 10000) / 2