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
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
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"
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"
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
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"
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"
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"
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
def test_get_head__ok(self): node = Node("a") alist = LinkedList(node) assert alist.get_head() == node