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


Python LinkedList.peek方法代码示例

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


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

示例1: test_reverse_single

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

示例2: test_reverse

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import peek [as 别名]
 def test_reverse(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))
     ll.reverse()
     self.assertEqual("9->8->7", str(ll))
     self.assertEqual(9, ll.peek())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:12,代码来源:test_linkedlist.py

示例3: test_prepend

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import peek [as 别名]
 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())
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:12,代码来源:test_linkedlist.py

示例4: test_reverse_double

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import peek [as 别名]
 def test_reverse_double(self):
     ll = LinkedList(45)
     ll.append(46)
     self.assertEqual(2, len(ll))
     self.assertEqual(45, ll.peek())
     self.assertEqual("45->46", str(ll))
     ll.reverse()
     self.assertEqual(2, len(ll))
     self.assertEqual(46, ll.peek())
     self.assertEqual("46->45", str(ll))
开发者ID:PeteRichardson,项目名称:practice-python,代码行数:12,代码来源:test_linkedlist.py

示例5: Test_LinkedList

# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import peek [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


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