@Test
public void testMapOfDisjointIntervals()
{

    for (int intervalSize = 1; intervalSize <= 5; intervalSize++) {
        List<Interval> control = new ArrayList<Interval>();
        SortedMap<Interval, Interval> map = new TreeMap<Interval, Interval>();
        for (int i = 0; i < 100; i++) {
            Interval interval = interval(i * intervalSize, (i + 1) * intervalSize - 1);
            control.add(interval);
            map.put(interval, interval);
        }
        Assert.assertEquals(control.size(), map.size());
        Iterator<Interval> controlScan = control.iterator();
        Iterator<Interval> mapScan = map.keySet().iterator();
        while (controlScan.hasNext() && mapScan.hasNext()) {
            Interval controlInterval = controlScan.next();
            Interval mapInterval = mapScan.next();
            Assert.assertEquals(controlInterval, mapInterval);
            mapInterval = map.get(controlInterval);
            Assert.assertEquals(controlInterval, mapInterval);
        }
        Assert.assertTrue(!controlScan.hasNext());
        Assert.assertTrue(!mapScan.hasNext());
    }
}