当前位置: 首页>>代码示例>>Python>>正文


Python BST.contains方法代码示例

本文整理汇总了Python中bst.BST.contains方法的典型用法代码示例。如果您正苦于以下问题:Python BST.contains方法的具体用法?Python BST.contains怎么用?Python BST.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bst.BST的用法示例。


在下文中一共展示了BST.contains方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_contains

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_contains():
    bst = BST()
    for i in range(1,11):
        bst.insert(i)
    assert bst.contains(1)
    assert bst.contains(5)
    assert not bst.contains(15)
开发者ID:EyuelAbebe,项目名称:data-structures1,代码行数:9,代码来源:test_bst.py

示例2: test_delete_head_only

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete_head_only():
    """Test deleteing a one node head."""
    from bst import BST
    b = BST([20])
    assert b.contains(20) is True
    b.delete(20)
    assert b.contains(20) is False
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例3: test_delete_head_one_right_child

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete_head_one_right_child():
    """Test deleting a head with one right child."""
    from bst import BST
    b = BST([20])
    b.insert(22)
    assert b.contains(20) is True
    b.delete(20)
    assert b.contains(20) is False
    assert b.top.value == 22
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:11,代码来源:test_bst.py

示例4: test_contains

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_contains():
    tree = BST()
    tree.insert(0)
    tree.insert(1)
    tree.insert(-1)
    tree.insert(2)
    tree.insert(-2)
    assert tree.contains(-1)
    assert tree.contains(0)
    assert tree.contains(4) is False
开发者ID:charlieRode,项目名称:data-structures,代码行数:12,代码来源:test_bst.py

示例5: test_contains

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_contains():
    btree = BST()
    btree.insert(3)
    btree.insert(2)
    btree.insert(5)
    btree.insert(4)
    btree.insert(1)
    assert btree.contains(5) is True
    assert btree.contains(1) is True
    assert btree.contains(10) is False
开发者ID:corinnelhh,项目名称:data-structures,代码行数:12,代码来源:test_bst.py

示例6: BSTTestCase

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
class BSTTestCase(unittest.TestCase):
    def setUp(self):
        self.tree = BST()
        self.nodes = {5: 'five', 7: 'seven', 2: 'two', 3: 'three', 1: 'one', 8: 'eight'}
        for k, v in self.nodes.items():
            self.tree.put(k,v)

    def tearDown(self):
        del self.tree
        del self.nodes

    def testPutGet(self):
        for k, v in self.nodes.items():
            self.assertEqual(v, self.tree.get(k))
        for k in [4,6,9]:
            self.assertIsNone(self.tree.get(k))

    def testLen(self):
        self.assertEqual(6, len(self.tree))

    def testMinKey(self):
        self.assertEqual(1, self.tree.minKey())

    def testMin(self):
        self.assertTupleEqual((1, 'one'), self.tree.min())

    def testMaxKey(self):
        self.assertEqual(8, self.tree.maxKey())

    def testMax(self):
        self.assertTupleEqual((8, 'eight'), self.tree.max())

    def testIsEmpty(self):
        self.assertFalse(self.tree.isEmpty())
        self.assertTrue(BST().isEmpty())

    def testItems(self):
        self.assertSequenceEqual(sorted(self.nodes.items()), list(self.tree.items()))

    def testKeys(self):
        self.assertSequenceEqual(sorted(self.nodes.keys()), list(self.tree.keys()))

    def testContains(self):
        self.assertTrue(self.tree.contains(8))
        self.assertFalse(self.tree.contains(13))

    def testKeysBetween(self):
        self.assertSequenceEqual([2,3,5], list(self.tree.keys_between(2, 6)))

    def testNumKeysBetween(self):
        # self.nodes = {5: 'five', 7: 'seven', 2: 'two', 3: 'three', 1: 'one', 8: 'eight'}
        self.assertEqual(4, self.tree.num_between(3, 8))

    def testRank(self):
        self.assertEqual(2, self.tree.rank(3))
开发者ID:d-strickland,项目名称:bst,代码行数:57,代码来源:test_bst.py

示例7: test_delete_head_two_children

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete_head_two_children():
    """Test deleting a head with two children."""
    from bst import BST
    b = BST([20])
    b.insert(18)
    b.insert(22)
    assert b.contains(20) is True
    b.delete(20)
    assert b.contains(20) is False
    assert b.top.value == 22
    assert b.top.left.value == 18
    assert b.top.right is None
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:14,代码来源:test_bst.py

示例8: test_delete_one_item

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete_one_item():
    from bst import BST
    bst = BST()
    bst.insert(42)
    bst.delete(42)
    assert not bst._search(42)
    assert not bst.contains(42)
开发者ID:KyleRichVA,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例9: test_contains

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_contains():
    """contains(val) should return True if val is in the BST, False if not."""
    bintree = BST()
    with pytest.raises(TypeError):
        bintree.insert()
    with pytest.raises(TypeError):
        bintree.insert(1, 2)
    # Will accept any value including None; behavior is on the user

    assert bintree.contains(None) is False
    assert bintree.contains(1) is False
    bintree.insert(1)
    assert bintree.contains(1) is True
    for i in xrange(-5, 5):
        bintree.insert(i)
    for i in xrange(-5, 5):
        assert bintree.contains(i) is True
    assert bintree.contains(None) is False
开发者ID:jbbrokaw,项目名称:data-structures,代码行数:20,代码来源:test_bst.py

示例10: test_delete_one_child

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete_one_child():
    """delete(self, val) should remove val from the tree if present,
    if not present it should do nothing. Return None in all cases"""
    bintree = BST()
    bintree.insert(5)
    bintree.insert(3)
    bintree.insert(7)
    bintree.insert(2)
    bintree.insert(4)
    bintree.insert(1)
    bintree.insert(9)
    bintree.insert(10)
    #     5
    #    / \
    #   3   7
    #  /\    \
    # 2  4    9
    # |       |
    # 1       10
    assert bintree.size() == 8
    assert bintree.delete(7) is None
    #     5
    #    / \
    #   3   9
    #  /\    \
    # 2  4    10
    # |
    # 1
    assert bintree.size() == 7
    assert not bintree.contains(7)
    assert bintree.contains(9)
    assert bintree.contains(10)
    assert bintree.balance() == 1
    assert bintree.delete(2) is None
    #     5
    #    / \
    #   3   9
    #  /\    \
    # 1  4    10
    assert bintree.size() == 6
    assert not bintree.contains(2)
    assert bintree.contains(1)
    assert bintree.leftchild.leftchild.value == 1
    assert bintree.balance() == 0
开发者ID:jbbrokaw,项目名称:data-structures,代码行数:46,代码来源:test_bst.py

示例11: test_delete

# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import contains [as 别名]
def test_delete():
    tree = BST()
    for n in [0, 2, -2, 1, -1, 3, -3]:
        tree.insert(n)
    for n in [-3, -2, -1, 0, 1, 2, 3]:
        assert tree.contains(n)
    tree.delete(-3)
    assert tree.contains(-3) is False
    tree.delete(-2)
    assert tree.contains(-2) is False
    for n in [-1, 0, 1, 2, 3]:
        assert tree.contains(n)
    assert tree.size() == 5
    tree.insert(5)
    tree.insert(4)
    tree.insert(6)
    tree.delete(3)
    assert tree.size() == 7
    for i in [-1, 0, 1, 2, 4, 5, 6]:
        assert tree.contains(i)
开发者ID:charlieRode,项目名称:data-structures,代码行数:22,代码来源:test_bst.py


注:本文中的bst.BST.contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。