示例#1
0
 def test_delete__non_empty_list_multiple_value_exists__ok(self):
     alist = LinkedList()
     for i in range(1, 4):
         alist.insert_at_head(i)
     assert str(alist) == "3 -> 2 -> 1 -> None"
     alist.delete(2)
     assert str(alist) == "3 -> 1 -> None"
示例#2
0
 def test_search_multivalued_list__value_does_not_exists__return_false(
         self):
     alist = LinkedList()
     for i in range(1, 4):
         alist.insert_at_head(i)
     assert str(alist) == "3 -> 2 -> 1 -> None"
     assert alist.search(4) is False
示例#3
0
 def test_insert_at_position__position_out_of_range__raises(self):
     with pytest.raises(Exception):
         alist = LinkedList()
         for i in range(1, 4):
             alist.insert_at_head(i)
         assert str(alist) == "3 -> 2 -> 1 -> None"
         alist.insert_at_position("xxx", 3)
示例#4
0
 def test_insert_at_position__position_equals_tail__ok(self):
     alist = LinkedList()
     for i in range(1, 4):
         alist.insert_at_head(i)
     assert str(alist) == "3 -> 2 -> 1 -> None"
     data, position = "xxx", 2
     alist.insert_at_position(data, position)
     assert str(alist) == f"3 -> 2 -> 1 -> xxx -> None"
示例#5
0
 def test_insert_at_position__position_equals_head__ok(self):
     alist = LinkedList()
     for i in range(1, 4):
         alist.insert_at_head(i)
     assert str(alist) == "3 -> 2 -> 1 -> None"
     data, position = "xxx", 0
     alist.insert_at_position(data, position)
     assert alist.get_head().data == data
     assert str(alist) == f"xxx -> 3 -> 2 -> 1 -> None"
示例#6
0
 def test_insert_at_head__non_empty_list__ok(self):
     alist = LinkedList(Node("1"))
     assert alist.is_empty() is False
     assert alist.get_head() is not None
     data = 2
     alist.insert_at_head(data)
     assert alist.is_empty() is False
     assert alist.get_head().data == data
     assert str(alist) == f"{data} -> 1 -> None"
示例#7
0
 def test_insert_at_head__empty_list__ok(self):
     alist = LinkedList()
     assert alist.is_empty() is True
     assert alist.get_head() is None
     data = 1
     alist.insert_at_head(data)
     assert alist.is_empty() is False
     assert alist.get_head().data == data
     assert str(alist) == f"{data} -> None"
示例#8
0
 def test_delete_at_head__empty_list_with_many_elements__ok(self):
     alist = LinkedList()
     for i in range(1, 4):
         alist.insert_at_head(i)
     assert str(alist) == "3 -> 2 -> 1 -> None"
     assert alist.get_head().data == 3
     alist.delete_at_head()
     assert str(alist) == "2 -> 1 -> None"
     assert alist.get_head().data == 2