public void TestMaxHeapInsert() { var heap = LockedBinaryHeap <int> .CreateMaxHeap(); heap.Insert(10); Assert.AreEqual(10, heap.Root); }
public void TestMaxHeapResize() { var heap = LockedBinaryHeap <int> .CreateMaxHeap(2); heap.Insert(10); heap.Insert(20); heap.Insert(30); Assert.True(heap.Size > 2); }
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); }
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; } }
public void TestMaxHeapEmpty() { var heap = LockedBinaryHeap <int> .CreateMaxHeap(); Assert.True(heap.IsEmpty); }
public void TestInvalidMaxHeapSizeThrows() { Assert.Throws <IndexOutOfRangeException>(() => LockedBinaryHeap <int> .CreateMaxHeap(-1)); }
public void TestMaxHeapRemoveFalseWhenEmpty() { var heap = LockedBinaryHeap <int> .CreateMaxHeap(); Assert.False(heap.TryRemoveRoot(out var r)); }