@Test
    public void insertTest() {
        int i, j, heapDimension, max = 0, x;
        Random randomGenerator = new Random();
        heapDimension = 100 + randomGenerator.nextInt(200); //[100, 200)
        MaxHeap heap = new MaxHeap(heapDimension);
        for (i = 0; i < heapDimension; i++) {
            x = 1 + randomGenerator.nextInt(200);
            if (x > max) {
                max = x;
            }
            try {
                heap.insert(x);
            } catch (Exception ex) {
                fail("Exception was not expected to be thrown.");
            }
            assertEquals(heap.lastFreePos, i + 1);
            assertEquals(heap.values[0], max);
            for (j = 0; j < (heap.lastFreePos + 1) / 2 - 1; j++) {
                if ((j + 1) * 2 - 1 < heap.lastFreePos) {
                    assertTrue(heap.values[j] >= heap.values[(j + 1) * 2 - 1]);
                }
                if ((j + 1) * 2 < heap.lastFreePos) {
                    assertTrue(heap.values[j] >= heap.values[(j + 1) * 2]);
                }
            }
        }

        try {
            heap.insert(100);
            fail("Heap should be full.");
        } catch (Exception ex) {
            assertEquals(ex.getMessage(), "Heap overflow");
        }
    }