Beispiel #1
0
        /// <summary>
        ///Peek 的测试
        ///</summary>
        public void PeekTestHelper <ValueT>()
        {
            LockFreeQueue <ValueT> target = new LockFreeQueue <ValueT>(); // TODO: 初始化为适当的值
            ValueT expected = default(ValueT);                            // TODO: 初始化为适当的值
            ValueT actual;

            actual = target.Peek();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("验证此测试方法的正确性。");
        }
Beispiel #2
0
        public void LockFreeQueuePeek()
        {
            var   queue = new LockFreeQueue <int>();
            Int32 t     = 0;

            //We enqueue some items to test
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            //We check that after a peeking we have the correct value but the item
            //is not deleted
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 1);
            Assert.AreEqual(queue.Count, 5);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 2);
            Assert.AreEqual(queue.Count, 4);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 3);
            Assert.AreEqual(queue.Count, 3);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 4);
            Assert.AreEqual(queue.Count, 2);
            queue.DequeueSingle();
            Assert.IsTrue(queue.Peek(ref t));
            Assert.AreEqual(t, 5);
            Assert.AreEqual(queue.Count, 1);
            queue.DequeueSingle();
            Assert.IsFalse(queue.Peek(ref t));
        }