Merge branch 'develop' into features/mchmmer
[jalview.git] / test / jalview / util / MapListTest.java
index 3fc6fe0..cd3e124 100644 (file)
@@ -391,7 +391,9 @@ public class MapListTest
     MapList ml7 = new MapList(codons, protein, 3, 1); // toShifts differ
 
     assertTrue(ml.equals(ml));
+    assertEquals(ml.hashCode(), ml.hashCode());
     assertTrue(ml.equals(ml1));
+    assertEquals(ml.hashCode(), ml1.hashCode());
     assertTrue(ml1.equals(ml));
 
     assertFalse(ml.equals(null));
@@ -426,7 +428,7 @@ public class MapListTest
   @Test(groups = { "Functional" })
   public void testGetRanges()
   {
-    List<int[]> ranges = new ArrayList<int[]>();
+    List<int[]> ranges = new ArrayList<>();
     ranges.add(new int[] { 2, 3 });
     ranges.add(new int[] { 5, 6 });
     assertEquals("[2, 3, 5, 6]", Arrays.toString(MapList.getRanges(ranges)));
@@ -599,60 +601,6 @@ public class MapListTest
     assertEquals("[ [11, 16] ] 1:3 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
    */
@@ -702,7 +650,7 @@ public class MapListTest
   public void testCoalesceRanges()
   {
     assertNull(MapList.coalesceRanges(null));
-    List<int[]> ranges = new ArrayList<int[]>();
+    List<int[]> ranges = new ArrayList<>();
     assertSame(ranges, MapList.coalesceRanges(ranges));
     ranges.add(new int[] { 1, 3 });
     assertSame(ranges, MapList.coalesceRanges(ranges));
@@ -763,7 +711,7 @@ public class MapListTest
   @Test(groups = { "Functional" })
   public void testCoalesceRanges_withOverlap()
   {
-    List<int[]> ranges = new ArrayList<int[]>();
+    List<int[]> ranges = new ArrayList<>();
     ranges.add(new int[] { 1, 3 });
     ranges.add(new int[] { 2, 5 });
 
@@ -940,4 +888,29 @@ public class MapListTest
     compound = ml1.traverse(ml2);
     assertNull(compound);
   }
+
+  /**
+   * Test that method that inspects for the (first) forward or reverse 'to' range.
+   * Single position ranges are ignored.
+   */
+  @Test(groups = { "Functional" })
+  public void testIsToForwardsStrand()
+  {
+    // [3-9] declares forward strand
+    MapList ml = new MapList(new int[] { 20, 11 },
+            new int[]
+            { 2, 2, 3, 9, 12, 11 }, 1, 1);
+    assertTrue(ml.isToForwardStrand());
+
+    // [11-5] declares reverse strand ([13-14] is ignored)
+    ml = new MapList(new int[] { 20, 11 },
+            new int[]
+            { 2, 2, 11, 5, 13, 14 }, 1, 1);
+    assertFalse(ml.isToForwardStrand());
+
+    // all single position ranges - defaults to forward strand
+    ml = new MapList(new int[] { 3, 1 }, new int[] { 2, 2, 4, 4, 6, 6 }, 1,
+            1);
+    assertTrue(ml.isToForwardStrand());
+  }
 }