public MaxHeap <int> CreateMaxHeapFromArray(int[] arr) { MaxHeap <int> heap = new MaxHeap <int>(); foreach (var item in arr) { heap.Insert(item); } return(heap); }
public void RemoveAt_RemoveLastItem_RemoveSuccessful() { int[] input = this.sampleMaxHeap; int[] expected = { 100, 19, 36, 17, 3, 25, 1, 2 }; MaxHeap <int> heap = this.CreateMaxHeapFromArray(input); heap.RemoveAt(input.Length - 1); Assert.IsTrue(heap.GetItems().SequenceEqual(expected)); }
public void RemoveAt_RemoveRootItem_RemoveSuccessful() { int[] input = this.sampleMaxHeap; int[] expected = { 36, 19, 25, 17, 3, 7, 1, 2 }; MaxHeap <int> heap = this.CreateMaxHeapFromArray(input); heap.Pop(); Assert.IsTrue(heap.GetItems().SequenceEqual(expected)); }
public void RemoveAt_PassInvalidIndex_ThrowsArgumentNullException() { MaxHeap <int> heap = this.CreateMaxHeapFromArray(sampleMaxHeap); Assert.Throws <ArgumentException>(() => heap.RemoveAt(-1)); }
public void Insert_PassNullItem_ThrowsArgumentNullException() { MaxHeap <string> heap = new MaxHeap <string>(); Assert.Throws <ArgumentNullException>(() => heap.Insert(null)); }