当前位置: 首页>>代码示例>>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;未经允许,请勿转载。