MinMaxHeap extends AbstractHeap implements IMinMaxHeap<IResetableComparable> { @Override public void replaceMin(IResetableComparable newElement) { entries[0].reset(newElement); trickleDown(0); } MinMaxHeap(IResetableComparableFactory factory, int capacity); @Override void getMin(IResetableComparable result); @Override void getMax(IResetableComparable result); boolean isEmpty(); @Override void peekMin(IResetableComparable result); @Override void peekMax(IResetableComparable result); @Override void replaceMin(IResetableComparable newElement); @Override void replaceMax(IResetableComparable newElement);  }
@Test public void testReplaceMin() { int capacity = 10; MinMaxHeap minMaxHeap = new MinMaxHeap(new IntFactory(), capacity); for (int i = 0; i < capacity; i++) { minMaxHeap.insert(new Int(i)); } assertEquals(capacity, minMaxHeap.getNumEntries()); assertFalse(minMaxHeap.isEmpty()); for (int i = capacity; i < capacity * 2; i++) { minMaxHeap.replaceMin(new Int(i)); } assertEquals(capacity, minMaxHeap.getNumEntries()); assertFalse(minMaxHeap.isEmpty()); Int minI = new Int(); Int peekI = new Int(); int i = 0; while (!minMaxHeap.isEmpty()) { minMaxHeap.peekMin(peekI); minMaxHeap.getMin(minI); assertTrue(peekI.compareTo(minI) == 0); assertEquals(i++ + capacity, minI.i); } }