Esempio n. 1
0
        public static void TestStress()
        {
            int atLeast             = 1000000;
            int maxSize             = AtLeast(atLeast);
            PriorityQueue <int?> pq = new IntegerQueue(maxSize);

            // Add a lot of elements
            for (int i = 0; i < maxSize; i++)
            {
                pq.Add(Random().Next());
            }

            // Pop some of them
            while (pq.Size() > atLeast / 2)
            {
                pq.Pop();
            }

            // Add some more
            while (pq.Size() < (atLeast * 3) / 4)
            {
                pq.Add(Random().Next());
            }

            PopAndTestElements(pq);

            Assert.AreEqual(pq.Size(), 0);

            // We fill it again
            for (int i = 0; 2 * i < maxSize; i++)
            {
                pq.Add(Random().Next());
            }

            Assert.AreEqual(pq.Size(), (maxSize + 1) / 2);
            pq.Clear();
            Assert.AreEqual(pq.Size(), 0);

            // One last time
            for (int i = 0; 2 * i < maxSize; i++)
            {
                pq.Add(Random().Next());
            }

            PopAndTestElements(pq);
            Assert.AreEqual(pq.Size(), 0);
        }
Esempio n. 2
0
        public static void Benchmarks()
        {
            if (!VERBOSE)
            {
                Assert.Fail("Turn VERBOSE on or otherwise you won't see the results.");
            }

            int maxSize             = AtLeast(100000);
            PriorityQueue <int?> pq = new IntegerQueue(maxSize);

            int?[] elements = new int?[maxSize];

            for (int i = 0; i < maxSize; i++)
            {
                elements[i] = Random().Next();
            }

            System.Console.WriteLine("Random list of elements...");

            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();

            System.Console.WriteLine("\nSorted list of elements...");

            pq = new IntegerQueue(maxSize);
            ArrayUtil.IntroSort(elements, new Less());
            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();

            System.Console.WriteLine("\nReverse sorted list of elements...");

            pq = new IntegerQueue(maxSize);
            ArrayUtil.IntroSort(elements, new Greater());
            TimedAddAndPop <int?>(pq, elements);
            pq.Clear();
        }
Esempio n. 3
0
		public virtual void  TestClear()
		{
			PriorityQueue pq = new IntegerQueue(3);
			pq.Put((System.Object) 2);
			pq.Put((System.Object) 3);
			pq.Put((System.Object) 1);
			Assert.AreEqual(3, pq.Size());
			pq.Clear();
			Assert.AreEqual(0, pq.Size());
		}