本文整理汇总了Python中bst.Bst.contains方法的典型用法代码示例。如果您正苦于以下问题:Python Bst.contains方法的具体用法?Python Bst.contains怎么用?Python Bst.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.Bst
的用法示例。
在下文中一共展示了Bst.contains方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_on_complex_tree
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_delete_on_complex_tree():
"""Test that the selected node is deleted."""
from bst import Bst
nodes = [10, 9, 15, 2, 6, 12, 20, 1, 3]
new_bst = Bst()
for item in nodes:
new_bst.insert(item)
new_bst.delete(2)
assert new_bst.contains(2) is False
示例2: test_delete_on_range
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_delete_on_range():
"""Test that the node selected is removed from the tree."""
from bst import Bst
new_bst = Bst()
for items in range(20):
new_bst.insert(items)
new_bst.delete(10)
assert new_bst.contains(10) is False
assert new_bst.size == 19
示例3: test_delete
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_delete():
"""Test that the selected node is deleted."""
from bst import Bst
new_bst = Bst()
new_bst.insert(1)
new_bst.delete(1)
assert new_bst.contains(1) is False
assert new_bst.head is None
assert new_bst.size == 0
示例4: test_edge_cases_delete_tree
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_edge_cases_delete_tree():
"""Test deletion on tree from EdgeCases example tree."""
from bst import Bst
new_bst = Bst()
new_bst.insert(10)
new_bst.insert(20)
new_bst.insert(5)
new_bst.delete(10)
assert new_bst.contains(10) is False
assert new_bst.size == 2
assert new_bst.head.value == 20
assert new_bst.head.right is None
assert new_bst.head.left.value == 5
示例5: test_delete_on_small_range
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_delete_on_small_range():
"""Test that the node selected is removed from the tree."""
from bst import Bst
new_bst = Bst()
for items in range(5):
new_bst.insert(items)
new_bst.delete(1)
assert new_bst.contains(1) is False
assert new_bst.size == 4
assert new_bst.head.value == 2
assert new_bst.head.left.value == 0
assert new_bst.head.right.value == 3
assert new_bst.head.right.right.value == 4
示例6: test_off_balance_delete_tree_non_head
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_off_balance_delete_tree_non_head():
"""Test deletion on tree from complex tree."""
from bst import Bst
new_bst = Bst()
new_bst.insert(10)
new_bst.insert(20)
new_bst.insert(5)
new_bst.insert(15)
new_bst.insert(25)
new_bst.delete(20)
assert new_bst.contains(20) is False
assert new_bst.size == 4
assert new_bst.head.value == 10
assert new_bst.head.right.value == 25
assert new_bst.head.left.value == 5
assert new_bst.head.right.left.value == 15
示例7: test_contains
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_contains(self):
# Test with a root only
tree = root_only()
self.assertFalse(tree.isempty())
self.assertEquals(tree.getsize(), 1)
self.assertIsNotNone(tree.root)
self.assertEquals(tree.root.getdata(), ROOT_DATA)
# Should contain the root data
self.assertTrue(tree.contains(ROOT_DATA))
# Should not contain any of the children data
self.assertFalse(tree.contains(LEFT_DATA))
self.assertFalse(tree.contains(RIGHT_DATA))
# Should not contain any of the grandchildren data
self.assertFalse(tree.contains(LL_DATA))
self.assertFalse(tree.contains(LR_DATA))
self.assertFalse(tree.contains(RL_DATA))
self.assertFalse(tree.contains(RR_DATA))
tree.remove(ROOT_DATA)
self.assertTrue(tree.isempty())
self.assertIsNone(tree.root)
self.assertFalse(tree.contains(ROOT_DATA))
# Now test with the balanced tree
tree = balanced_tree()
self.assertFalse(tree.isempty())
self.assertEquals(tree.getsize(), 7)
self.assertIsNotNone(tree.root)
self.assertEquals(tree.root.getdata(), ROOT_DATA)
# Should contain the root data
self.assertTrue(tree.contains(ROOT_DATA))
# Should not contain any of the children data
self.assertTrue(tree.contains(LEFT_DATA))
self.assertTrue(tree.contains(RIGHT_DATA))
# Should not contain any of the grandchildren data
self.assertTrue(tree.contains(LL_DATA))
self.assertTrue(tree.contains(LR_DATA))
self.assertTrue(tree.contains(RL_DATA))
self.assertTrue(tree.contains(RR_DATA))
TO_ADD_DATA = 50
self.assertFalse(tree.contains(TO_ADD_DATA))
tree.add(TO_ADD_DATA)
self.assertTrue(tree.getsize(), 8)
self.assertTrue(tree.contains(TO_ADD_DATA))
# Finally, test with an empty tree
tree = Bst()
self.assertTrue(tree.isempty())
self.assertIsNone(tree.root)
# Should not contain the root data
self.assertFalse(tree.contains(ROOT_DATA))
# Should not contain any of the children data
self.assertFalse(tree.contains(LEFT_DATA))
self.assertFalse(tree.contains(RIGHT_DATA))
# Should not contain any of the grandchildren data
self.assertFalse(tree.contains(LL_DATA))
self.assertFalse(tree.contains(LR_DATA))
self.assertFalse(tree.contains(RL_DATA))
self.assertFalse(tree.contains(RR_DATA))
示例8: test_contain_false
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_contain_false():
"""Test if value in list return False."""
from bst import Bst
new_bst = Bst()
new_bst.insert(3)
assert new_bst.contains(4) is False
示例9: test_contain_true
# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import contains [as 别名]
def test_contain_true():
"""Test if value in list return True."""
from bst import Bst
new_bst = Bst()
new_bst.insert(3)
assert new_bst.contains(3) is True