@Test
public void testToIntervalMap() {

  ResourceCalculator resCalc = new DefaultResourceCalculator();
  RLESparseResourceAllocation rleSparseVector =
      new RLESparseResourceAllocation(resCalc);
  Map<ReservationInterval, Resource> mapAllocations;
  // Check empty
  mapAllocations = rleSparseVector.toIntervalMap();
  Assert.assertTrue(mapAllocations.isEmpty());
  // Check full
  int[] alloc = { 0, 5, 10, 10, 5, 0, 5, 0 };
  int start = 100;
  Set<Entry<ReservationInterval, Resource>> inputs =
      generateAllocation(start, alloc, false).entrySet();
  for (Entry<ReservationInterval, Resource> ip : inputs) {
    rleSparseVector.addInterval(ip.getKey(), ip.getValue());
  }
  mapAllocations = rleSparseVector.toIntervalMap();
  Assert.assertTrue(mapAllocations.size() == 5);
  for (Entry<ReservationInterval, Resource> entry : mapAllocations
      .entrySet()) {
    ReservationInterval interval = entry.getKey();
    Resource resource = entry.getValue();
    if (interval.getStartTime() == 101L) {
      Assert.assertTrue(interval.getEndTime() == 102L);
      Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5));
    } else if (interval.getStartTime() == 102L) {
      Assert.assertTrue(interval.getEndTime() == 104L);
      Assert.assertEquals(resource, Resource.newInstance(10 * 1024, 10));
    } else if (interval.getStartTime() == 104L) {
      Assert.assertTrue(interval.getEndTime() == 105L);
      Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5));
    } else if (interval.getStartTime() == 105L) {
      Assert.assertTrue(interval.getEndTime() == 106L);
      Assert.assertEquals(resource, Resource.newInstance(0 * 1024, 0));
    } else if (interval.getStartTime() == 106L) {
      Assert.assertTrue(interval.getEndTime() == 107L);
      Assert.assertEquals(resource, Resource.newInstance(5 * 1024, 5));
    } else {
      Assert.fail();
    }
  }
}