import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
import java.util.ArrayList;
import java.util.Arrays;
1);
assertTrue(ml.isFromForwardStrand());
}
+
+ /**
+ * Test the method that merges a list of ranges where possible
+ */
+ @Test(groups = { "Functional" })
+ public void testCoalesceRanges()
+ {
+ assertNull(MapList.coalesceRanges(null));
+ List<int[]> ranges = new ArrayList<int[]>();
+ assertSame(ranges, MapList.coalesceRanges(ranges));
+ ranges.add(new int[] { 1, 3 });
+ assertSame(ranges, MapList.coalesceRanges(ranges));
+
+ // add non-contiguous range:
+ ranges.add(new int[] { 5, 6 });
+ assertSame(ranges, MapList.coalesceRanges(ranges));
+
+ // 'contiguous' range in opposite direction is not merged:
+ ranges.add(new int[] { 7, 6 });
+ assertSame(ranges, MapList.coalesceRanges(ranges));
+
+ // merging in forward direction:
+ ranges.clear();
+ ranges.add(new int[] { 1, 3 });
+ ranges.add(new int[] { 4, 5 });
+ ranges.add(new int[] { 5, 5 });
+ ranges.add(new int[] { 5, 7 });
+ List<int[]> merged = MapList.coalesceRanges(ranges);
+ assertEquals(1, merged.size());
+ assertArrayEquals(new int[] { 1, 7 }, merged.get(0));
+
+ // merging in reverse direction:
+ ranges.clear();
+ ranges.add(new int[] { 7, 5 });
+ ranges.add(new int[] { 5, 4 });
+ ranges.add(new int[] { 4, 4 });
+ ranges.add(new int[] { 3, 1 });
+ merged = MapList.coalesceRanges(ranges);
+ assertEquals(1, merged.size());
+ assertArrayEquals(new int[] { 7, 1 }, merged.get(0));
+
+ // merging with switches of direction:
+ ranges.clear();
+ ranges.add(new int[] { 1, 3 });
+ ranges.add(new int[] { 4, 5 });
+ ranges.add(new int[] { 5, 5 });
+ ranges.add(new int[] { 6, 6 });
+ ranges.add(new int[] { 12, 10 });
+ ranges.add(new int[] { 9, 8 });
+ ranges.add(new int[] { 8, 8 });
+ ranges.add(new int[] { 7, 7 });
+ merged = MapList.coalesceRanges(ranges);
+ assertEquals(2, merged.size());
+ assertArrayEquals(new int[] { 1, 6 }, merged.get(0));
+ assertArrayEquals(new int[] { 12, 7 }, merged.get(1));
+ }
}