本文整理汇总了Python中data_structures.linked_list.LinkedList.pop方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.pop方法的具体用法?Python LinkedList.pop怎么用?Python LinkedList.pop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类data_structures.linked_list.LinkedList
的用法示例。
在下文中一共展示了LinkedList.pop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pop_from_empty_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import pop [as 别名]
def test_pop_from_empty_list(self):
"""Pop from a LinkedList that is empty."""
ll = LinkedList()
self.assertTrue(ll.head is None)
node = ll.pop()
self.assertTrue(node is None)
self.assertTrue(ll.head is None)
示例2: test_pop_from_one_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import pop [as 别名]
def test_pop_from_one_list(self):
"""Pop from a LinkedList with one node."""
ll = LinkedList()
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
node = ll.pop()
self.assertEqual(node.value, self.insert_string)
self.assertTrue(ll.head is None)
示例3: test_pop_from_many_list
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import pop [as 别名]
def test_pop_from_many_list(self):
"""Pop from a LinkedList with many nodes."""
ll = LinkedList()
ll.insert(self.insert_float)
ll.insert(self.insert_int)
ll.insert(self.insert_string)
self.assertEqual(ll.head.value, self.insert_string)
node = ll.pop()
self.assertEqual(node.value, self.insert_string)
self.assertEqual(ll.head.value, self.insert_int)
示例4: test_pop
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import pop [as 别名]
def test_pop(items):
s = LinkedList(items)
for item in reversed(items):
assert s.pop() == item
with pytest.raises(IndexError):
s.pop()
示例5: TestLinky
# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import pop [as 别名]
class TestLinky(unittest.TestCase):
def setUp(self):
self.linky = LinkedList()
l = [1, 2, 3, 4]
for i in l:
self.linky.insert(i)
def test_insert_to_empty(self):
self.linky = LinkedList()
self.linky.insert(1)
self.assertEqual(1, self.linky.head.val)
def test_insert_to_non_empty(self):
self.linky.insert(5)
self.assertEqual(5, self.linky.head.val)
def test_pop_empty(self):
self.linky = LinkedList()
self.assertEqual(None, self.linky.pop())
def test_pop_non_empty(self):
self.assertEqual(4, self.linky.pop())
def test_size_greater_than_one(self):
self.assertEqual(4, self.linky.size())
def test_size_of_one(self):
self.linky = LinkedList()
self.linky.insert(1)
self.assertEqual(1, self.linky.size())
def test_size_of_zero(self):
self.linky = LinkedList()
self.assertEqual(0, self.linky.size())
def test_search_exists(self):
self.assertEqual(True, self.linky.search(3))
def test_search_not_exists(self):
self.assertEqual(False, self.linky.search(5))
def test_remove_head(self):
self.linky.remove(4)
self.assertListEqual([3, 2, 1], self.linky.print_me())
def test_remove_middle(self):
self.linky.remove(2)
self.assertListEqual([4, 3, 1], self.linky.print_me())
def test_print_me(self):
self.linky = LinkedList()
self.assertListEqual([], self.linky.print_me())
def test_return_0th_from_4th(self):
self.assertEqual(1, self.linky.return_kth_from_nth(0, 4))
def test_return_1st_from_4th(self):
self.assertEqual(2, self.linky.return_kth_from_nth(1, 4))
def test_return_0th_from_2nd(self):
self.assertEqual(3, self.linky.return_kth_from_nth(0, 2))
def test_return_1st_from_2nd(self):
self.assertEqual(4, self.linky.return_kth_from_nth(1, 2))
def test_partition_around_x(self):
self.linky = LinkedList()
l = [1, 2, 3, 4, 5, 6, 7, 5, 8, 9, 10]
for i in range(len(l)):
self.linky.insert(l[i])
self.linky.partition_around_x(5)
self.assertListEqual([1, 2, 3, 4, 5, 5, 10, 9, 8, 7, 6],
self.linky.print_me())
def test_rem_dups(self):
self.linky = LinkedList()
self.linky.insert(1)
self.linky.insert(1)
self.linky.insert(2)
self.linky.insert(2)
self.linky.insert(3)
self.linky.insert(3)
self.linky.rem_dups()
self.assertListEqual([3, 2, 1], self.linky.print_me())