public void ExtractMinimum_SingleElement_ReturnsElement() { var heap = new BinaryHeap <int>(); heap.Insert(42); Assert.That(heap.ExtractMinimum(), Is.EqualTo(42)); }
public void ExtractMinimum_SingleElement_RemovesElement() { var heap = new BinaryHeap <int>(); heap.Insert(0); heap.ExtractMinimum(); Assert.That(heap.Count, Is.Zero); Assert.That(() => heap.Minimum, Throws.InvalidOperationException); }
public void ExtractMinimum_ManyElements_CanSortSequence(params int[] values) { var heap = new BinaryHeap <int>(); foreach (var value in values) { heap.Insert(value); } var sorted = new List <int>(); while (heap.Count > 0) { sorted.Add(heap.ExtractMinimum()); } Assert.That(sorted, Is.EqualTo(values.OrderBy(x => x).ToList())); }
public void ExtractMinimum_Empty_Throws() { var heap = new BinaryHeap <int>(); Assert.That(() => heap.ExtractMinimum(), Throws.InvalidOperationException); }