def test_reverse():
    ll, arr = DoublyLinkedList(), []
    for i in range(ITERS):
        if i != 0:
            ll.insert(0, i)
            arr.insert(0, i)
        ll.reverse()
        arr = arr[::-1]
        assert (ll.to_array() == arr)
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)