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


Python bst.BST类代码示例

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


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

示例1: test_balance

def test_balance():
    aBST = BST()
    assert aBST.balance() == 0
    for num, bal in zip([4, 2, 6, 3, 7, 8, 9, 10, 11],
                        [0, 1, 0, 1, 0, -1, -2, -3]):
        aBST.insert(num)
        assert aBST.balance() == bal
开发者ID:tpeek,项目名称:data-structures-1,代码行数:7,代码来源:test_bst.py

示例2: test_depth

def test_depth():
    aBST = BST()
    assert aBST.depth() == 0
    for num, depth in zip([4, 2, 6, 3, 7, 8, 9, 10, 11],
                          [1, 2, 2, 3, 3, 4, 5,  6,  7]):
        aBST.insert(num)
        assert aBST.depth() == depth
开发者ID:tpeek,项目名称:data-structures-1,代码行数:7,代码来源:test_bst.py

示例3: test_insert_same

def test_insert_same():
    """Test that a value cannot be added to tree if it already exisits."""
    from bst import BST
    new_bst = BST()
    new_bst.insert(5)
    with pytest.raises(ValueError):
        new_bst.insert(5)
开发者ID:palindromed,项目名称:data-structures2,代码行数:7,代码来源:test_bst.py

示例4: test_contains

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,代码行数:7,代码来源:test_bst.py

示例5: test_delete_head_only

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,代码行数:7,代码来源:test_bst.py

示例6: test_larger_child

def test_larger_child():
    """Test that inserting a value greater than
    head sets the left child of head."""
    from bst import BST
    new_bst = BST()
    new_bst.insert(5)
    new_bst.insert(9)
    assert new_bst.head.get_right_child().data == 9
开发者ID:palindromed,项目名称:data-structures2,代码行数:8,代码来源:test_bst.py

示例7: tiny_tree

def tiny_tree():
    from bst import BST
    new_bst = BST()
    new_bst.insert(30)
    new_bst.insert(50)
    new_bst.insert(75)

    return new_bst
开发者ID:palindromed,项目名称:data-structures2,代码行数:8,代码来源:test_bst.py

示例8: test_insert

 def test_insert(self):
     bst = BST()
     self.assertTrue(bst.insert(5))
     self.assertTrue(bst.insert(10))
     self.assertTrue(bst.insert(1))
     self.assertFalse(bst.insert(5))
     self.assertTrue(bst.root.left is not None)
     self.assertTrue(bst.root.right is not None)
开发者ID:derekargueta,项目名称:Data-Structures,代码行数:8,代码来源:tests.py

示例9: test_child_setting

def test_child_setting():
    """Test that inserting a value less than
    head sets right child value to head."""
    from bst import BST
    new_bst = BST()
    new_bst.insert(5)
    new_bst.insert(3)
    assert new_bst.head.get_left_child().data == 3
开发者ID:palindromed,项目名称:data-structures2,代码行数:8,代码来源:test_bst.py

示例10: test_in_order_empty

def test_in_order_empty():
    """Test an empty Node returns empty list."""
    from bst import BST
    b = BST()
    in_ord = b.in_order()
    in_ord_list = []
    for ii in in_ord:
        in_ord_list.append(ii)
    assert in_ord_list == []
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例11: test_breath_first_solo

def test_breath_first_solo():
    """Test running breath on a tree with one Node."""
    from bst import BST
    b = BST([25])
    breath = b.breath_first()
    breath_first_list = []
    for ii in breath:
        breath_first_list.append(ii)
    assert breath_first_list == [25]
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例12: test_breath_first_empty

def test_breath_first_empty():
    """Test an empty Node returns empty list."""
    from bst import BST
    b = BST()
    breath = b.breath_first()
    breath_first_list = []
    for ii in breath:
        breath_first_list.append(ii)
    assert breath_first_list == []
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例13: test_post_order_solo

def test_post_order_solo():
    """Test running post-order on a tree with one Node."""
    from bst import BST
    b = BST([35])
    post_ord = b.post_order()
    post_ord_list = []
    for ii in post_ord:
        post_ord_list.append(ii)
    assert post_ord_list == [35]
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例14: test_post_order_empty

def test_post_order_empty():
    """Test an empty Node returns empty list."""
    from bst import BST
    b = BST()
    post_ord = b.post_order()
    post_ord_list = []
    for ii in post_ord:
        post_ord_list.append(ii)
    assert post_ord_list == []
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py

示例15: test_pre_order_solo

def test_pre_order_solo():
    """Test running pre-order on a tree with one Node."""
    from bst import BST
    b = BST([132])
    pre_ord = b.pre_order()
    pre_ord_list = []
    for ii in pre_ord:
        pre_ord_list.append(ii)
    assert pre_ord_list == [132]
开发者ID:muniri92,项目名称:Data-Structures-2.0,代码行数:9,代码来源:test_bst.py


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