예제 #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);
        }
예제 #2
0
        public void InsertTest3()
        {
            var heap1 = Enumerable.Range(0, 3).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current));
            var heap  = ParingHeap <int> .Insert(3, heap1);

            Assert.AreEqual("[0: [3][2][1]]", DumpHeap(heap));
        }
예제 #3
0
        public void InsertTest1()
        {
            var empty = ParingHeap <int> .Empty;
            var heap  = ParingHeap <int> .Insert(0, empty);

            Assert.AreEqual("[0]", DumpHeap(heap));
        }
예제 #4
0
        public void EmptyTest()
        {
            var empty = ParingHeap <int> .Empty;

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

            var heap = ParingHeap <int> .Insert(3, empty);

            Assert.IsFalse(ParingHeap <int> .IsEmpty(heap));
        }
예제 #5
0
        public void MergeTest3()
        {
            var heap1 = Enumerable.Range(0, 4).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current));
            var heap2 = Enumerable.Range(10, 3).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current));
            var heap  = ParingHeap <int> .Merge(heap1, heap2);

            Assert.AreEqual("[0: [10: [12][11]][3][2][1]]", DumpHeap(heap));
        }
예제 #6
0
        public void MergeTest2()
        {
            var empty = ParingHeap <int> .Empty;
            var heap2 = Enumerable.Range(0, 8).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current));
            var heap  = ParingHeap <int> .Merge(empty, heap2);

            Assert.AreSame(heap2, heap);
        }
예제 #7
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));
        }
예제 #8
0
        public void FindMinTest()
        {
            var heap = Enumerable.Range(0, 8).Aggregate(ParingHeap <int> .Empty, (current, i) => ParingHeap <int> .Insert(i, current));
            var min  = ParingHeap <int> .FindMin(heap);

            Assert.AreEqual(0, min);
        }