Esempio n. 1
0
    public void DetachTail()
    {
        // setup
        var deque = new CacheDeque <int>();
        var queue = new Queue <int>();

        var val = GetRandomArray(iterations);

        // act
        // insert 10 in the front
        for (var i = 0; i < iterations; i++)
        {
            var newVal = new DequeElem <int>(val[i]);
            deque.PushHead(newVal);
            queue.Enqueue(val[i]);
        }

        // act & assert
        for (var i = 0; i < iterations / 2; i++)
        {
            var det  = deque.DetachTail().item;
            var det2 = queue.Dequeue();
            Assert.Equal(det2, det);
        }

        Assert.True(DequeQueueWereEqual(deque, queue));

        Assert.Throws <ApplicationException>(() => deque.DetachTail());
    }
Esempio n. 2
0
    public void PushHead()
    {
        // setup
        var deque = new CacheDeque <int>();
        var queue = new Queue <int>();

        var val = GetRandomArray(iterations);

        // act & assert
        // insert 10 in the front
        Assert.Equal(0, deque.Count);

        for (var i = 0; i < iterations; i++)
        {
            var newVal = new DequeElem <int>(val[i]);
            deque.PushHead(newVal);
            queue.Enqueue(val[i]);

            Assert.Equal(i + 1, deque.Count);
        }

        Assert.True(DequeQueueWereEqual(deque, queue));
    }