Пример #1
0
        public void TestAddsKeptInSequence()
        {
            DelayQueue<uint> dq = new DelayQueue<uint>();
            dq.Enqueue(0, 1);
            dq.Enqueue(1, 1);
            dq.Enqueue(2, 1);
            dq.Enqueue(3, 1);
            Assert.AreEqual(1, dq.MaximumDelay);
            Assert.IsFalse(dq.Dequeue(0, null));
            uint lastSeen = 0;
            dq.Enqueue(4, 1);
            Assert.AreEqual(1, dq.MaximumDelay);
            Assert.IsTrue(dq.Dequeue(1, v => Assert.AreEqual(lastSeen++, v)));

            Assert.AreEqual(0, dq.Count);
            Assert.AreEqual(0, dq.MaximumDelay);
        }
Пример #2
0
 public void TestReversedAdds()
 {
     DelayQueue<uint> dq = new DelayQueue<uint>();
     Assert.AreEqual(0, dq.Count);
     for (uint i = 0; i < 10; i++)
     {
         dq.Enqueue(10 - i - 1, 10 - i);
         Assert.AreEqual(i + 1, dq.Count);
         Assert.AreEqual(10, dq.MaximumDelay);   // MaxDelay shouldn't change
     }
     Assert.IsFalse(dq.Dequeue(0, null));    // nothing at time 0
     for (uint i = 0; i < 10; i++)
     {
         Assert.AreEqual(10 - i, dq.Count);
         Assert.AreEqual(10 - i , dq.MaximumDelay);
         bool dequeued = dq.Dequeue(1, e => Assert.AreEqual(i, e));
         Assert.IsTrue(dequeued);
         Assert.AreEqual(10 - (i + 1), dq.Count);
         Assert.AreEqual(10 - i - 1, dq.MaximumDelay);
         Assert.IsFalse(dq.Dequeue(0, null));
     }
     Assert.AreEqual(0, dq.Count);
     Assert.AreEqual(0, dq.MaximumDelay);
 }
Пример #3
0
        public void TestSequentialAdds()
        {
            DelayQueue<uint> dq = new DelayQueue<uint>();
            Assert.AreEqual(0, dq.Count);
            for (uint i = 0; i < 10; i++)
            {
                dq.Enqueue(i, i + 1);
                Assert.AreEqual(i + 1, dq.Count);
                Assert.AreEqual(i + 1, dq.MaximumDelay);
            }

            Assert.IsFalse(dq.Dequeue(0, null));    // nothing at time 0
            for (uint i = 0; i < 10; i++)
            {
                uint expected = i;
                Assert.AreEqual(10 - i, dq.Count);
                Assert.AreEqual(10 - i, dq.MaximumDelay);
                bool dequeued = dq.Dequeue(1, e => Assert.AreEqual(expected, e));
                Assert.IsTrue(dequeued);
                Assert.AreEqual(10 - (i + 1), dq.Count);
                Assert.AreEqual(10 - (i + 1), dq.MaximumDelay);
                Assert.IsFalse(dq.Dequeue(0, null));
            }
            Assert.AreEqual(0, dq.Count);
            Assert.AreEqual(0, dq.MaximumDelay);
        }
Пример #4
0
        public void TestSequentialAddsButUnequalRemoved()
        {
            DelayQueue<uint> dq = new DelayQueue<uint>();
            Assert.AreEqual(0, dq.Count);
            Assert.AreEqual(0, dq.MaximumDelay);
            for (uint i = 0; i < 5; i++)
            {
                dq.Enqueue(2 * i, i + 1);
                dq.Enqueue(2 * i + 1, i + 1);
                Assert.AreEqual(2 * (i + 1), dq.Count);
                Assert.AreEqual(i + 1, dq.MaximumDelay);
            }

            Assert.IsFalse(dq.Dequeue(0, null));    // nothing at time 0
            uint lastCount = 0;
            for (uint i = 0; i < 5; i++)
            {
                Assert.AreEqual(10 - (2 * i), dq.Count);
                Assert.AreEqual(5 - i, dq.MaximumDelay);
                bool dequeued = dq.Dequeue(1, e => Assert.AreEqual(lastCount++, e));
                Assert.IsTrue(dequeued);
                Assert.AreEqual(10 - 2 * (i + 1), dq.Count);
                Assert.AreEqual(5 - i - 1, dq.MaximumDelay);
                Assert.IsFalse(dq.Dequeue(0, null));
            }
            Assert.AreEqual(0, dq.Count);
        }