public void RemoveFirstTest() { Heap <MaxHeapInt> maxHeap = new Heap <MaxHeapInt>(10); Heap <MinHeapInt> minHeap = new Heap <MinHeapInt>(10); MaxHeapInt maxItem = new MaxHeapInt(20); MinHeapInt minItem = new MinHeapInt(-42); maxHeap.Add(new MaxHeapInt(5)); maxHeap.Add(new MaxHeapInt(-10)); maxHeap.Add(new MaxHeapInt(15)); maxHeap.Add(new MaxHeapInt(-11)); maxHeap.Add(new MaxHeapInt(-1)); maxHeap.Add(new MaxHeapInt(1)); maxHeap.Add(maxItem); minHeap.Add(new MinHeapInt(1)); minHeap.Add(new MinHeapInt(-1)); minHeap.Add(new MinHeapInt(-8)); minHeap.Add(new MinHeapInt(91)); minHeap.Add(minItem); Assert.AreEqual(maxHeap.RemoveFirst(), maxItem); Assert.AreEqual(minHeap.RemoveFirst(), minItem); }
public void HeapSortingIntTest() { Heap <MaxHeapInt> maxHeap = new Heap <MaxHeapInt>(10); Heap <MinHeapInt> minHeap = new Heap <MinHeapInt>(10); maxHeap.Add(new MaxHeapInt(5)); maxHeap.Add(new MaxHeapInt(-10)); maxHeap.Add(new MaxHeapInt(15)); maxHeap.Add(new MaxHeapInt(-11)); maxHeap.Add(new MaxHeapInt(-1)); maxHeap.Add(new MaxHeapInt(1)); maxHeap.Add(new MaxHeapInt(1)); maxHeap.Add(new MaxHeapInt(8)); maxHeap.Add(new MaxHeapInt(91)); maxHeap.Add(new MaxHeapInt(-42)); minHeap.Add(new MinHeapInt(5)); minHeap.Add(new MinHeapInt(-10)); minHeap.Add(new MinHeapInt(15)); minHeap.Add(new MinHeapInt(-11)); minHeap.Add(new MinHeapInt(-1)); minHeap.Add(new MinHeapInt(1)); minHeap.Add(new MinHeapInt(1)); minHeap.Add(new MinHeapInt(8)); minHeap.Add(new MinHeapInt(91)); minHeap.Add(new MinHeapInt(-42)); int lastItem = int.MinValue; while (minHeap.Count > 0) { MinHeapInt removed = minHeap.RemoveFirst(); Assert.LessOrEqual(lastItem, removed.num); lastItem = removed.num; } lastItem = int.MaxValue; while (maxHeap.Count > 0) { MaxHeapInt removed = maxHeap.RemoveFirst(); Assert.GreaterOrEqual(lastItem, removed.num); lastItem = removed.num; } }