def test_peek_invalid():
    ll = DoublyLinkedList()
    with pytest.raises(AssertionError):
        ll.peek(0)
    ll.insert(0, 0)
    for i in range(-ITERS // 2, ITERS // 2 + 1):
        if i == 0: continue
        with pytest.raises(AssertionError):
            ll.peek(i)
def test_random_ops():
    ll, arr = DoublyLinkedList(), []
    for i in range(ITERS):
        index = random.randrange(i + 1)
        data = random.randrange(MAX_VAL)
        ll.insert(index, data)
        arr.insert(index, data)
        assert (ll.to_array() == arr)
    for i in range(ITERS):
        index = random.randrange(ITERS)
        actual = ll.peek(index)
        expected = arr[index]
        assert (actual == expected)
    for i in range(ITERS, 0, -1):
        index = random.randrange(i)
        actual = arr.pop(index)
        expected = ll.pop(index)
        assert (actual == expected)
        assert (ll.to_array() == arr)
    assert (ll.is_empty() and len(arr) == 0)