Example #1
0
 def test_delete__empty_list__ok(self):
     alist = LinkedList()
     assert alist.is_empty() is True
     assert alist.get_head() is None
     alist.delete(10)
     assert alist.is_empty() is True
     assert alist.get_head() is None
Example #2
0
 def test_insert_at_tail__empty_list__ok(self):
     alist = LinkedList()
     assert alist.is_empty() is True
     assert alist.get_head() is None
     data = 1
     alist.insert_at_tail(data)
     assert alist.is_empty() is False
     assert alist.get_head().data == data
     assert str(alist) == f"{data} -> None"
Example #3
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"
Example #4
0
 def test_insert_at_tail__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_tail(data)
     assert alist.is_empty() is False
     assert str(alist) == f"1 -> {data} -> None"
     data = 3
     alist.insert_at_tail(data)
     assert alist.is_empty() is False
     assert str(alist) == f"1 -> 2 -> {data} -> None"
Example #5
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"
Example #6
0
 def test_delete_at_head__non_empty_list_with_one_element__ok(self):
     alist = LinkedList(Node(1))
     assert str(alist) == "1 -> None"
     assert alist.get_head().data == 1
     alist.delete_at_head()
     assert alist.is_empty() is True
     assert alist.get_head() is None
Example #7
0
 def test_delete__non_empty_list_single_value_exists__ok(self):
     alist = LinkedList(Node(1))
     assert str(alist) == "1 -> None"
     alist.delete(1)
     assert alist.is_empty() is True
     assert alist.get_head() is None
Example #8
0
 def test_is_empty__empty_list__ok(self):
     alist = LinkedList()
     node = Node("a")
     blist = LinkedList(node)
     assert alist.is_empty() is True
     assert blist.is_empty() is False
Example #9
0
 def test_search__empty_list__return_false(self):
     alist = LinkedList()
     assert alist.is_empty() is True
     assert alist.search(1) is False