public void Minimum_SingleElement_ReturnsElement() { var heap = new BinaryHeap <int>(); heap.Insert(42); Assert.That(heap.Minimum, Is.EqualTo(42)); }
public void Insert_Empty_CountIsOne() { var heap = new BinaryHeap <int>(); heap.Insert(0); Assert.That(heap.Count, Is.EqualTo(1)); }
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 Minimum_ManyElements_IsCorrect(params int[] values) { var heap = new BinaryHeap <int>(); foreach (var value in values) { heap.Insert(value); } Assert.That(heap.Minimum, Is.EqualTo(values.Min())); }
public void Insert_MultipleTimesIntoEmpty_CountIsCorrect(int size) { var heap = new BinaryHeap <int>(); for (var i = 0; i < size; i++) { heap.Insert(0); } Assert.That(heap.Count, Is.EqualTo(size)); }
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())); }