def test_pop_empty(self): dll = LinkedList() assert dll.head is None assert dll.tail is None assert dll.size == 0 with pytest.raises(IndexError): dll.pop()
def test_pop_out_of_range_negative(self): dll = LinkedList() assert dll.head is None assert dll.tail is None assert dll.size == 0 assert dll.push(1) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.size == 1 with pytest.raises(IndexError): dll.pop(-2)
def test_pop_2nd_negative(self): dll = LinkedList() items = 100 assert dll.head is None assert dll.tail is None assert dll.size == 0 for i in range(items - 1, -1, -1): assert dll.push(i) is None assert isinstance(dll.head, Node) assert isinstance(dll.head.next, Node) assert dll.head.prev is None assert isinstance(dll.tail, Node) assert isinstance(dll.tail.prev, Node) assert dll.tail.next is None assert dll.size == items for j in range(items - 2, 0, -1): second = dll.pop(-2) assert isinstance(second, Node) assert second.next is None assert second.prev is None assert second.data == j assert isinstance(dll.head, Node) assert isinstance(dll.head.next, Node) assert dll.head.prev is None assert isinstance(dll.tail, Node) assert isinstance(dll.tail.prev, Node) assert dll.tail.next is None assert dll.head.data == 0 assert dll.tail.data == items - 1 assert dll.size == 2
def test_pop_tails_negative(self): dll = LinkedList() items = 100 assert dll.head is None assert dll.tail is None assert dll.size == 0 for i in range(items - 1, -1, -1): assert dll.push(i) is None assert isinstance(dll.head, Node) assert isinstance(dll.head.next, Node) assert dll.head.prev is None assert isinstance(dll.tail, Node) assert isinstance(dll.tail.prev, Node) assert dll.tail.next is None assert dll.size == items for j in range(items - 1, -1, -1): assert isinstance(dll.tail, Node) tail = dll.pop(-1) assert isinstance(tail, Node) assert tail.data == j assert tail.next == None assert dll.size == items - (items - j) assert dll.head is None assert dll.tail is None assert dll.size == 0
def test_append_multiple(self): dll = LinkedList() items = 100 assert dll.head is None assert dll.tail is None assert dll.size == 0 for i in range(items): assert dll.append(i) is None assert dll.size == i + 1 assert dll.tail.data == i assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.size == items for j in range(items): assert dll.pop().data == j assert dll.head is None assert dll.tail is None assert dll.size == 0
def test_pop_single_negative(self): dll = LinkedList() assert dll.head is None assert dll.tail is None assert dll.size == 0 assert dll.push(1) is None assert isinstance(dll.head, Node) assert dll.head.next is None assert dll.head.prev is None assert isinstance(dll.tail, Node) assert dll.tail.next is None assert dll.tail.prev is None assert dll.head.data == dll.tail.data assert dll.size == 1 single = dll.pop(-1) assert isinstance(single, Node) assert single.data == 1 assert single.next is None assert single.prev is None assert dll.head is None assert dll.tail is None assert dll.size == 0
def test_pop_heads(self): dll = LinkedList() items = 100 assert dll.head is None assert dll.tail is None assert dll.size == 0 for i in range(items): assert dll.push(i) is None assert isinstance(dll.head, Node) assert isinstance(dll.head.next, Node) assert dll.head.prev is None assert isinstance(dll.tail, Node) assert isinstance(dll.tail.prev, Node) assert dll.tail.next is None assert dll.size == items for j in range(items - 1, -1, -1): assert isinstance(dll.head, Node) head = dll.pop() assert isinstance(head, Node) assert head.data == j assert dll.size == items - (items - j) assert dll.head is None assert dll.tail is None assert dll.size == 0