コード例 #1
0
        public void AdvancingHeadOnEmptyQueueCausesException()
        {
            var queue = new LeakyQueue<int>();

              Assert.Throws<InvalidOperationException>(
            delegate() { queue.AdvanceHead(); }
              );
        }
コード例 #2
0
 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);
 }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
        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);
              }
        }
コード例 #5
0
        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());
              }
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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()
              );
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        public void PeekInEmptyQueueThrowsException()
        {
            var queue = new LeakyQueue<int>();

              Assert.Throws<InvalidOperationException>(
            delegate() { queue.Peek(); }
              );
        }
コード例 #11
0
        public void PeekDoesNotDequeueItem()
        {
            var queue = new LeakyQueue<int>();
              queue.Enqueue(12);
              queue.Enqueue(34);

              Assert.AreEqual(12, queue.Peek());
              Assert.AreEqual(12, queue.Peek());
        }
コード例 #12
0
        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()
              );
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public void DequeuingFromEmptyQueueCausesException()
        {
            var queue = new LeakyQueue<int>();

              Assert.Throws<InvalidOperationException>(
            delegate() { queue.Dequeue(); }
              );
        }
コード例 #15
0
 public void DefaultConstructorCanBeUsed()
 {
     var queue = new LeakyQueue<int>();
       Assert.IsNotNull(queue); // nonsense, avoids compiler warning
 }
コード例 #16
0
        public void CountPropertyMatchesNumberOfContainedItems()
        {
            var queue = new LeakyQueue<int>();
              for (int index = 0; index < 42; ++index) {
            queue.Enqueue(index);

            Assert.AreEqual(index + 1, queue.Count);
              }
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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);
        }