Example #1
0
        public static void TestOverflow()
        {
            // Tests adding elements to full queues
            // Add's documentation claims throwing an IndexOutOfRangeException in this situation

            // Add an element to a prepopulated queue
            int maxSize             = 10;
            PriorityQueue <int?> pq = new IntegerQueueWithSentinel(maxSize, true);

            try
            {
                pq.Add(3);
                Assert.Fail();
            }
            catch (Exception e) when(e.IsIndexOutOfBoundsException())
            {
            }

            // Populate manually
            maxSize = 5;
            pq      = new IntegerQueue(maxSize);
            pq.Add(1);
            pq.Add(4);
            pq.Add(-1);
            pq.Add(0);
            pq.Add(10);

            try
            {
                pq.Add(666);
            }
            catch (Exception e) when(e.IsIndexOutOfBoundsException())
            {
            }
        }
Example #2
0
        public static void TestPrepopulation()
        {
            int maxSize = 10;
            // Populates the internal array
            PriorityQueue <int?> pq = new IntegerQueueWithSentinel(maxSize, true);

            Assert.AreEqual(pq.Top, int.MaxValue);
            Assert.AreEqual(pq.Count, 10);

            // Does not populate it
            pq = new IntegerQueue(maxSize, false);
            Assert.AreEqual(pq.Top, default);
            Assert.AreEqual(pq.Count, 0);
        }