Beispiel #1
0
        public void TestMaxHeapInsert()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap();

            heap.Insert(10);
            Assert.AreEqual(10, heap.Root);
        }
Beispiel #2
0
        public void TestMaxHeapResize()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap(2);

            heap.Insert(10);
            heap.Insert(20);
            heap.Insert(30);
            Assert.True(heap.Size > 2);
        }
Beispiel #3
0
        public void TestMaxHeapRemovesRoot()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap();

            heap.Insert(10);
            heap.Insert(20);
            var removed = heap.TryRemoveRoot(out var root);

            Assert.True(removed);
            Assert.AreEqual(20, root);
            Assert.AreEqual(10, heap.Root);
        }
Beispiel #4
0
        public void TestMaxHeapOrderedRemoval()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap();

            var random = new Random(0);

            for (int i = 0; i < 1000; i++)
            {
                heap.Insert(random.Next());
            }

            int last = int.MaxValue;

            while (heap.TryRemoveRoot(out var root))
            {
                Assert.LessOrEqual(root, last);
                last = root;
            }
        }
Beispiel #5
0
        public void TestMaxHeapEmpty()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap();

            Assert.True(heap.IsEmpty);
        }
Beispiel #6
0
 public void TestInvalidMaxHeapSizeThrows()
 {
     Assert.Throws <IndexOutOfRangeException>(() => LockedBinaryHeap <int> .CreateMaxHeap(-1));
 }
Beispiel #7
0
        public void TestMaxHeapRemoveFalseWhenEmpty()
        {
            var heap = LockedBinaryHeap <int> .CreateMaxHeap();

            Assert.False(heap.TryRemoveRoot(out var r));
        }