예제 #1
0
        public void DelMinTest()
        {
            var heap = new[] { 3, 2, 5, 1 }.Aggregate(LeftistHeap <int> .Empty, (h, x) => LeftistHeap <int> .Insert(x, h));

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

            Assert.AreEqual("3, 2, 5, ", DumpHeap(heap));
            Assert.AreEqual(2, LeftistHeap <int> .FindMin(heap));
        }
예제 #2
0
        public void SingleDeleteMinTest()
        {
            var heap = LeftistHeap <int> .Empty;

            heap = LeftistHeap <int> .Insert(2, heap);

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

            Assert.IsTrue(LeftistHeap <int> .IsEmpty(heap));
        }
예제 #3
0
        public void DeleteLotsOfMinsTest()
        {
            var random = new Random(3456);
            var heap   = LeftistHeap <int> .Empty;

            for (var i = 0; i < 100; i++)
            {
                heap = LeftistHeap <int> .Insert(random.Next(100), heap);
            }
            var last  = 0;
            var count = 0;

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

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

                Assert.IsTrue(last <= next);
                last = next;
                count++;
            }
            Assert.AreEqual(100, count);
        }
예제 #4
0
        public void EmptyDeleteMinTest()
        {
            var heap = LeftistHeap <int> .Empty;

            AssertThrows <ArgumentNullException>(() => LeftistHeap <int> .DeleteMin(heap));
        }