本文整理汇总了Python中LinkedList.LinkedList.search方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.search方法的具体用法?Python LinkedList.search怎么用?Python LinkedList.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedList.LinkedList
的用法示例。
在下文中一共展示了LinkedList.search方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_positive_search
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [as 别名]
def test_positive_search():
l_list = LinkedList()
l_list.insert("Batman")
l_list.insert("Superman")
found = l_list.search("Batman")
assert found.get_key() == "Batman"
found = l_list.search("Superman")
assert found.get_key() == "Superman"
示例2: test_searchNone
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [as 别名]
def test_searchNone():
l_list = LinkedList()
l_list.insert("Jacob")
l_list.insert("Pallymay")
# make sure reg search works
found = l_list.search("Jacob")
assert found.get_data() == "Jacob"
with pytest.raises(ValueError):
l_list.search("Vincent")
示例3: test_positive_search
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [as 别名]
def test_positive_search():
l_list = LinkedList()
l_list.insert("Jacob")
l_list.insert("Pallymay")
l_list.insert("Rasmus")
found = l_list.search("Jacob")
assert found.get_data() == "Jacob"
found = l_list.search("Pallymay")
assert found.get_data() == "Pallymay"
found = l_list.search("Jacob")
assert found.get_data() == "Jacob"
示例4: test_remove
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [as 别名]
def test_remove(self):
# test empty list
myLinkedList = LinkedList()
self.assertRaises(ValueError, myLinkedList.remove, 5)
# test node not in linked list
myLinkedList = self.getLinkedList()
self.assertRaises(ValueError, myLinkedList.remove, 11)
# test successful removal
myLinkedList.remove(5)
self.assertFalse(myLinkedList.search(5))
示例5: LinkedListTest
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [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)
示例6: test_negative_search
# 需要导入模块: from LinkedList import LinkedList [as 别名]
# 或者: from LinkedList.LinkedList import search [as 别名]
def test_negative_search():
l_list = LinkedList()
l_list.insert("Batman")
not_found = l_list.search("Bruce Wayne")
assert not_found is None