public void AdvancingHeadOnEmptyQueueCausesException() { var queue = new LeakyQueue<int>(); Assert.Throws<InvalidOperationException>( delegate() { queue.AdvanceHead(); } ); }
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); }
/// <summary>Initializes a new DirectInput-based game pad</summary> /// <param name="joystick">The DirectInput joystick this instance will query</param> /// <param name="checkAttachedDelegate"> /// Delegate through which the instance can check if the device is attached /// </param> public DirectInputGamePad( Joystick joystick, CheckAttachedDelegate checkAttachedDelegate ) { this.joystick = joystick; this.checkAttachedDelegate = checkAttachedDelegate; this.states = new LeakyQueue<JoystickState>(); this.converter = new DirectInputConverter(this.joystick); // Ensure the leaky queue has created its array ensureSlotAvailable(); }
public void TailCanBeAdvancedWithoutQueueing() { var queue = new LeakyQueue<int>(); for (int index = 0; index < 13; ++index) { queue.EnsureSlotAvailable(); queue.AdvanceTail(); Assert.AreEqual(index + 1, 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 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 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 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 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 PeekInEmptyQueueThrowsException() { var queue = new LeakyQueue<int>(); Assert.Throws<InvalidOperationException>( delegate() { queue.Peek(); } ); }
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 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 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); }
public void DequeuingFromEmptyQueueCausesException() { var queue = new LeakyQueue<int>(); Assert.Throws<InvalidOperationException>( delegate() { queue.Dequeue(); } ); }
public void DefaultConstructorCanBeUsed() { var queue = new LeakyQueue<int>(); Assert.IsNotNull(queue); // nonsense, avoids compiler warning }
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 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 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); }