public void DequeuingFromEmptyQueueCausesException() { var queue = new LeakyQueue <int>(); Assert.Throws <InvalidOperationException>( delegate() { queue.Dequeue(); } ); }
public void InternallyWrappedQueueCanBeConvertedIntoArray() { var queue = new LeakyQueue <int>(); for (int index = 0; index < 4; ++index) { queue.Enqueue(index); } queue.Dequeue(); queue.Dequeue(); for (int index = 4; index < 6; ++index) { queue.Enqueue(index); } Assert.AreEqual( new int[] { 2, 3, 4, 5 }, queue.ToArray() ); }
public void QueueReturnsItemsInFifoOrder() { var queue = new LeakyQueue <int>(); for (int index = 0; index < 15; ++index) { queue.Enqueue(index); } for (int index = 0; index < 15; ++index) { Assert.AreEqual(index, queue.Dequeue()); } }
public void HeadAndTailIndexCanBeQueried() { var queue = new LeakyQueue <int>(); for (int run = 0; run < 4; ++run) { for (int index = 0; index < 16; ++index) { queue.Enqueue(index); } for (int index = 0; index < 8; ++index) { queue.Dequeue(); } } // We can't make any assumptions about how the queue works, thus: Assert.GreaterOrEqual(queue.HeadIndex, 0); Assert.Less(queue.HeadIndex, queue.Items.Length); Assert.GreaterOrEqual(queue.TailIndex, 0); Assert.Less(queue.TailIndex, queue.Items.Length); }