當前位置: 首頁>>代碼示例>>Python>>正文


Python LinkedList.search方法代碼示例

本文整理匯總了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"
開發者ID:prathamtandon,項目名稱:python-algorithms-and-data-structures,代碼行數:10,代碼來源:LinkedList_test.py

示例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")
開發者ID:pombredanne,項目名稱:CrackCode,代碼行數:11,代碼來源:TestLinkedList.py

示例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"
開發者ID:pombredanne,項目名稱:CrackCode,代碼行數:13,代碼來源:TestLinkedList.py

示例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))
開發者ID:avihoo,項目名稱:singly-linked-list,代碼行數:14,代碼來源:TestLinkedList.py

示例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)
開發者ID:ZachLiuGIS,項目名稱:Algorithm-Enthusiasts,代碼行數:38,代碼來源:test_LinkedList.py

示例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
開發者ID:prathamtandon,項目名稱:python-algorithms-and-data-structures,代碼行數:7,代碼來源:LinkedList_test.py


注:本文中的LinkedList.LinkedList.search方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。