/*
 * Copyright (C) 2014 Birunthan Mohanathas
 *
 * Licensed under the MIT license <http://opensource.org/licenses/MIT>. This
 * file may not be copied, modified, or distributed except according to those
 * terms.
 */

package com.mohanathas.spiffer.util;

import java.util.NoSuchElementException;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;

/**
 * Tests the BinaryMinHeap class.
 */
public class BinaryMinHeapTest {
    private BinaryMinHeap<Integer> mHeap;

    public BinaryMinHeapTest() {
    }

    @Before
    public void setUp() {
        mHeap = new BinaryMinHeap<>();
    }

    @Test(expected = NoSuchElementException.class)
    public void testPeekOnEmptyHeap() {
        mHeap.peek();
    }

    @Test
    public void testPopOrder() {
        mHeap.add(3);
        mHeap.add(8);
        mHeap.add(2);
        mHeap.add(6);
        mHeap.add(4);
        mHeap.add(5);
        mHeap.add(1);
        mHeap.add(9);
        mHeap.add(7);
        mHeap.add(0);
        assertEquals(new Integer(0), mHeap.pop());
        assertEquals(new Integer(1), mHeap.pop());
        assertEquals(new Integer(2), mHeap.pop());
        assertEquals(new Integer(3), mHeap.pop());
    }

    @Test
    public void testToString() {
        mHeap.add(1);
        mHeap.add(2);
        assertTrue(mHeap.toString().startsWith("[1, 2"));
    }
}

@@ -744,33 +744,26 @@
     
-@Test%0A    public
+private
  void 
-tes
+asser
 tPop
@@ -772,53 +772,123 @@
 der(
-) %7B%0A        mHeap.add(3);%0A       
+int from, int to) %7B%0A        for (int i = from; i %3C= to; ++i) %7B%0A            assertEquals(new Integer(i),
  mHeap.
-add(8
+pop()
 );%0A 
@@ -898,44 +898,113 @@
     
-mHeap.add(2);%0A        mHeap.add(6);%0A
+%7D%0A    %7D%0A%0A    @Test%0A    public void testAscedingAddOrder() %7B%0A        for (int i = 0; i %3C= 100; ++i) %7B%0A    
     
@@ -1017,17 +1017,17 @@
 eap.add(
-4
+i
 );%0A     
@@ -1033,96 +1033,153 @@
     
-mHeap.add(5);%0A        mHeap.add(1
+%7D%0A        assertPopOrder(0, 100
 );%0A    
+%7D%0A%0A
     
-mHeap.add(9);%0A        mHeap.add(7);%0A
+@Test%0A    public void testDescedingAddOrder() %7B%0A        for (int i = 100; i %3E= 0; --i) %7B%0A   
         
 mHea
@@ -1166,32 +1166,33 @@
 i) %7B%0A           
+ 
 mHeap.add(0);%0A  
@@ -1185,17 +1185,17 @@
 eap.add(
-0
+i
 );%0A     
@@ -1201,201 +1201,225 @@
     
-assertEquals(new Integ
+%7D%0A        assertPopOrd
 er(0
-)
 , 
-mHeap.pop()
+100
 );%0A    
+%7D%0A%0A
     
-assertEquals(new Integer(1), mHeap.pop());%0A        assertEquals(new Integer(2), mHeap.pop());%0A        assertEquals(new Integer(3), mHeap.pop()
+@Test%0A    public void testBothAddOrder() %7B%0A        for (int i = 0; i %3C= 100; ++i) %7B%0A            mHeap.add(i %25 2 == 0 ? i : 100 - i);%0A        %7D%0A        assertPopOrder(0, 100
 );%0A 

Make tests more exhaustive