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

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

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

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

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

            var random = new Random(0);

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

            int last = -1;

            while (heap.TryRemoveRoot(out var root))
            {
                Assert.GreaterOrEqual(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 TestMinHeapRemoveFalseWhenEmpty()
        {
            var heap = LockedBinaryHeap <int> .CreateMinHeap();

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