本文整理汇总了Python中linkedlist.LinkedList.size方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.size方法的具体用法?Python LinkedList.size怎么用?Python LinkedList.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linkedlist.LinkedList
的用法示例。
在下文中一共展示了LinkedList.size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import size [as 别名]
def main():
#Create list of names
listOfNames = { "Tom", "Harry","Susan","Ethan","Willy","Shaina"}
#Create linkedlist object
testinglist = LinkedList()
#Test insertion method
for name in listOfNames:
testinglist.insert(name)
#Test size of list
print testinglist.size()
#Test print list
testinglist.printList()
#Test Deletion of head node
testinglist.delete("Tom")
#Test Deletion method:
testinglist.delete("Susan")
testinglist.printList()
#Test search list
testinglist.search("Willy")
示例2: TestLinkedList
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import size [as 别名]
class TestLinkedList(unittest.TestCase):
def setUp(self):
self.linked_list = LinkedList()
def test_append(self):
self.linked_list.append(1)
self.assertEqual(self.linked_list.size(), 1)
def test_remove(self):
self.linked_list.append(1)
self.linked_list.append(2)
self.linked_list.append(3)
self.linked_list.remove(2)
self.assertEqual(self.linked_list.size(), 2)
def test_search_by_data(self):
self.linked_list.append(1)
self.linked_list.append(2)
self.linked_list.append(3)
self.assertEqual(self.linked_list.search_by_data(3), (3, 2))
def test_search_by_position(self):
self.linked_list.append(1)
self.linked_list.append(2)
self.linked_list.append(3)
self.assertEqual(self.linked_list.search_by_position(1), 2)
示例3: test_create
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import size [as 别名]
def test_create(self):
"""Create empty list, single-item list, and multi-item list."""
list1 = LinkedList()
list2 = LinkedList(2)
list3 = LinkedList(1, 2, "buckle my shoe")
assert list1.size() == 0
assert list2.size() == 1
assert list3.size() == 3
示例4: main
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import size [as 别名]
def main():
ll = LinkedList()
data = [char for char in '123456789']
for char in data[::-1]:
node = Node(char)
ll.insert(node)
print ll
print ll.size()
print kth_tolast(ll.head, 5).val == '123456789'[-5]
示例5: TestLinkedList
# 需要导入模块: from linkedlist import LinkedList [as 别名]
# 或者: from linkedlist.LinkedList import size [as 别名]
class TestLinkedList(unittest.TestCase):
def setUp(self):
"""Test setup"""
self.empty_list = LinkedList()
self.A_LIST_HEAD = 42
self.a_list = LinkedList(self.A_LIST_HEAD)
def test_new_list(self):
"""A criação de uma Nova Lista"""
self.assertIsInstance(self.empty_list, LinkedList)
def test_new_list_empty(self):
"""Uma Nova Lista criada sem parâmetros é vazia"""
self.assertTrue(self.empty_list.is_empty())
def test_empty_list_equality(self):
"""Listas Vazias são iguais"""
a = LinkedList()
b = LinkedList()
self.assertEqual(self.empty_list, a)
self.assertEqual(self.empty_list, b)
self.assertEqual(a, b)
def test_new_list_not_empty_with_value(self):
"""Uma Nova Lista criada com parâmetros é não-vazia"""
self.assertFalse(self.a_list.is_empty())
def test_empty_list_size(self):
"""Uma Lista vazia possui tamanho zero"""
self.assertEqual(self.empty_list.size(), 0)
def test_a_list_with_one_element_size_is_one(self):
"""Uma Lista com um elemento possui tamanho 1"""
self.assertEqual(self.a_list.size(), 1)
def test_a_list_head_is_the_first_element(self):
"""A cabeça de uma lista é seu primeiro elemento"""
"""Caso a lista seja vazia, o valor da cabeça é None"""
self.assertEqual(self.empty_list.head().value,None)
self.assertEqual(self.a_list.head().value, self.A_LIST_HEAD)
def test_a_list_tail_is_the_rest_of_the_list(self):
"""A cauda de uma lista são todos os elementos menos a cabeça"""
"""Caso a lista seja vazia ou tenha somente um elemento,
a Cauda é uma Lista Vazia"""
self.assertEqual(self.empty_list.tail(),LinkedList())
self.assertEqual(self.a_list.tail(), LinkedList() )
def test_append_changes_list_size(self):
"""Append insere um elemento no final da lista"""
"""A operação append aumenta o tamanho da lista em 1"""
size = self.a_list.size()
self.a_list.append(55)
new_size = size + 1
self.assertEqual(self.a_list.size(), new_size)
def test_append_changes_list_size_multiple_elements(self):
"""X appends aumentam o tamanho da lista em X elementos"""
size = self.a_list.size()
x = random.randint(1, 200)
for i in range(0, x):
value = random.randint(1, 10000)
self.a_list.append(value)
new_size = size + x
self.assertEqual(self.a_list.size(), new_size)
def test_append_empty_list_appended_element_is_head(self):
"""Append numa lista vazia torna o novo elemento a cabeça da lista"""
self.assertTrue(self.empty_list.is_empty())
self.assertTrue(self.empty_list.head().is_empty())
x = 42
self.empty_list.append(x)
self.assertEqual(self.empty_list.head().value, x)
def test_prepend_changes_list_size(self):
"""Prepend insere um elemento no início da lista"""
"""A operação prepend aumenta o tamanho da lista em 1"""
size = self.a_list.size()
self.a_list.prepend(98)
new_size = size + 1
self.assertEqual(self.a_list.size(), new_size)
def test_prepend_changes_list_size_multiple_elements(self):
"""X prepends aumentam o tamanho da lista em X elementos"""
size = self.a_list.size()
x = random.randint(1, 200)
#.........这里部分代码省略.........