本文整理匯總了Python中LinkedList.LinkedList.size方法的典型用法代碼示例。如果您正苦於以下問題:Python LinkedList.size方法的具體用法?Python LinkedList.size怎麽用?Python LinkedList.size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.size方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_size
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
def test_size():
l_list = LinkedList()
assert l_list.size() == 0
l_list.insert("Batman")
l_list.insert("Superman")
assert l_list.size() == 2
l_list.delete("Superman")
assert l_list.size() == 1
示例2: RemoveDuplicatesTest
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
class RemoveDuplicatesTest(unittest.TestCase):
def setUp(self):
self.default_list = LinkedList()
self.default_list.insert('a')
self.default_list.insert('b')
self.default_list.insert('c')
self.default_list.insert('c')
self.default_list.insert('d')
self.default_list.insert('d')
def test_remove_duplicates(self):
remove_duplicates(self.default_list)
self.assertEqual(self.default_list.size(), 4)
示例3: LinkedListTest
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
class LinkedListTest(unittest.TestCase):
def setUp(self):
self.default_list = LinkedList()
self.default_list.insert('a')
self.default_list.insert('b')
self.default_list.insert('c')
self.default_list.insert('d')
def test_insert(self):
self.default_list.insert('z')
self.assertEqual(self.default_list.head.get_data(), 'z')
self.assertEqual(self.default_list.head.get_next().get_data(), 'd')
def test_get_next(self):
self.assertEqual(self.default_list.head.get_next().get_data(), 'c')
def test_search(self):
# search head
self.assertEqual(self.default_list.search('d'), self.default_list.head)
# normal search
self.assertEqual(self.default_list.search('c'), self.default_list.head.get_next())
# search value not in list
self.assertEqual(self.default_list.search('e'), None)
def test_delete_head(self):
self.default_list.delete('d')
self.assertEqual(self.default_list.head.get_data(), 'c')
self.assertEqual(self.default_list.size(), 3)
def test_delete_tail(self):
self.default_list.delete('a')
self.assertEqual(self.default_list.size(), 3)
def test_delete_not_exist(self):
self.assertEqual(self.default_list.delete('e'), None)
示例4: range
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
list1.insert(8)
list1.insert(2)
#add elements in second linked list. Below I'm inserting number 813
list2.insert(3)
list2.insert(1)
list2.insert(8)
print "== Initial list1 =="
list1.printlist()
print "== Initial list2 =="
list2.printlist()
#compare total elements in lists and accordingly add zeros to make them of same size
if list1.size() > list2.size():
diff = list1.size() - list2.size()
for i in range(0, diff):
list2.insert(0)
elif list1.size() < list2.size():
diff = list2.size() - list1.size()
for i in range(0, diff):
list1.insert(0)
print "After making same size..."
print "== list1 =="
list1.printlist()
print "== list2 =="
list2.printlist()
示例5: testLargeSize
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
def testLargeSize(self):
ll = LinkedList()
for i in range(0, 10000):
ll.addNode(randint(1, 10))
self.assertEqual(ll.size(), 10000)
示例6: testSize
# 需要導入模塊: from LinkedList import LinkedList [as 別名]
# 或者: from LinkedList.LinkedList import size [as 別名]
def testSize(self):
ll = LinkedList()
ll.addNode(1)
self.assertEqual(ll.size(), 1)