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


Python linked_list.LinkedList类代码示例

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


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

示例1: test_pop_from_empty_list

 def test_pop_from_empty_list(self):
     """Pop from a LinkedList that is empty."""
     ll = LinkedList()
     self.assertTrue(ll.head is None)
     node = ll.pop()
     self.assertTrue(node is None)
     self.assertTrue(ll.head is None)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:7,代码来源:test_linked_list.py

示例2: test_remove_empty_list

 def test_remove_empty_list(self):
     """Remove from an empty LinkedList."""
     ll = LinkedList()
     prestring = ll.__str__()
     ll.remove(self.insert_float)
     poststring = ll.__str__()
     self.assertEqual(prestring, poststring)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:7,代码来源:test_linked_list.py

示例3: test_pop_from_one_list

 def test_pop_from_one_list(self):
     """Pop from a LinkedList with one node."""
     ll = LinkedList()
     ll.insert(self.insert_string)
     self.assertEqual(ll.head.value, self.insert_string)
     node = ll.pop()
     self.assertEqual(node.value, self.insert_string)
     self.assertTrue(ll.head is None)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:8,代码来源:test_linked_list.py

示例4: test_search

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,代码行数:8,代码来源:test_linked_list.py

示例5: test_text_representation

 def test_text_representation(self):
     self.assertEqual(repr(self.ll), 'LinkedList()')
     self.ll = LinkedList(1)
     self.assertEqual(repr(self.ll), 'LinkedList(1)')
     self.ll = LinkedList([1, 2, 3, 4])
     self.assertEqual(repr(self.ll), 'LinkedList([1, 2, 3, 4])')
     self.ll = LinkedList(1, 2, 3, 4)
     self.assertEqual(repr(self.ll), 'LinkedList(1, 2, 3, 4)')
开发者ID:ignat980,项目名称:CS-Theory,代码行数:8,代码来源:test_linked_list.py

示例6: test_remove_item

    def test_remove_item(self):
        ll = LinkedList()
        ll.add(1)
        ll.add(2)

        self.assertEqual(len(ll), 2)
        ll.remove(1)
        self.assertEqual(len(ll), 1)
开发者ID:ocozalp,项目名称:Algorithms,代码行数:8,代码来源:linked_list_test.py

示例7: test_insert_float_into_empty

    def test_insert_float_into_empty(self):
        """Insert into a LinkedList that is empty."""
        ll = LinkedList()

        self.assertTrue(ll.head is None)
        ll.insert(self.insert_float)
        self.assertEqual(ll.head.value, self.insert_float)
        self.assertTrue(isinstance(ll.head.value, float))
        self.assertTrue(ll.head.next is None)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:9,代码来源:test_linked_list.py

示例8: test_remove_list_with_value_at_tail

    def test_remove_list_with_value_at_tail(self):
        """Remove from a populated LinkedList a value it contains at its tail."""
        ll = LinkedList()
        ll.insert(self.insert_float)
        ll.insert(self.insert_int)
        ll.insert(self.insert_string)

        ll.remove(self.insert_float)
        expected = '(' + "'" + self.insert_string + "'" + ', ' + \
            str(self.insert_int) + ')'
        poststring = ll.__str__()
        self.assertEqual(expected, poststring)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:12,代码来源:test_linked_list.py

示例9: test_search_list_without_value

    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,代码行数:9,代码来源:test_linked_list.py

示例10: test_size_of_populated_list

    def test_size_of_populated_list(self):
        """Get the size of a populated LinkedList."""
        ll = LinkedList()
        ll.insert(self.insert_float)
        ll.insert(self.insert_int)
        ll.insert(self.insert_string)

        self.assertEqual(ll.head.value, self.insert_string)
        self.assertEqual(ll.size(), 3)
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:9,代码来源:test_linked_list.py

示例11: test_init

 def test_init(self):
     ll = LinkedList()
     self.assertTrue(ll.is_empty(), msg="initalizing an empty linked list should be empty")
     ll = LinkedList('Data')
     self.assertFalse(ll.is_empty(), msg="initalizing a linked list with one element should not be empty")
     ll = LinkedList(['Data', 'Data2'])
     self.assertFalse(ll.is_empty(), msg="initalizing a linked list with one list should not be empty")
     ll = LinkedList('Data', 'Data2', 'Data3')
     self.assertFalse(ll.is_empty(), msg="initalizing a linked list with multiple element should not be empty")
开发者ID:ignat980,项目名称:CS-Theory,代码行数:9,代码来源:test_linked_list.py

示例12: test_partition_around_x

 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())
开发者ID:jwhite007,项目名称:DataStructures,代码行数:8,代码来源:linked_list_tests.py

示例13: test_insert_at_index

 def test_insert_at_index(self):
     self.ll = LinkedList('Data1', 'Data2', 'Data3', 'Data4', 'Data5')
     self.ll.insert_at_index(3, 'Data3.5')
     self.assertEqual(self.ll[3], 'Data3.5', 'Insert at index should set the data at the index')
     self.assertEqual(self.ll[2], 'Data3', 'Insert at index should not change the data at the index before it')
     self.assertEqual(self.ll[4], 'Data4', 'Insert at index should move the other data up an index')
     with self.assertRaises(IndexError, msg='Insert at out of bounds index should raise IndexError'):
         self.ll.insert_at_index(len(self.ll) + 1, 'Data7')
开发者ID:ignat980,项目名称:CS-Theory,代码行数:8,代码来源:test_linked_list.py

示例14: test_search_list_with_value_at_tail

    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,代码行数:10,代码来源:test_linked_list.py

示例15: test_str_many_list

    def test_str_many_list(self):
        """Get the string representation of a LinkedList with many values."""
        ll = LinkedList()
        ll.insert(self.insert_float)
        ll.insert(self.insert_int)
        ll.insert(self.insert_string)

        self.assertEqual(ll.__str__(), '(' + "'" + self.insert_string +
            "', " + str(self.insert_int) + ', ' + str(self.insert_float) +
            ')')
开发者ID:geekofalltrades,项目名称:data-structures,代码行数:10,代码来源:test_linked_list.py


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