Ejemplo n.º 1
0
        public void DeleteLotsOfMinsTest()
        {
            const int size   = 1000;
            var       random = new Random(3456);
            var       heap   = ParingHeap <int> .Empty;

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

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

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

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

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

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

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