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


Python LinkedList.isEmpty方法代码示例

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


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

示例1: test_pop_to_empty

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import isEmpty [as 别名]
 def test_pop_to_empty(self):
     ll = LinkedList(5)
     self.assertEqual(1, len(ll))
     self.assertEqual(ll.next, None)
     self.assertFalse(ll.isEmpty())
     head_value = ll.pop()
     self.assertEqual(head_value, 5)
     self.assertEqual(0, len(ll))
     self.assertEqual(ll.next, None)
     self.assertTrue(ll.isEmpty())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:12,代码来源:test_linkedlist.py

示例2: test_clear_empty_list

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import isEmpty [as 别名]
 def test_clear_empty_list(self):
     ll = LinkedList()
     ll.clear()
     self.assertTrue(ll.isEmpty())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:6,代码来源:test_linkedlist.py

示例3: test_isEmpty

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import isEmpty [as 别名]
 def test_isEmpty(self):
     ll = LinkedList()
     self.assertTrue(ll.isEmpty())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:5,代码来源:test_linkedlist.py

示例4: Test_LinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import isEmpty [as 别名]
class Test_LinkedList(unittest.TestCase):
    def setUp(self):
        self.ll = LinkedList(4)
        self.ll.prepend(5)

    def test_simple(self):
        self.assertEqual(5, self.ll.peek())
        self.assertEqual(2, len(self.ll))

    def test_prepend(self):
        ll = LinkedList(3)
        self.assertEqual(1, len(ll))
        self.assertEqual(3, ll.peek())
        ll.prepend(2)
        self.assertEqual(2, len(ll))
        self.assertEqual(2, ll.peek())
        ll.prepend(1)
        self.assertEqual(3, len(ll))
        self.assertEqual(1, ll.peek())

    def test_append(self):
        self.ll.append(6)
        self.assertEqual(5, self.ll.peek())
        self.assertEqual(3, len(self.ll))
        self.assertEqual(4, self.ll.next.peek())
        self.assertEqual(6, self.ll.next.next.peek())

    def test_len(self):
        self.ll.append(6)
        self.assertEqual(3, len(self.ll))

    def test_len_uninitialized(self):
        ll = LinkedList()
        ll.prepend(5)
        self.assertEqual(1, len(ll))

    def test_pop(self):
        head_value = self.ll.pop()
        self.assertEqual(5, head_value)
        self.assertEqual(1, len(self.ll))
        self.assertEqual(4, self.ll.peek())

    def test_pop_to_empty(self):
        ll = LinkedList(5)
        self.assertEqual(1, len(ll))
        self.assertEqual(ll.next, None)
        self.assertFalse(ll.isEmpty())
        head_value = ll.pop()
        self.assertEqual(head_value, 5)
        self.assertEqual(0, len(ll))
        self.assertEqual(ll.next, None)
        self.assertTrue(ll.isEmpty())

    def test_isEmpty(self):
        ll = LinkedList()
        self.assertTrue(ll.isEmpty())

    def test_pop_empty(self):
        ll = LinkedList()
        self.assertRaises(ListEmptyError, ll.pop)

    def test_add(self):
        ll = LinkedList(4)
        ll.append(6)
        ll2 = LinkedList(10)
        ll2.append(12)
        ll2.append(13)
        ll = ll + ll2
        self.assertEqual(5, len(ll))

    def test_clear(self):
        self.assertFalse(self.ll.isEmpty())
        self.assertTrue(len(self.ll) == 2)
        self.ll.clear()
        self.assertTrue(self.ll.isEmpty())

    def test_clear_empty_list(self):
        ll = LinkedList()
        ll.clear()
        self.assertTrue(ll.isEmpty())

    def test_reversed(self):
        ll = LinkedList(7)
        ll.append(8)
        ll.append(9)
        self.assertEqual(3, len(ll))
        self.assertEqual(7, ll.peek())
        self.assertEqual("7->8->9", str(ll))
        rev = ll.reversed()
        self.assertEqual("9->8->7", str(rev))
        self.assertEqual(9, rev.peek())
        self.assertEqual(3, len(ll))
        self.assertEqual(7, ll.peek())
        self.assertEqual("7->8->9", str(ll))

    def test_reverse(self):
        ll = LinkedList(7)
        ll.append(8)
        ll.append(9)
        self.assertEqual(3, len(ll))
#.........这里部分代码省略.........
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:103,代码来源:test_linkedlist.py

示例5: test_reverse_empty

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import isEmpty [as 别名]
 def test_reverse_empty(self):
     ll = LinkedList()
     self.assertTrue(ll.isEmpty())
     ll.reverse()
     self.assertTrue(ll.isEmpty())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:7,代码来源:test_linkedlist.py


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