Example #1
0
        public void DeleteLotsOfMinsTest()
        {
            const int size   = 1000;
            var       random = new Random(3456);
            var       heap   = BinomialHeap <int> .Empty;

            for (var i = 0; i < size; i++)
            {
                heap = BinomialHeap <int> .Insert(random.Next(size), heap);
            }

            var last  = 0;
            var count = 0;

            while (!BinomialHeap <int> .IsEmpty(heap))
            {
                var next = BinomialHeap <int> .FindMin(heap);

                heap = BinomialHeap <int> .DeleteMin(heap);

                Assert.IsTrue(last <= next);
                last = next;
                count++;
            }
            Assert.AreEqual(size, count);
        }
Example #2
0
        public void DeleteMinTest()
        {
            var heap = Enumerable.Range(0, 8).Aggregate(BinomialHeap <int> .Empty, (current, i) => BinomialHeap <int> .Insert(i, current));

            heap = BinomialHeap <int> .DeleteMin(heap);

            Assert.AreEqual("[1]; [2, [3]]; [4, [6, [7]], [5]]", DumpHeap(heap));
        }
Example #3
0
        public void DeleteMinEmptyTest()
        {
            var empty = BinomialHeap <int> .Empty;

            AssertThrows <ArgumentNullException>(() => BinomialHeap <int> .DeleteMin(empty));
        }