Exemple #1
0
        public void AddTest()
        {
            var heap = new BinomialHeap();

            heap.Add(7);
            heap.Add(5);
            heap.Add(4);
            heap.Add(8);

            const int expectedCount = 4;

            Assert.IsTrue(heap.Count == expectedCount, "Incorrect number of items added");
        }
Exemple #2
0
        public void RemoveTest()
        {
            var heap = new BinomialHeap();

            heap.Add(7);
            heap.Add(5);
            heap.Add(4);
            heap.Add(8);
            heap.Remove(4);

            const int expectedCount = 3;

            Assert.IsTrue(heap.Count == expectedCount, "Incorrect number of items after deletion");
        }
Exemple #3
0
        public void ExtractMinTest()
        {
            var heap = new BinomialHeap();

            heap.Add(7);
            heap.Add(5);
            heap.Add(4);
            heap.Add(8);

            heap.TryExtractMin(out var min);
            const int expectedMin = 4;

            Assert.IsTrue(min == expectedMin, "Extracted the wrong item");
        }
Exemple #4
0
        public static void TestBinomialHeapCreation()
        {
            var heap = new BinomialHeap();

            heap.Add(2);
            Assert.AreEqual(heap.Roots.Count, 1);
            heap.Add(3);
            Assert.AreEqual(heap.Roots.Count, 1);
            heap.Add(1);
            Assert.AreEqual(heap.Roots.Count, 2);
            heap.Add(4);
            Assert.AreEqual(heap.Roots.Count, 1);
            heap.Add(2);
            Assert.AreEqual(heap.Roots.Count, 2);
            heap.Add(5);
            Assert.AreEqual(heap.Roots.Count, 2);
            heap.Add(6);
            Assert.AreEqual(heap.Roots.Count, 3);
            heap.Add(7);
            Assert.AreEqual(heap.Roots.Count, 1);
            Assert.IsNotNull(heap.Roots[3]);
            var max = heap.GetMaximum();

            Assert.AreEqual(max, 7);
        }
Exemple #5
0
        public void DecreaseKeyTest()
        {
            const int newMinKey = 2;

            var heap = new BinomialHeap();

            heap.Add(7);
            heap.Add(5);
            heap.Add(4);
            heap.Add(8);
            heap.DecreaseKey(4, newMinKey);

            heap.TryExtractMin(out var min);

            Assert.IsTrue(min == newMinKey, "The specified key has not changed");
        }