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


Python LinkedList.add方法代码示例

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


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

示例1: test_when_adding_several_items_should_be_able_to_get_last_node_by_index

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_adding_several_items_should_be_able_to_get_last_node_by_index(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.add('test item 1')
     linked_list.add('test item 2')
     linked_list.add('test item 3')
     last_node = linked_list.get(3)
     self.assertEqual(last_node.value, 'test item 3')
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:10,代码来源:LinkedListTests.py

示例2: test_when_adding_second_element_previous_one_should_point_to_it

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
    def test_when_adding_second_element_previous_one_should_point_to_it(self):
        linked_list = LinkedList()
        linked_list.add('test item 0')
        first_node = linked_list.get(0)

        linked_list.add('test item 1')

        self.assertEqual(first_node.next_node, linked_list.get_last())
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:10,代码来源:LinkedListTests.py

示例3: LinkedList

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_3_items_have_been_added_and_last_one_removed_then__get_last__should_return_second_item_with_no_next_node(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.add('test item 1')
     linked_list.add('test item 2')
     linked_list.remove(2)
     last_node = linked_list.get_last()
     self.assertEqual(last_node.value, 'test item 1')
     self.assertIsNone(last_node.next_node)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:11,代码来源:LinkedListTests.py

示例4: test_when_there_are_two_items_added_to_list_that_point_to_each_other_should_report_it_as_a_cycle

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
    def test_when_there_are_two_items_added_to_list_that_point_to_each_other_should_report_it_as_a_cycle(self):
        linked_list = LinkedList()
        linked_list.add('test item 0')
        linked_list.add('test item 1')
        node0 = linked_list.get(0)
        node1 = linked_list.get(1)
        node1.next_node = node0

        self.assertTrue(linked_list.has_loop())
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:11,代码来源:LinkedListTests.py

示例5: test_when_3_items_have_been_added_and_then_first_item_removed_3_times_count_should_be_0

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_3_items_have_been_added_and_then_first_item_removed_3_times_count_should_be_0(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.add('test item 1')
     linked_list.add('test item 2')
     linked_list.remove(0)
     linked_list.remove(0)
     linked_list.remove(0)
     self.assertEqual(linked_list.count, 0)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:11,代码来源:LinkedListTests.py

示例6: test_when_there_is_a_loop_in_the_middle_of_the_list_should_be_able_to_report_it

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
    def test_when_there_is_a_loop_in_the_middle_of_the_list_should_be_able_to_report_it(self):
        linked_list = LinkedList()
        linked_list.add('test item 0')
        linked_list.add('test item 1')
        linked_list.add('test item 2')
        linked_list.add('test item 3')
        linked_list.add('test item 4')

        node1 = linked_list.get(1)
        node3 = linked_list.get(3)
        node3.next_node = node1

        self.assertTrue(linked_list.has_loop())
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:15,代码来源:LinkedListTests.py

示例7: delete_middle_node

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
from LinkedList import *

def delete_middle_node(node):
    node.value = node.next.value
    node.next = node.next.next

ll = LinkedList()
ll.add_multiple([1, 2, 3, 4])
middle_node = ll.add(5)
ll.add_multiple([7, 8, 9])

print(ll)
delete_middle_node(middle_node)
print(ll)
开发者ID:soham-shah,项目名称:coding_practice,代码行数:16,代码来源:2_3.py

示例8: test__remove__when_one_item_have_been_added_and_then_removed_then_count_should_be_0

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test__remove__when_one_item_have_been_added_and_then_removed_then_count_should_be_0(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.remove(0)
     self.assertEqual(linked_list.count, 0)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:7,代码来源:LinkedListTests.py

示例9: test_when_two_items_have_been_added_should_return_count_equal_to_2

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_two_items_have_been_added_should_return_count_equal_to_2(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.add('test item 1')
     self.assertEqual(linked_list.count, 2)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:7,代码来源:LinkedListTests.py

示例10: test_when_one_item_has_been_added_should_return_count_equal_to_1

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_one_item_has_been_added_should_return_count_equal_to_1(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     self.assertEqual(linked_list.count, 1)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:6,代码来源:LinkedListTests.py

示例11: test_when_adding_several_items_should_be_able_to_get_first_one

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_adding_several_items_should_be_able_to_get_first_one(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.add('test item 1')
     first_node = linked_list.get_first()
     self.assertEqual(first_node.value, 'test item 0')
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:8,代码来源:LinkedListTests.py

示例12: test_when_one_item_has_been_added_it_should_be_returned_as_first_one

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_one_item_has_been_added_it_should_be_returned_as_first_one(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     self.assertEqual(linked_list.get_first().value, 'test item 0')
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:6,代码来源:LinkedListTests.py

示例13: test_when_there_are_no_loops_should_find_none

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
    def test_when_there_are_no_loops_should_find_none(self):
        linked_list = LinkedList()
        linked_list.add('test item 0')
        linked_list.add('test item 1')

        self.assertFalse(linked_list.has_loops)
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:8,代码来源:LinkedListTests.py

示例14: test_when_1_item_have_been_added_and_removed_then_last_item_should_not_be_present

# 需要导入模块: import LinkedList [as 别名]
# 或者: from LinkedList import add [as 别名]
 def test_when_1_item_have_been_added_and_removed_then_last_item_should_not_be_present(self):
     linked_list = LinkedList()
     linked_list.add('test item 0')
     linked_list.remove(0)
     self.assertIsNone(linked_list.get_last())
开发者ID:Restuta,项目名称:LinkedListTests,代码行数:7,代码来源:LinkedListTests.py


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