Exemple #1
0
 public void TestGetFromEmptyQueueAfterClear()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue("a");
     q.Enqueue("b");
     q.Clear();
     q.Dequeue();
 }
        public void TestGetFromEmptyQueueAfterClear()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Enqueue("a");
            q.Enqueue("b");
            q.Clear();
            q.Dequeue();
        }
 protected void CloseQuoteSocket()
 {
     if (quotePacketQueue != null)
     {
         quotePacketQueue.Clear();
     }
     if (quoteSocket != null)
     {
         quoteSocket.Dispose();
     }
 }
Exemple #4
0
 protected void CloseFIXSocket()
 {
     if (fixPacketQueue != null && fixPacketQueue.Count > 0)
     {
         fixPacketQueue.Clear();
     }
     if (fixSocket != null)
     {
         fixSocket.Dispose();
     }
 }
Exemple #5
0
 public void TestGetFromEmptyQueueAfterClear()
 {
     FastQueue<string> q = new FastQueue<string>();
     q.Enqueue( "a" );
     q.Enqueue( "b" );
     q.Clear();
     string msg = null;
     try
     {
         q.Dequeue();
     }
     catch ( IndexOutOfRangeException nsee )
     {
         msg = nsee.Message;
     }
     string expecting = "queue index 0 > last index -1";
     string found = msg;
     Assert.AreEqual( expecting, found );
 }
Exemple #6
0
        public void TestGetFromEmptyQueueAfterClear()
        {
            FastQueue <string> q = new FastQueue <string>();

            q.Enqueue("a");
            q.Enqueue("b");
            q.Clear();
            string msg = null;

            try
            {
                q.Dequeue();
            }
            catch (InvalidOperationException nsee)
            {
                msg = nsee.Message;
            }
            string expecting = "queue index 0 > last index -1";
            string found     = msg;

            Assert.AreEqual(expecting, found);
        }
Exemple #7
0
        public void EmptyConstructorAndEmptyQueueTest()
        {
            FastQueue <int> q = new FastQueue <int>();

            Assert.IsTrue(q.Count == 0, "Count is non-zero!");
            Assert.IsTrue(!q.Any(), "FastQueue has a member when empty!");

            q.Clear();

            Assert.IsTrue(q.Count() == 0, "Count is non-zero!");
            Assert.IsTrue(!q.Any(), "FastQueue has a member when empty!");

            bool looped = false;

            foreach (int i in q)
            {
                looped = true;
            }
            Assert.IsTrue(!looped, "FastQueue looped even though empty!");

            Assert.ThrowsException <InvalidOperationException>(() => q.Dequeue(), "FastQueue didn't throw InvalidOperationException on empty Dequeue()");

            Assert.ThrowsException <InvalidOperationException>(() => q.Peek(), "FastQueue didn't throw InvalidOperationException on empty Peek()");
        }
Exemple #8
0
        public void EnqueuePerformanceTest()
        {
            Stopwatch  listWatch = Stopwatch.StartNew();
            List <int> list      = new List <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                list.Add(i);
                //list.TrimExcess();
            }
            listWatch.Stop();
            float listElapsedTime = listWatch.ElapsedTicks;

            list.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch   qWatch = Stopwatch.StartNew();
            Queue <int> q      = new Queue <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                q.Enqueue(i);
                //q.TrimExcess();
            }
            qWatch.Stop();
            float qElapsedTime = qWatch.ElapsedTicks;

            q.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch        linkedWatch = Stopwatch.StartNew();
            LinkedList <int> linked      = new LinkedList <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                linked.AddLast(i);
            }
            linkedWatch.Stop();
            float linkedElapedTime = linkedWatch.ElapsedTicks;

            linked.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Stopwatch       fqWatch = Stopwatch.StartNew();
            FastQueue <int> fq      = new FastQueue <int>();

            for (int i = 0; i <= maxNumber; i++)
            {
                fq.Enqueue(i);
            }
            fqWatch.Stop();
            float fqElapsedTime = fqWatch.ElapsedTicks;

            fq.Clear();

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Assert.IsTrue(listElapsedTime > fqElapsedTime, "list is faster than FastQueue! {0} to {1}", listElapsedTime, fqElapsedTime);
            Assert.IsTrue(qElapsedTime > fqElapsedTime, "q is faster than FastQueue! {0} to {1}", qElapsedTime, fqElapsedTime);
            Assert.IsTrue(linkedElapedTime > fqElapsedTime, "linked list is faster than FastQueue! {0} to {1}", linkedElapedTime, fqElapsedTime);
        }