public void DeleteLotsOfMinsTest()
        {
            const int size   = 1000;
            var       random = new Random(3456);
            var       heap   = LazyBinomialHeap <int> .Empty;

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

            var last  = 0;
            var count = 0;

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

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

                Assert.IsTrue(last <= next);
                last = next;
                count++;
            }

            Assert.AreEqual(size, count);
        }
Пример #2
0
            public void RunModel(IModel obj)
            {
                var heap = LazyBinomialHeap <int> .Empty;

                for (var i = 0; i < Size; i++)
                {
                    var val = _random.Next(Size);
                    heap = LazyBinomialHeap <int> .Insert(val, heap);

                    Assert.IsFalse(heap.IsValueCreated);
                }

                Console.WriteLine(LazyBinomialHeapTests.DumpHeap(heap, true));

                var last  = 0;
                var count = 0;

                while (!LazyBinomialHeap <int> .IsEmpty(heap))
                {
                    Assert.IsTrue(heap.IsValueCreated);

                    var next = LazyBinomialHeap <int> .FindMin(heap);

                    Assert.IsTrue(last <= next);
                    last = next;

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

                    count++;
                }

                Assert.AreEqual(Size, count);
            }
        public void EmptyTest()
        {
            var empty = LazyBinomialHeap <int> .Empty;

            Assert.IsTrue(LazyBinomialHeap <int> .IsEmpty(empty));

            var heap = LazyBinomialHeap <int> .Insert(1, empty);

            Assert.IsFalse(LazyBinomialHeap <int> .IsEmpty(heap));
        }