public void TestFairness()
        {
            var fq       = new FairQueue <string>();
            int enqueued = 0;

            fq.Enqueue(1, "11"); ++enqueued;
            fq.Enqueue(1, "12"); ++enqueued;
            fq.Enqueue(1, "13"); ++enqueued;
            fq.Enqueue(1, "14"); ++enqueued;

            fq.Enqueue(2, "21"); ++enqueued;
            fq.Enqueue(2, "22"); ++enqueued;
            fq.Enqueue(2, "23"); ++enqueued;
            fq.Enqueue(2, "24"); ++enqueued;

            fq.Enqueue(3, "31"); ++enqueued;
            fq.Enqueue(3, "32"); ++enqueued;
            fq.Enqueue(3, "33"); ++enqueued;
            fq.Enqueue(3, "34"); ++enqueued;

            int tag, ptag;

            fq.Dequeue(out tag); --enqueued;
            for (int i = 0; i < enqueued; ++i)
            {
                ptag = tag;
                fq.Dequeue(out tag);
                Assert.AreEqual((ptag + 1) % 3, tag % 3, "Incorrect cycling between tags");
            }

            Assert.IsTrue(fq.Empty, "The queue should be empty");
        }
        public void TestDequeue()
        {
            var fq = new FairQueue <string>();

            fq.Enqueue("1");
            var r = fq.Dequeue();

            Assert.IsTrue(fq.Empty, "The queue should be empty");
            Assert.AreEqual("1", r, "Incorrect dequeued value");

            fq.Enqueue("1");
            fq.Enqueue(2, "2");
            fq.Enqueue(2, "3");
            fq.Enqueue(5, "4");
            fq.Enqueue("5");
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            Assert.IsTrue(fq.Empty, "The queue should be empty");

            Assert.Throws(typeof(InvalidOperationException), () => fq.Dequeue(), "Dequeueing from an empty queue should throw an InvalidOperationException");

            int tag;

            fq.Enqueue("1");
            fq.Dequeue(out tag);
            Assert.AreEqual(0, tag, "The queue is supposed to contain only one tag and we got an incorrect value for it");
            fq.Enqueue(42, "1");
            fq.Dequeue(out tag);
            Assert.AreEqual(42, tag, "The queue is supposed to contain only one tag and we got an incorrect value for it");
        }
        public void TestDequeue()
        {
            var fq = new FairQueue<string>();
            fq.Enqueue("1");
            var r = fq.Dequeue();
            Assert.IsTrue(fq.Empty, "The queue should be empty");
            Assert.AreEqual("1", r, "Incorrect dequeued value");

            fq.Enqueue("1");
            fq.Enqueue(2, "2");
            fq.Enqueue(2, "3");
            fq.Enqueue(5, "4");
            fq.Enqueue("5");
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            fq.Dequeue();
            Assert.IsTrue(fq.Empty, "The queue should be empty");

            Assert.Throws(typeof(InvalidOperationException), () => fq.Dequeue(), "Dequeueing from an empty queue should throw an InvalidOperationException");

            int tag;
            fq.Enqueue("1");
            fq.Dequeue(out tag);
            Assert.AreEqual(0, tag, "The queue is supposed to contain only one tag and we got an incorrect value for it");
            fq.Enqueue(42, "1");
            fq.Dequeue(out tag);
            Assert.AreEqual(42, tag, "The queue is supposed to contain only one tag and we got an incorrect value for it");
        }
        public void TestFairness()
        {
            var fq = new FairQueue<string>();
            int enqueued = 0;
            fq.Enqueue(1, "11"); ++enqueued;
            fq.Enqueue(1, "12"); ++enqueued;
            fq.Enqueue(1, "13"); ++enqueued;
            fq.Enqueue(1, "14"); ++enqueued;

            fq.Enqueue(2, "21"); ++enqueued;
            fq.Enqueue(2, "22"); ++enqueued;
            fq.Enqueue(2, "23"); ++enqueued;
            fq.Enqueue(2, "24"); ++enqueued;

            fq.Enqueue(3, "31"); ++enqueued;
            fq.Enqueue(3, "32"); ++enqueued;
            fq.Enqueue(3, "33"); ++enqueued;
            fq.Enqueue(3, "34"); ++enqueued;

            int tag, ptag;
            fq.Dequeue(out tag); --enqueued;
            for (int i = 0; i < enqueued; ++i)
            {
                ptag = tag;
                fq.Dequeue(out tag);
                Assert.AreEqual((ptag + 1) % 3, tag % 3, "Incorrect cycling between tags");
            }

            Assert.IsTrue(fq.Empty, "The queue should be empty");
        }