本文整理汇总了Python中linkedlist.LinkedList.extract方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.extract方法的具体用法?Python LinkedList.extract怎么用?Python LinkedList.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.extract方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestLinkedList
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import extract [as 别名]
class TestLinkedList(unittest.TestCase):
def setUp(self):
self.list = LinkedList()
def test_element(self):
e = LinkedList.Element(self.list, 10)
self.assertEqual(e._list, self.list)
self.assertEqual(e.value, 10)
self.assertEqual(e.next, None)
def test_init(self):
self.assertEqual(self.list.head, None)
self.assertEqual(self.list.tail, None)
self.assertEqual(self.list.isEmpty, True)
# self.assertRaises(RuntimeError, self.list.first)
# self.assertRaises(RuntimeError, self.list.last)
def test_pend(self):
self.list.prepend(10)
self.assertEqual(self.list.head.value, 10)
self.list.prepend(11)
self.assertEqual(self.list.head.value, 11)
self.list.append(5)
self.assertEqual(self.list.last, 5)
self.assertEqual(self.list.isEmpty, False)
self.list.purge()
self.assertEqual(self.list.isEmpty, True)
def test_extract(self):
self.assertRaises(KeyError, self.list.extract, 10)
self.list.prepend(10)
self.list.prepend(5)
self.list.extract(10)
self.assertRaises(KeyError, self.list.extract, 6)
self.list.extract(5)
self.assertEqual(self.list.isEmpty, True)
def test_copy(self):
self.list.prepend(10)
self.list.prepend(5)
a = copy(self.list)
self.assertEqual(a.first, self.list.first)
self.assertEqual(a.last, self.list.last)