def test_reverse(self): dll = LinkedList() items = 100 assert dll.is_empty() assert dll.reverse() is None assert dll.is_empty() for i in range(items): assert dll.append(i) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.size == items assert dll.head is not dll.tail assert dll.head.data == 0 assert dll.head.prev is None assert dll.tail.data == items - 1 assert dll.tail.next is None assert dll.reverse() is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.size == items assert dll.head is not dll.tail assert dll.head.data == items - 1 assert dll.head.prev is None assert dll.tail.data == 0 assert dll.tail.next is None match = items - 1 for node in dll: assert node.data == match match -= 1 assert dll.reverse() is None match = 0 for node in dll: assert node.data == match match += 1
def test_remove_not_found(self): dll = LinkedList() assert dll.is_empty() is True assert dll.push(1) is None assert dll.is_empty() is False with pytest.raises(ValueError): dll.remove(2)
def test_remove_single(self): dll = LinkedList() assert dll.is_empty() assert dll.push(1) is None assert dll.size == 1 assert dll.head is dll.tail assert dll.remove(1) is None assert dll.is_empty()
def test_is_empty_2(self): dll = LinkedList() assert dll.head is None assert dll.tail is None assert dll.size == 0 assert dll.append(1) is None assert dll.is_empty() is False
def test_insert_empty(self): dll = LinkedList() assert dll.is_empty() assert dll.insert(0, 0) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is dll.tail assert dll.size == 1
def test_remove_tail(self): dll = LinkedList() items = 2 assert dll.is_empty() for i in range(items): assert dll.append(i) is None assert dll.size == items assert dll.tail is not dll.head assert dll.remove(1) is None assert dll.head is dll.tail assert dll.size == items - 1
def test_clear(self): dll = LinkedList() items = 100 assert dll.is_empty() for i in range(items): assert dll.append(i) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.size == items assert dll.clear() is None assert dll.head is None assert dll.tail is None assert dll.size == 0
def test_extend_iterable_object(self): items = 100 first = LinkedList() second = list(range(items)) assert first.is_empty() assert first.extend(second) is None assert isinstance(first.head, Node) assert isinstance(first.tail, Node) assert first.head is not first.tail assert first.size == len(second) match = 0 for node in first: assert node.data == match match += 1
def test_remove_mid(self): dll = LinkedList() items = 3 assert dll.is_empty() for i in range(items): assert dll.append(i) is None assert dll.size == items assert dll.head is not dll.tail assert dll.remove(1) is None assert dll.head is not dll.tail assert dll.head.data == 0 assert dll.tail.data == 2 assert dll.head.next is dll.tail assert dll.tail.prev is dll.head assert dll.head.prev is None assert dll.tail.next is None assert dll.size == items - 1
def test_extend_another_linked_list_from_empty(self): first = LinkedList() second = LinkedList() items = 100 for i in range(items): assert second.append(i) is None assert first.is_empty() assert second.size == items assert first.extend(second) is None assert isinstance(first.head, Node) assert isinstance(first.tail, Node) assert first.head is not second.head assert first.tail is not second.tail assert first.size == second.size match = 0 for node in first: assert node.data == match match += 1
def test_insert_new_tail(self): dll = LinkedList() assert dll.is_empty() assert dll.push(1) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is dll.tail assert dll.size == 1 assert dll.insert(1, 2) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.head.data == 1 assert dll.tail.data == 2 assert dll.head.next is dll.tail assert dll.head.prev is None assert dll.tail.prev is dll.head assert dll.tail.next is None assert dll.size == 2
def test_insert_new_head_negative_out_of_bounds(self): dll = LinkedList() assert dll.is_empty() assert dll.push(1) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is dll.tail assert dll.size == 1 assert dll.insert(-1000, 2) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.head.data == 2 assert dll.tail.data == 1 assert dll.head.next is dll.tail assert dll.head.prev is None assert dll.tail.prev is dll.head assert dll.tail.next is None assert dll.size == 2
def test_insert_new_tail_out_of_bounds(self): dll = LinkedList() assert dll.is_empty() assert dll.push(0) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is dll.tail assert dll.size == 1 assert dll.insert(1000, 1) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.head.data == 0 assert dll.tail.data == 1 assert dll.head.next is dll.tail assert dll.head.next.data == 1 assert dll.head.prev is None assert dll.tail.prev is dll.head assert dll.tail.prev.data == 0 assert dll.tail.next is None assert dll.size == 2
def test_insert_end_negative(self): dll = LinkedList() assert dll.is_empty() assert dll.append(0) is None assert dll.append(1) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.size == 2 assert dll.insert(-1, 2) is None assert isinstance(dll.head, Node) assert isinstance(dll.tail, Node) assert dll.head is not dll.tail assert dll.head.data == 0 assert dll.tail.data == 1 assert dll.head.next is not dll.tail assert dll.head.next.data == 2 assert dll.head.prev is None assert dll.tail.prev is not dll.head assert dll.tail.prev.data == 2 assert dll.tail.next is None assert dll.size == 3
def test_is_empty(self): dll = LinkedList() assert dll.head is None assert dll.tail is None assert dll.size == 0 assert dll.is_empty() is True
def test_clear_empty(self): dll = LinkedList() assert dll.is_empty() assert dll.clear() is None assert dll.is_empty()