本文整理汇总了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')
示例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())
示例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)
示例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())
示例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)
示例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())
示例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)
示例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)
示例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)
示例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)
示例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')
示例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')
示例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)
示例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())