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


Python Bst.isempty方法代码示例

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


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

示例1: test_isempty

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import isempty [as 别名]
    def test_isempty(self):
        tree = Bst()
        self.assertTrue(tree.isempty())

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

示例2: remove_one_child_root

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import isempty [as 别名]
            def remove_one_child_root():
                """Removing root in a tree where the root has only one child"""
                tree = Bst()
                tree.add(ROOT_DATA)
                tree.add(LEFT_DATA)
                self.assertFalse(tree.isempty())
                self.assertEquals(tree.getsize(), 2)
                self.assertEquals(tree.root.getleft().getdata(), LEFT_DATA)

                val = tree.remove(ROOT_DATA)

                self.assertFalse(tree.isempty())
                self.assertEquals(tree.getsize(), 1)
                self.assertEquals(val, ROOT_DATA)
                self.assertIsNotNone(tree.root)
                self.assertNotEquals(tree.root.getdata(), ROOT_DATA)
                self.assertEquals(tree.root, Node(LEFT_DATA))
开发者ID:mosdragon,项目名称:PythonDS,代码行数:19,代码来源:test_bst.py

示例3: test_contains

# 需要导入模块: from bst import Bst [as 别名]
# 或者: from bst.Bst import isempty [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))
开发者ID:mosdragon,项目名称:PythonDS,代码行数:75,代码来源:test_bst.py


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