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


Python bst.Bst类代码示例

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


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

示例1: test_right_left_conversion_six_nodes

def test_right_left_conversion_six_nodes():
    """
    Test that given six nodes in a left-right state converts to left-left.
    """
    from bst import Bst, Node
    new_bst = Bst()
    node1 = Node(10)
    node2 = Node(5)
    node3 = Node(15)
    node4 = Node(20)
    node5 = Node(14)
    node6 = Node(13)
    new_bst.head = node1
    node1.left = node2
    node2.parent = node1
    node1.right = node3
    node3.parent = node1
    node3.right = node4
    node4.parent = node3
    node3.left = node5
    node5.parent = node3
    node5.left = node6
    node6.parent = node5
    new_bst.head.right_left_conversion()
    assert new_bst.head.right == node5
    assert new_bst.head.right.right == node3
    assert new_bst.head.right.right.right == node4
开发者ID:jmcclena94,项目名称:data-structures,代码行数:27,代码来源:test_bst.py

示例2: test_balance_left_two_nodes

def test_balance_left_two_nodes():
    """Test balance left heavy."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(2)
    assert new_bst.balance() == 1
开发者ID:cacizi41,项目名称:data-structures,代码行数:7,代码来源:test_bst.py

示例3: bst_with_stuff

def bst_with_stuff():
    """Create BST with stuff in it."""
    from bst import Bst
    bst = Bst()
    for i in range(1, 21):
        bst.insert(i)
    return bst
开发者ID:flegald,项目名称:data_structures,代码行数:7,代码来源:test_bst.py

示例4: test_search

def test_search():
    """Test that the search returns a node connected to the selected value."""
    from bst import Bst, Node
    new_bst = Bst()
    new_bst.insert(1)
    for item in new_bst.head._search():
        assert isinstance(item, Node)
开发者ID:jmcclena94,项目名称:data-structures,代码行数:7,代码来源:test_bst.py

示例5: test_isempty

    def test_isempty(self):
        tree = Bst()
        self.assertTrue(tree.isempty())

        ARBITRARY_SIZE = 5
        tree.size = ARBITRARY_SIZE
        self.assertFalse(tree.isempty())
开发者ID:mosdragon,项目名称:PythonDS,代码行数:7,代码来源:test_bst.py

示例6: test_balance_right_two_nodes

def test_balance_right_two_nodes():
    """Test balance right heavy."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(4)
    assert new_bst.balance() == -1
开发者ID:cacizi41,项目名称:data-structures,代码行数:7,代码来源:test_bst.py

示例7: instance2

def instance2():
    """Fun tree fixture."""
    fun_tree = Bst()
    insertions = [11, 17, 9, 10, 8, 7, 4, 12, 19, 18]
    for fun in insertions:
        fun_tree.insert(fun)
    return fun_tree
开发者ID:scotist,项目名称:data-structures,代码行数:7,代码来源:test_bst.py

示例8: test_balance_left_complex

def test_balance_left_complex():
    """Test a left heavy list with multiple nodes."""
    from bst import Bst
    r = range(10, 0, -1)
    new_bst = Bst()
    for i in r:
        new_bst.insert(i)
    assert new_bst.balance() == 9
开发者ID:cacizi41,项目名称:data-structures,代码行数:8,代码来源:test_bst.py

示例9: test_depth

def test_depth():
    """Test depth works."""
    from bst import Bst
    r = range(10)
    new_bst = Bst()
    for i in r:
        new_bst.insert(i)
    assert new_bst.depth() == 10
开发者ID:cacizi41,项目名称:data-structures,代码行数:8,代码来源:test_bst.py

示例10: test_insert_value_already_exists

def test_insert_value_already_exists():
    """Test if value exists it is ignored."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(3)
    assert new_bst.head.right is None
    assert new_bst.head.left is None
    assert new_bst.head.value == 3
开发者ID:cacizi41,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例11: test_rotated_children_after_insert

def test_rotated_children_after_insert(seq):
    """Test that children from top of tree are what we expect after rotate."""
    tree = Bst()
    expected_left_child = list(sorted(seq))[0]
    expected_right_child = list(sorted(seq))[2]
    for val in seq:
        tree.insert(val)
    assert all([tree.left_child.value == expected_left_child,
                tree.right_child.value == expected_right_child])
开发者ID:scotist,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例12: test_insert_two_values

def test_insert_two_values():
    """Test insert works for two values."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(3)
    new_bst.insert(4)
    assert new_bst.head.value == 3
    assert new_bst.head.right.value == 4
    assert new_bst.head.left is None
开发者ID:cacizi41,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例13: test_rotated_root_after_insert

def test_rotated_root_after_insert(seq):
    """Test that value at top of tree is what we expect after rotate."""
    tree = Bst()
    expected_root_val = list(sorted(seq))[1]
    tree.insert(seq[0])
    tree.insert(seq[1])
    assert tree.value == seq[0]
    tree.insert(seq[2])
    assert tree.value == expected_root_val
开发者ID:scotist,项目名称:data-structures,代码行数:9,代码来源:test_bst.py

示例14: test_rotated_root_after_delete_ll

def test_rotated_root_after_delete_ll():
    """Test that tree rotates as expected after deleting from heavier side."""
    tree = Bst()
    for val in [3, 4, 2, 1]:
        tree.insert(val)
    assert tree.value == 3
    tree.delete(4)
    assert all([tree.value == 2,
                tree.left_child.value == 1,
                tree.right_child.value == 3])
开发者ID:scotist,项目名称:data-structures,代码行数:10,代码来源:test_bst.py

示例15: test_check_balance_left_left

def test_check_balance_left_left():
    """Test for balance of tree from selected Node."""
    from bst import Bst
    new_bst = Bst()
    new_bst.insert(15)
    new_bst.insert(12)
    new_bst.insert(10)
    assert new_bst.head.check_balance() == 0
    assert new_bst.head.left.check_balance() == 0
    assert new_bst.head.right.check_balance() == 0
开发者ID:jmcclena94,项目名称:data-structures,代码行数:10,代码来源:test_bst.py


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