def test_size(): linked_list = DoublyLinkedList() assert linked_list.size() == 0 linked_list.append(1) assert linked_list.size() == 1 assert get_multi_node_list().size() == 4
def test_append(): doubly_linked_list = DoublyLinkedList() doubly_linked_list.append(3) doubly_linked_list.append(4) assert doubly_linked_list.size() == 2 assert doubly_linked_list.get(0) == 3 assert doubly_linked_list.get(1) == 4
def get_multi_node_list() -> DoublyLinkedList: multi_node_list = DoublyLinkedList() multi_node_list.append(5) multi_node_list.append(2) multi_node_list.append(4) multi_node_list.append(1) return multi_node_list
class QueueLinkedList(Generic[T]): """ Queue backed by a doubly linked list """ def __init__(self): self.linked_list = DoublyLinkedList() def __len__(self): return self.linked_list.size() # O(1) def dequeue(self) -> T: return self.linked_list.remove(0) # O(1) def enqueue(self, element: T): self.linked_list.append(element)
def test_init(): linked_list = DoublyLinkedList() linked_list.append(3) assert linked_list.size() == 1 assert linked_list.get(0) == 3
def test_append_empty(): doubly_linked_list = DoublyLinkedList() doubly_linked_list.append(1) assert doubly_linked_list.size() == 1 assert doubly_linked_list.get(0) == 1