+
+ @Test(groups = { "Functional" })
+ public void testAddMapList()
+ {
+ MapList ml = new MapList(new int[] { 11, 15, 20, 25, 35, 30 },
+ new int[] { 72, 22 }, 1, 3);
+ assertEquals(11, ml.getFromLowest());
+ assertEquals(35, ml.getFromHighest());
+ assertEquals(22, ml.getToLowest());
+ assertEquals(72, ml.getToHighest());
+
+ MapList ml2 = new MapList(new int[] { 2, 4, 37, 40 }, new int[] { 12,
+ 17, 78, 83, 88, 96 }, 1, 3);
+ ml.addMapList(ml2);
+ assertEquals(2, ml.getFromLowest());
+ assertEquals(40, ml.getFromHighest());
+ assertEquals(12, ml.getToLowest());
+ assertEquals(96, ml.getToHighest());
+
+ String s = ml.toString();
+ assertEquals(
+ "From (1:3) [ [11, 15] [20, 25] [35, 30] [2, 4] [37, 40] ] To [ [72, 22] [12, 17] [78, 83] [88, 96] ]",
+ s);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testAddMapList_contiguous()
+ {
+ MapList ml = new MapList(new int[] { 11, 15 }, new int[] { 72, 58 }, 1,
+ 3);
+
+ MapList ml2 = new MapList(new int[] { 15, 16 }, new int[] { 58, 53 },
+ 1, 3);
+ ml.addMapList(ml2);
+ assertEquals("From (1:3) [ [11, 16] ] To [ [72, 53] ]", ml.toString());
+ }
+
+ @Test(groups = "Functional")
+ public void testAddRange()
+ {
+ int[] range = { 1, 5 };
+ List<int[]> ranges = new ArrayList<int[]>();
+
+ // add to empty list:
+ MapList.addRange(range, ranges);
+ assertEquals(1, ranges.size());
+ assertSame(range, ranges.get(0));
+
+ // extend contiguous (same position):
+ MapList.addRange(new int[] { 5, 10 }, ranges);
+ assertEquals(1, ranges.size());
+ assertEquals(1, ranges.get(0)[0]);
+ assertEquals(10, ranges.get(0)[1]);
+
+ // extend contiguous (next position):
+ MapList.addRange(new int[] { 11, 15 }, ranges);
+ assertEquals(1, ranges.size());
+ assertEquals(1, ranges.get(0)[0]);
+ assertEquals(15, ranges.get(0)[1]);
+
+ // change direction: range is not merged:
+ MapList.addRange(new int[] { 16, 10 }, ranges);
+ assertEquals(2, ranges.size());
+ assertEquals(16, ranges.get(1)[0]);
+ assertEquals(10, ranges.get(1)[1]);
+
+ // extend reverse contiguous (same position):
+ MapList.addRange(new int[] { 10, 8 }, ranges);
+ assertEquals(2, ranges.size());
+ assertEquals(16, ranges.get(1)[0]);
+ assertEquals(8, ranges.get(1)[1]);
+
+ // extend reverse contiguous (next position):
+ MapList.addRange(new int[] { 7, 6 }, ranges);
+ assertEquals(2, ranges.size());
+ assertEquals(16, ranges.get(1)[0]);
+ assertEquals(6, ranges.get(1)[1]);
+
+ // change direction: range is not merged:
+ MapList.addRange(new int[] { 6, 9 }, ranges);
+ assertEquals(3, ranges.size());
+ assertEquals(6, ranges.get(2)[0]);
+ assertEquals(9, ranges.get(2)[1]);
+
+ // not contiguous: not merged
+ MapList.addRange(new int[] { 11, 12 }, ranges);
+ assertEquals(4, ranges.size());
+ assertEquals(11, ranges.get(3)[0]);
+ assertEquals(12, ranges.get(3)[1]);
+ }
+
+ /**
+ * Check state after construction
+ */
+ @Test(groups = { "Functional" })
+ public void testConstructor_withLists()
+ {
+ /*
+ * reverse direction
+ */
+ int[][] codons = new int[][] { { 9, 6 } };
+ int[][] protein = new int[][] { { 100, 91 }, { 80, 79 } };
+ MapList ml = new MapList(Arrays.asList(codons), Arrays.asList(protein),
+ 3, 1);
+ assertEquals(6, ml.getFromLowest());
+ assertEquals(9, ml.getFromHighest());
+ assertEquals(79, ml.getToLowest());
+ assertEquals(100, ml.getToHighest());
+ }