本文整理汇总了Python中linkedlist.LinkedList.add_to_front方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.add_to_front方法的具体用法?Python LinkedList.add_to_front怎么用?Python LinkedList.add_to_front使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.add_to_front方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_can_only_remove_items_from_own_list
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_can_only_remove_items_from_own_list(self):
with pytest.raises(Exception):
ll = LinkedList()
linked_list2 = LinkedList()
ll.add_to_front(123)
list_item = ll.front
linked_list2.remove(list_item)
示例2: test_in_filter_preserves_front_and_back_if_needed
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_in_filter_preserves_front_and_back_if_needed(self):
ll = LinkedList()
item1 = ll.add_to_front(123, 123123)
item2 = ll.add_to_front(234234, 92834923)
ll.in_filter(None)
assert ll.front == item2
assert ll.back == item1
示例3: test_swap_only_items_from_list
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_swap_only_items_from_list(self):
ll = LinkedList()
ll2 = LinkedList()
item1 = ll.add_to_front(5151, 91951)
item2 = ll2.add_to_front(58888888, 851)
with pytest.raises(Exception):
ll.swap(item1, item2)
示例4: test_prev_from_front_is_none
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_prev_from_front_is_none(self):
'''Item at the front has None as prev pointer'''
ll = LinkedList()
ll.add_to_front(0, 98)
assert ll.front.prev == None
ll.add_to_front(123, 98)
assert ll.front.prev == None
示例5: test_in_filter_remove_all
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_in_filter_remove_all(self):
ll = LinkedList()
item1 = ll.add_to_front(123, 345)
item2 = ll.add_to_front(51515, 15151551)
item3 = ll.add_to_front(987, 234267)
assert ll.length == 3
ll.in_filter(lambda x,y: False)
assert ll.length == 0
示例6: test_swap_preserves_length
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_swap_preserves_length(self):
ll = LinkedList()
item1 = ll.add_to_front(5151, 91951)
assert ll.length == 1
item2 = ll.add_to_front(235151, 91951)
assert ll.length == 2
ll.swap(item1, item2)
assert ll.length == 2
示例7: test_remove_updates_head_if_necessary
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_remove_updates_head_if_necessary(self):
'''Removing head, updates head'''
ll = LinkedList()
item1 = ll.add_to_front(1234)
item2 = ll.add_to_front(list())
assert ll.front == item2
ll.remove(item2)
assert ll.front == item1
示例8: test_add_front_prepends_item
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_add_front_prepends_item(self):
'''Adding to the front of the list multiple times does not remove items.
Instead the list is prepended with the new item'''
ll = LinkedList()
ll.add_to_front(12, 54)
ll.add_to_front(14, 98)
assert ll.front.key == 14
assert ll.front.next.key == 12
示例9: test_non_empty_list_has_length
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_non_empty_list_has_length(self):
ll = LinkedList()
ll.add_to_front(123)
assert ll.length == 1
ll.add_to_back(345)
assert ll.length == 2
ll.add_to_front(987)
assert ll.length == 3
示例10: test_add_front_multiple_equal_items
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_add_front_multiple_equal_items(self):
'''Adding the same item to the front of the list multiple times creates
different linked list objects with the same item'''
ll = LinkedList()
ll.add_to_front(12)
ll.add_to_front(12)
assert ll.front.key == ll.front.next.key
assert ll.front != ll.front.next
示例11: test_filter_preserves_front_and_back_if_needed
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_filter_preserves_front_and_back_if_needed(self):
ll = LinkedList()
ll.add_to_front(123, 123123)
ll.add_to_front(234234, 92834923)
ll2 = ll.filter(None)
assert ll.front.key == ll2.front.key
assert ll.front.value == ll2.front.value
assert ll.back.key == ll2.back.key
assert ll.back.value == ll2.back.value
示例12: test_map_preserves_front_and_back
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_map_preserves_front_and_back(self):
ll = LinkedList()
ll.add_to_front(123, 123123)
ll.add_to_front(234234, 92834923)
ll2 = ll.map(None)
assert ll.front.key == ll2.front.key
assert ll.front.value == ll2.front.value
assert ll.back.key == ll2.back.key
assert ll.back.value == ll2.back.value
示例13: test_find_last_finds_last
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_find_last_finds_last(self):
ll = LinkedList()
key = 123
value1 = 441
value2 = "sdsfgg"
ll.add_to_front(key, value1)
ll.add_to_front(key, value2)
item = ll.find_last(key)
assert item.value == value1
示例14: test_add_to_front_prev
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_add_to_front_prev(self):
'''Add to front places previous front after the new front'''
ll = LinkedList()
key1 = 123
key2 = 1233
ll.add_to_front(key1)
ll.add_to_front(key2)
assert ll.front.next.key == key1
assert ll.front.next.prev.key == key2
示例15: test_removing_items_reduces_length
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import add_to_front [as 别名]
def test_removing_items_reduces_length(self):
ll = LinkedList()
assert ll.length == 0
ll.add_to_front(123)
ll.add_to_front(12312)
assert ll.length == 2
item = ll.front
ll.remove(item)
assert ll.length == 1
item = ll.front
ll.remove(item)
assert ll.length == 0