public void PeekDoesNotDequeueItem() { var queue = new LeakyQueue <int>(); queue.Enqueue(12); queue.Enqueue(34); Assert.AreEqual(12, queue.Peek()); Assert.AreEqual(12, queue.Peek()); }
public void QueueHeadCanBeAdvanced() { var queue = new LeakyQueue <int>(); queue.Enqueue(12); queue.Enqueue(34); Assert.AreEqual(12, queue.Peek()); queue.AdvanceHead(); Assert.AreEqual(34, queue.Peek()); }
public void CountPropertyMatchesNumberOfContainedItems() { var queue = new LeakyQueue <int>(); for (int index = 0; index < 42; ++index) { queue.Enqueue(index); Assert.AreEqual(index + 1, queue.Count); } }
public void CapacityCanBePassedToConstructor() { var queue = new LeakyQueue <int>(123); int[] oldArray = queue.Items; for (int index = 0; index < 123; ++index) { queue.Enqueue(index); } Assert.AreSame(oldArray, queue.Items); }
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 QueueBecomesEmptyAfterCallingClear() { var queue = new LeakyQueue <int>(); for (int index = 0; index < 14; ++index) { queue.Enqueue(index); } Assert.AreEqual(14, queue.Count); queue.Clear(); Assert.AreEqual(0, queue.Count); }
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 QueueCanBeConvertedIntoArray() { var queue = new LeakyQueue <int>(); for (int index = 0; index < 4; ++index) { queue.Enqueue(index); } Assert.AreEqual( new int[] { 0, 1, 2, 3 }, queue.ToArray() ); }
public void ContainsMethodFindsNullItems() { var queue = new LeakyQueue <object>(); Assert.IsFalse(queue.Contains(109)); for (int index = 0; index < 12; ++index) { queue.Enqueue(new object()); } Assert.IsFalse(queue.Contains(null)); queue.Enqueue(null); Assert.IsTrue(queue.Contains(null)); for (int index = 0; index < 13; ++index) { queue.Enqueue(new object()); } Assert.IsTrue(queue.Contains(null)); }
public void ContainsMethodFindsSearchedItem() { var queue = new LeakyQueue <int>(); Assert.IsFalse(queue.Contains(109)); for (int index = 0; index < 12; ++index) { queue.Enqueue(index); } Assert.IsFalse(queue.Contains(109)); queue.Enqueue(109); Assert.IsTrue(queue.Contains(109)); for (int index = 0; index < 13; ++index) { queue.Enqueue(index); } Assert.IsTrue(queue.Contains(109)); }
public void QueueCanEnsureCapacityForOneMoreSlot() { var queue = new LeakyQueue <int>(); // Make sure the queue is filled to capacity. It is a valid implementation // to increase capacity in advance, so we just take the initial capacity // and make sure to fill up to that. The queue may have increased capacity already. int capacity = queue.Items.Length; while (queue.Count < capacity) { queue.Enqueue(123); } queue.EnsureSlotAvailable(); Assert.Greater(queue.Items.Length, queue.Count); }
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); }