本文整理匯總了Python中linked_list.implementation.LinkedList類的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList類的具體用法?Python LinkedList怎麽用?Python LinkedList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了LinkedList類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_pop_removes_last_item
def test_pop_removes_last_item(self):
l1 = LinkedList([1, 2, 3])
elem = l1.pop(2)
self.assertEqual(elem, 3)
self.assertEqual(l1.count(), 2)
self.assertEqual(l1, LinkedList([1, 2]))
示例2: test_pop_removes_item_in_the_middle_of_the_list
def test_pop_removes_item_in_the_middle_of_the_list(self):
l1 = LinkedList([1, 2, 3, 4, 5])
elem = l1.pop(2)
self.assertEqual(elem, 3)
self.assertEqual(l1.count(), 4)
self.assertEqual(l1, LinkedList([1, 2, 4, 5]))
elem = l1.pop(1)
self.assertEqual(elem, 2)
self.assertEqual(l1.count(), 3)
self.assertEqual(l1, LinkedList([1, 4, 5]))
示例3: test_add_equals_list
def test_add_equals_list(self):
my_list = LinkedList()
my_list += LinkedList([1, 2])
self.assertEqual(my_list, LinkedList([1, 2]))
my_list = LinkedList([1, 2])
my_list += LinkedList([3, 4])
self.assertEqual(my_list, LinkedList([1, 2, 3, 4]))
my_list = LinkedList([1, 2])
my_list += LinkedList()
self.assertEqual(my_list, LinkedList([1, 2]))
my_list = LinkedList()
my_list += LinkedList()
self.assertEqual(my_list.count(), 0)
self.assertEqual(my_list, LinkedList())
示例4: test_add_list
def test_add_list(self):
my_list = LinkedList()
new_list = my_list + LinkedList([1])
self.assertEqual(new_list, LinkedList([1]))
self.assertEqual(my_list, LinkedList())
my_list = LinkedList([1, 2])
new_list = my_list + LinkedList([3, 4])
self.assertEqual(new_list, LinkedList([1, 2, 3, 4]))
self.assertEqual(my_list, LinkedList([1, 2]))
my_list = LinkedList([1, 2])
new_list = my_list + LinkedList()
self.assertEqual(new_list, LinkedList([1, 2]))
self.assertEqual(my_list, LinkedList([1, 2]))
my_list = LinkedList()
new_list = my_list + LinkedList()
self.assertEqual(new_list, LinkedList())
self.assertEqual(new_list.count(), 0)
self.assertEqual(my_list, LinkedList())
self.assertEqual(my_list.count(), 0)
示例5: test_append
def test_append(self):
my_list = LinkedList()
my_list.append(1)
self.assertEqual(my_list.start.elem, 1)
self.assertEqual(my_list.start.next, None)
self.assertEqual(my_list, LinkedList([1]))
my_list.append(2)
self.assertEqual(my_list.start.elem, 1)
self.assertEqual(my_list.start.next, Node(2))
self.assertEqual(my_list.start.next.elem, 2)
self.assertEqual(my_list.start.next.next, None)
self.assertEqual(my_list.count(), 2)
示例6: test_pop_with_a_single_element_list
def test_pop_with_a_single_element_list(self):
# Default index
l1 = LinkedList([9])
elem = l1.pop()
self.assertEqual(elem, 9)
self.assertEqual(l1.count(), 0)
self.assertEqual(l1, LinkedList([]))
# index == 0
l1 = LinkedList([9])
elem = l1.pop(0)
self.assertEqual(elem, 9)
self.assertEqual(l1.count(), 0)
self.assertEqual(l1, LinkedList([]))