Beispiel #1
0
        public void ClasPeekTest()
        {
            FixedSizePriorityQueue <float, int> testQ = new FixedSizePriorityQueue <float, int>(10);

            Assert.IsNull(testQ.Peek());

            testQ = new FixedSizePriorityQueue <float, int>(
                new List <KeyValuePair <float, int> >()
            {
                new KeyValuePair <float, int>(-10, 22)
            },
                10);
            Assert.AreEqual(1, testQ.Count);
            Assert.IsNotNull(testQ.Peek());
            Assert.AreEqual(1, testQ.Count);
            Assert.AreEqual(-10, testQ.Peek().Value.Key);
            Assert.AreEqual(22, testQ.Peek().Value.Value);
        }
Beispiel #2
0
        public void ClasEnqueueTest()
        {
            int maxSize = 3;

            FixedSizePriorityQueue <float, int> testQ = new FixedSizePriorityQueue <float, int>(maxSize);

            Assert.IsNull(testQ.Peek());
            Assert.AreEqual(0, testQ.Count);

            float key   = -5;
            int   value = 1;

            testQ.Enqueue(key, value);

            Assert.AreEqual(1, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);

            key   = 10;
            value = 2;

            testQ.Enqueue(key, value);

            Assert.AreEqual(2, testQ.Count);
            Assert.AreEqual(-5, testQ.Peek().Value.Key);
            Assert.AreEqual(1, testQ.Peek().Value.Value);

            //Updates the top of the queue when higher prio elements are added
            key   = -10;
            value = 3;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);

            //When the queue is full, doesn't change its size
            //and doesn't insert a new element with lower prio than top's
            key   = -11;
            value = 4;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(-10, testQ.Peek().Value.Key);
            Assert.AreEqual(3, testQ.Peek().Value.Value);

            //When the queue is full, doesn't change its size
            //and does insert a new element with hiher prio than top's
            key   = -9;
            value = 5;

            testQ.Enqueue(key, value);

            Assert.AreEqual(3, testQ.Count);
            Assert.AreEqual(key, testQ.Peek().Value.Key);
            Assert.AreEqual(value, testQ.Peek().Value.Value);
        }