Beispiel #1
0
        public void Test_NotEmpty_WhenAdding()
        {
            MaxPQ <Int32> pq = new MaxPQ <Int32>(2);

            pq.Add(18);
            pq.Add(2);

            Assert.False(pq.IsEmpty);
            Assert.Equal(2, pq.Count);
        }
Beispiel #2
0
        public void Test_Empty_WhenCleaning()
        {
            MaxPQ <Int32> pq = new MaxPQ <Int32>(1);

            pq.Add(2);
            pq.DeleteMax();

            Assert.True(pq.IsEmpty);
            Assert.Equal(0, pq.Count);
        }
Beispiel #3
0
        public void Test_Add_Max()
        {
            MaxPQ <Int32> pq = new MaxPQ <Int32>(10);

            for (int i = 1; i < 11; i++)
            {
                pq.Add(i);
            }

            Assert.Equal(10, pq.Max());
        }
Beispiel #4
0
        public void Test_Add_DeleteMax_Order()
        {
            MaxPQ <Int32> pq = new MaxPQ <Int32>(10);

            for (int i = 1; i < 11; i++)
            {
                pq.Add(i);
            }

            for (int i = 10; i > 0; i--)
            {
                Assert.Equal(pq.DeleteMax(), i);
            }
        }
        public void TestAdd()
        {
            int[] a = Range(100);
            Shuffle(a);
            MaxPQ <int> pq = new MaxPQ <int>();

            pq.Add(10);
            Assert.AreEqual(10, pq.Peek());
            pq.Add(20);
            Assert.AreEqual(20, pq.Peek());
            for (int i = 0; i < 20; ++i)
            {
                pq.Add(i);
                Assert.AreEqual(i + 3, pq.Count);
                Assert.AreEqual(20, pq.Peek());
            }
            Assert.AreEqual(20, pq.DelMax());
            Assert.AreEqual(19, pq.DelMax());
            foreach (int val in a)
            {
                pq.Add(val);
            }
            Assert.AreEqual(99, pq.Peek());
        }