本文整理汇总了Python中tree.Tree.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.remove方法的具体用法?Python Tree.remove怎么用?Python Tree.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Tree
的用法示例。
在下文中一共展示了Tree.remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test007
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import remove [as 别名]
def test007(self):
# stress
data = range(10, 100)
random.shuffle(data)
tree = Tree(data)
self.assertEqual(len(tree), len(data))
random.shuffle(data)
for d in data:
tree.remove(d)
self.assertEqual(len(tree), 0)
示例2: TreeTestCase
# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import remove [as 别名]
class TreeTestCase(unittest.TestCase):
def setUp(self):
self.tree = Tree()
def test001(self):
# creation
self.assertIsNotNone(self.tree)
self.assertIsNone(self.tree.root)
def test002(self):
# insert
self.tree.insert(42)
self.assertEqual(self.tree.root.data, 42)
self.tree.insert(25)
self.assertEqual(self.tree.root.left.data, 25)
self.tree.insert(777)
self.assertEqual(self.tree.root.right.data, 777)
def test003(self):
# length
for i in range(1, 10):
self.tree.insert(i)
self.assertEqual(i, len(self.tree))
def test004(self):
# iterators
self.tree.insert([4, 2, 1, 3, 6, 5, 8, 7, 9])
self.assertEqual([4, 2, 1, 3, 6, 5, 8, 7, 9], [n.data for n in self.tree.preorder()])
self.assertEqual([1, 3, 2, 5, 7, 9, 8, 6, 4], [n.data for n in self.tree.posorder()])
self.assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9], [n.data for n in self.tree.inorder()])
def test005(self):
# simple remove
self.tree.insert([42, 25, 777])
self.tree.remove(0)
self.assertEqual(len(self.tree), 3)
self.tree.remove(777)
self.assertEqual(len(self.tree), 2)
self.assertEqual([42, 25], [n.data for n in self.tree.preorder()])
self.tree.insert(12)
self.assertEqual(len(self.tree), 3)
self.tree.remove(25)
self.assertEqual(len(self.tree), 2)
self.assertEqual([42, 12], [n.data for n in self.tree.preorder()])
def test006(self):
# complex remove
self.tree.insert([42, 25, 777, 12, 36, 555, 999, 600])
self.tree.remove(42)
self.assertEqual(self.tree.root.data, 555)
self.tree.remove(555)
self.assertEqual(self.tree.root.data, 600)
def test007(self):
# stress
data = range(10, 100)
random.shuffle(data)
tree = Tree(data)
self.assertEqual(len(tree), len(data))
random.shuffle(data)
for d in data:
tree.remove(d)
self.assertEqual(len(tree), 0)