Exemplo n.º 1
0
 def test_insert_at_position__empty_list_position_one__ok(self):
     alist = LinkedList()
     data, position = 1, 0
     alist.insert_at_position(data, position)
     assert alist.is_empty() is False
     assert alist.get_head().data == data
     assert str(alist) == f"{data} -> None"
Exemplo n.º 2
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)
Exemplo n.º 3
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"
Exemplo n.º 4
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"