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);
        }
Exemplo n.º 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 DeleteMinTest()
        {
            var heap = Enumerable.Range(0, 8).Aggregate(LazyBinomialHeap <int> .Empty, (current, i) => LazyBinomialHeap <int> .Insert(i, current));

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

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

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