public void TryActionTest()
        {
            var q = new MPSCQueue <int>(16);

            //Inserts 10 items.
            QueueTestSetup.SplitQueue(q);

            //Insert 6 more to fill the queue
            for (int i = 0; i < 6; i++)
            {
                q.TryEnqueue(999);
            }

            Assert.IsFalse(q.TryEnqueue(10));
            Assert.IsTrue(q.TryPeek(out int result));
            Assert.AreEqual(0, result);

            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(q.TryDequeue(out int val));
                Assert.AreEqual(i, val);
            }

            //Empty 6 last items
            for (int i = 0; i < 6; i++)
            {
                Assert.IsTrue(q.TryDequeue(out int val));
            }

            //Empty queue
            Assert.IsFalse(q.TryPeek(out int res));
        }
        public void ClearTest()
        {
            var q = new MPSCQueue <int>(16);

            //Inserts 10 items.
            QueueTestSetup.SplitQueue(q);

            Assert.AreEqual(10, q.Count);
            q.Clear();
            Assert.AreEqual(0, q.Count);

            Assert.IsTrue(q.IsEmpty);
        }
        public void ToArrayTest()
        {
            var q = new SPSCQueue <int>(10);

            QueueTestSetup.SplitQueue(q);

            var arr = q.ToArray();

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, arr[i]);
            }
        }
        public void CopyToTest()
        {
            var q = new MPSCQueue <int>(10);

            QueueTestSetup.SplitQueue(q);

            var arr = new int[q.Count];

            q.CopyTo(arr, 0);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(i, arr[i]);
            }
        }
        public void ExpandTest()
        {
            var q = new MPSCQueue <int>(10);

            QueueTestSetup.SplitQueue(q);

            //Fill buffer to capacity.
            for (int i = 0; i < 6; i++)
            {
                q.TryEnqueue(999);
            }


            //Buffer is full, can no longer insert.
            Assert.IsFalse(q.TryEnqueue(10));
        }
        public void CopyToTest()
        {
            var q = new SPSCQueue <int>(10);

            QueueTestSetup.SplitQueue(q);

            var arr = new int[15];

            q.CopyTo(arr, 5);

            var num = 0;

            for (int i = 5; i < 15; i++)
            {
                Assert.AreEqual(num++, arr[i]);
            }
        }
        public void ExpandTest()
        {
            var q = new ConcurrentQueue <int>(16, false);

            QueueTestSetup.SplitQueue(q);

            // Fill buffer beyond capacity
            for (int i = 0; i < 100;)
            {
                if (q.TryEnqueue(999))
                {
                    i++;
                }
            }


            Assert.AreEqual(110, q.Count);
        }
        public void ClearFixedTest()
        {
            int size = 128; // Power of two.
            var q    = new ConcurrentQueue <int>(size, true);

            //Inserts 10 items.
            QueueTestSetup.SplitQueue(q);

            Assert.AreEqual(10, q.Count);
            Assert.AreEqual(size, q.Capacity);

            q.Clear();

            Assert.AreEqual(0, q.Count);
            // Queue capacity needs to remain unchanged after clear.
            Assert.AreEqual(size, q.Capacity);

            Assert.IsTrue(q.IsEmpty);
        }
        public void IteratorTest()
        {
            var q = new SPSCQueue <int>(10);

            // Wrap tail around
            QueueTestSetup.SplitQueue(q);

            // Iterator should start from the head.
            int num = 0;

            foreach (int i in q)
            {
                Assert.AreEqual(num, i);
                num++;
            }

            // Iterated 10 items
            Assert.AreEqual(10, num);
        }
        public void IteratorTest()
        {
            var q = new MPSCQueue <int>(10);

            // Wrap tail around
            QueueTestSetup.SplitQueue(q);

            // Iterator should start from the head.
            int num      = 0;
            var iterator = q.GetEnumerator();

            while (iterator.MoveNext())
            {
                Assert.AreEqual(num, iterator.Current);
                num++;
            }

            // Iterated 10 items
            Assert.AreEqual(10, num);
        }
        public void IteratorSplitTest()
        {
            var q = new ConcurrentQueue <int>(10, false);

            // Wrap tail around
            QueueTestSetup.SplitQueue(q);

            for (int i = 10; i < 50; i++)
            {
                q.Enqueue(i);
            }

            // Iterator should start from the head.
            int num = 0;

            foreach (int i in q)
            {
                Assert.AreEqual(num, i);
                num++;
            }

            // Iterated 50 items
            Assert.AreEqual(50, num);
        }