JAL-653 handle reverse strand mappings also
[jalview.git] / test / jalview / util / MappingUtilsTest.java
index 032af30..758694a 100644 (file)
@@ -442,7 +442,7 @@ public class MappingUtilsTest
             "[1, 2, 3, 4, 7, 8, 9, 12]",
             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
                 9, 12, 12 })));
-    // unpaired start position is ignored:
+    // trailing unpaired start position is ignored:
     assertEquals(
             "[1, 2, 3, 4, 7, 8, 9, 12]",
             Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
@@ -736,4 +736,43 @@ public class MappingUtilsTest
     assertEquals(12, e.getPosition());
     assertEquals(6, e.getNumber());
   }
+
+  /**
+   * Tests for the method that converts a series of [start, end] ranges to
+   * single positions, where the mapping is to a reverse strand i.e. start is
+   * greater than end point mapped to
+   */
+  @Test(groups = { "Functional" })
+  public void testFlattenRanges_reverseStrand()
+  {
+    assertEquals("[4, 3, 2, 1]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 1 })));
+    assertEquals(
+            "[4, 3, 2, 1]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 3, 2,
+                1 })));
+    assertEquals(
+            "[4, 3, 2, 1]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 4, 3,
+                3, 2, 2, 1, 1 })));
+    assertEquals(
+            "[12, 9, 8, 7, 4, 3, 2, 1]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 12, 12,
+                9, 7, 4, 1 })));
+    // forwards and backwards anyone?
+    assertEquals(
+            "[4, 5, 6, 3, 2, 1]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 4, 6, 3,
+                1 })));
+    // backwards and forwards
+    assertEquals(
+            "[3, 2, 1, 4, 5, 6]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 3, 1, 4,
+                6 })));
+    // trailing unpaired start position is ignored:
+    assertEquals(
+            "[12, 9, 8, 7, 4, 3, 2]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[] { 12, 12,
+                9, 7, 4, 2, 1 })));
+  }
 }