当前位置: 首页>>代码示例>>Python>>正文


Python LinkedList.search方法代码示例

本文整理汇总了Python中data_structures.linked_list.LinkedList.search方法的典型用法代码示例。如果您正苦于以下问题:Python LinkedList.search方法的具体用法?Python LinkedList.search怎么用?Python LinkedList.search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在data_structures.linked_list.LinkedList的用法示例。


在下文中一共展示了LinkedList.search方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_search

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
def test_search():
    items = range(10)
    a_list = LinkedList(items)
    # searching for a non-contained item returns None
    assert a_list.search(object()) is None
    # prove those values are searchable
    for item in items:
        assert a_list.search(item).data == item
开发者ID:Mumbleskates,项目名称:data-structures,代码行数:10,代码来源:test_linked_list.py

示例2: test_remove

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
def test_remove():
    items = list(range(10))
    a_list = LinkedList(items)
    # removing a value that isn't in it should return false
    assert a_list.remove(object()) is False
    assert list(a_list) == list(reversed(items))
    # get 7 and remove it
    seven = a_list.search(7)
    assert a_list.remove(seven) is True
    assert list(a_list) == [9, 8, 6, 5, 4, 3, 2, 1, 0]
    # remove all the even-numbered values
    for node in a_list:
        if node & 1 == 0:
            assert a_list.remove(a_list.search(node)) is True
    assert list(a_list) == [9, 5, 3, 1]
开发者ID:Mumbleskates,项目名称:data-structures,代码行数:17,代码来源:test_linked_list.py

示例3: test_search_list_without_value

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
    def test_search_list_without_value(self):
        """Search a populated LinkedList for a value it doesn't contain."""
        ll = LinkedList()
        ll.insert(self.insert_float)
        ll.insert(self.insert_int)
        ll.insert(self.insert_string)

        node = ll.search(self.value_not_in_list)
        self.assertTrue(node is None)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:11,代码来源:test_linked_list.py

示例4: test_search_list_with_value_at_tail

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
    def test_search_list_with_value_at_tail(self):
        """Search a populated LinkedList for a value it contains at its tail."""
        ll = LinkedList()
        ll.insert(self.insert_float)
        ll.insert(self.insert_int)
        ll.insert(self.insert_string)

        node = ll.search(self.insert_float)
        self.assertTrue(isinstance(node, LinkedListNode))
        self.assertEqual(node.value, self.insert_float)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:12,代码来源:test_linked_list.py

示例5: test_search_empty_list

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
    def test_search_empty_list(self):
        """Search for a value in an empty LinkedList."""
        ll = LinkedList()

        node = ll.search(self.insert_string)
        self.assertTrue(node is None)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:8,代码来源:test_linked_list.py

示例6: TestLinky

# 需要导入模块: from data_structures.linked_list import LinkedList [as 别名]
# 或者: from data_structures.linked_list.LinkedList import search [as 别名]
class TestLinky(unittest.TestCase):

    def setUp(self):
        self.linky = LinkedList()
        l = [1, 2, 3, 4]
        for i in l:
            self.linky.insert(i)

    def test_insert_to_empty(self):
        self.linky = LinkedList()
        self.linky.insert(1)
        self.assertEqual(1, self.linky.head.val)

    def test_insert_to_non_empty(self):
        self.linky.insert(5)
        self.assertEqual(5, self.linky.head.val)

    def test_pop_empty(self):
        self.linky = LinkedList()
        self.assertEqual(None, self.linky.pop())

    def test_pop_non_empty(self):
        self.assertEqual(4, self.linky.pop())

    def test_size_greater_than_one(self):
        self.assertEqual(4, self.linky.size())

    def test_size_of_one(self):
        self.linky = LinkedList()
        self.linky.insert(1)
        self.assertEqual(1, self.linky.size())

    def test_size_of_zero(self):
        self.linky = LinkedList()
        self.assertEqual(0, self.linky.size())

    def test_search_exists(self):
        self.assertEqual(True, self.linky.search(3))

    def test_search_not_exists(self):
        self.assertEqual(False, self.linky.search(5))

    def test_remove_head(self):
        self.linky.remove(4)
        self.assertListEqual([3, 2, 1], self.linky.print_me())

    def test_remove_middle(self):
        self.linky.remove(2)
        self.assertListEqual([4, 3, 1], self.linky.print_me())

    def test_print_me(self):
        self.linky = LinkedList()
        self.assertListEqual([], self.linky.print_me())

    def test_return_0th_from_4th(self):
        self.assertEqual(1, self.linky.return_kth_from_nth(0, 4))

    def test_return_1st_from_4th(self):
        self.assertEqual(2, self.linky.return_kth_from_nth(1, 4))

    def test_return_0th_from_2nd(self):
        self.assertEqual(3, self.linky.return_kth_from_nth(0, 2))

    def test_return_1st_from_2nd(self):
        self.assertEqual(4, self.linky.return_kth_from_nth(1, 2))

    def test_partition_around_x(self):
        self.linky = LinkedList()
        l = [1, 2, 3, 4, 5, 6, 7, 5, 8, 9, 10]
        for i in range(len(l)):
            self.linky.insert(l[i])
        self.linky.partition_around_x(5)
        self.assertListEqual([1, 2, 3, 4, 5, 5, 10, 9, 8, 7, 6],
                             self.linky.print_me())

    def test_rem_dups(self):
        self.linky = LinkedList()
        self.linky.insert(1)
        self.linky.insert(1)
        self.linky.insert(2)
        self.linky.insert(2)
        self.linky.insert(3)
        self.linky.insert(3)
        self.linky.rem_dups()
        self.assertListEqual([3, 2, 1], self.linky.print_me())
开发者ID:jwhite007,项目名称:DataStructures,代码行数:87,代码来源:linked_list_tests.py


注:本文中的data_structures.linked_list.LinkedList.search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。