本文整理汇总了Python中linked_list.implementation.LinkedList.count方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.count方法的具体用法?Python LinkedList.count怎么用?Python LinkedList.count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linked_list.implementation.LinkedList
的用法示例。
在下文中一共展示了LinkedList.count方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pop_removes_item_in_the_middle_of_the_list
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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]))
示例2: test_pop_with_a_single_element_list
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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([]))
示例3: test_pop_removes_last_item
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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]))
示例4: test_append
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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)
示例5: test_add_equals_list
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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())
示例6: test_add_list
# 需要导入模块: from linked_list.implementation import LinkedList [as 别名]
# 或者: from linked_list.implementation.LinkedList import count [as 别名]
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)