JAL-3725 helper methods for computing mapped feature range overlap
[jalview.git] / test / jalview / util / MappingUtilsTest.java
index 097ccd4..4b7c75c 100644 (file)
@@ -22,10 +22,23 @@ package jalview.util;
 
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
+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.awt.Color;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
 
 import jalview.api.AlignViewportI;
+import jalview.bin.Cache;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
 import jalview.commands.EditCommand.Edit;
@@ -46,18 +59,13 @@ import jalview.io.FileFormat;
 import jalview.io.FileFormatI;
 import jalview.io.FormatAdapter;
 
-import java.awt.Color;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
 public class MappingUtilsTest
 {
+  @BeforeClass(alwaysRun = true)
+  public void setUp()
+  {
+    Cache.initLogger();
+  }
 
   @BeforeClass(alwaysRun = true)
   public void setUpJvOptionPane()
@@ -89,8 +97,9 @@ public class MappingUtilsTest
     MapList map = new MapList(new int[] { 5, 10 }, new int[] { 12, 13 }, 3,
             1);
     acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     /*
      * Check protein residue 12 maps to codon 5-7, 13 to codon 8-10
@@ -139,11 +148,14 @@ public class MappingUtilsTest
      * Map dna bases [6, 8, 9], [11, 13, 115] to protein residues 8 and 9
      */
     AlignedCodonFrame acf = new AlignedCodonFrame();
-    MapList map = new MapList(new int[] { 6, 6, 8, 9, 11, 11, 13, 13, 15,
-        15 }, new int[] { 8, 9 }, 3, 1);
+    MapList map = new MapList(
+            new int[]
+            { 6, 6, 8, 9, 11, 11, 13, 13, 15, 15 }, new int[] { 8, 9 }, 3,
+            1);
     acf.addMap(seq1.getDatasetSequence(), aseq1.getDatasetSequence(), map);
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     /*
      * Check protein residue 8 maps to [6, 8, 9]
@@ -183,8 +195,8 @@ public class MappingUtilsTest
     for (int i = 5; i < 18; i++)
     {
       sr = MappingUtils.buildSearchResults(seq1, i, acfList);
-      int residue = (i == 6 || i == 8 || i == 9) ? 8 : (i == 11 || i == 13
-              || i == 15 ? 9 : 0);
+      int residue = (i == 6 || i == 8 || i == 9) ? 8
+              : (i == 11 || i == 13 || i == 15 ? 9 : 0);
       if (residue == 0)
       {
         assertEquals(0, sr.getResults().size());
@@ -220,11 +232,12 @@ public class MappingUtilsTest
     MapList map = new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 3, 1);
     for (int seq = 0; seq < 3; seq++)
     {
-      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
-              .getSequenceAt(seq).getDatasetSequence(), map);
+      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(),
+              protein.getSequenceAt(seq).getDatasetSequence(), map);
     }
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     AlignViewportI dnaView = new AlignViewport(cdna);
     AlignViewportI proteinView = new AlignViewport(protein);
@@ -285,8 +298,8 @@ public class MappingUtilsTest
   protected AlignmentI loadAlignment(final String data, FileFormatI format)
           throws IOException
   {
-    AlignmentI a = new FormatAdapter().readFile(data,
-            DataSourceType.PASTE, format);
+    AlignmentI a = new FormatAdapter().readFile(data, DataSourceType.PASTE,
+            format);
     a.setDataset(null);
     return a;
   }
@@ -331,8 +344,8 @@ public class MappingUtilsTest
     cs.clear();
     colsel.clear();
     colsel.addElement(2);
-    MappingUtils.mapColumnSelection(colsel, hidden, proteinView,
-            dnaView, cs, hs);
+    MappingUtils.mapColumnSelection(colsel, hidden, proteinView, dnaView,
+            cs, hs);
     assertEquals("[]", cs.getSelected().toString());
 
     /*
@@ -342,8 +355,8 @@ public class MappingUtilsTest
     cs.clear();
     colsel.clear();
     colsel.addElement(3);
-    MappingUtils.mapColumnSelection(colsel, hidden, proteinView,
-            dnaView, cs, hs);
+    MappingUtils.mapColumnSelection(colsel, hidden, proteinView, dnaView,
+            cs, hs);
     assertEquals("[5, 6, 7, 8, 9, 10]", cs.getSelected().toString());
 
     /*
@@ -354,10 +367,10 @@ public class MappingUtilsTest
     colsel.clear();
     colsel.addElement(1);
     colsel.addElement(3);
-    MappingUtils.mapColumnSelection(colsel, hidden, proteinView,
-            dnaView, cs, hs);
-    assertEquals("[0, 1, 2, 3, 5, 6, 7, 8, 9, 10]", cs.getSelected()
-            .toString());
+    MappingUtils.mapColumnSelection(colsel, hidden, proteinView, dnaView,
+            cs, hs);
+    assertEquals("[0, 1, 2, 3, 5, 6, 7, 8, 9, 10]",
+            cs.getSelected().toString());
   }
 
   /**
@@ -386,23 +399,27 @@ public class MappingUtilsTest
     // map first dna to first protein seq
     AlignedCodonFrame acf = new AlignedCodonFrame();
     MapList map = new MapList(new int[] { 10, 12, 15, 15, 17, 18 },
-            new int[] { 40, 41 }, 3, 1);
-    acf.addMap(cdna.getSequenceAt(0).getDatasetSequence(), protein
-            .getSequenceAt(0).getDatasetSequence(), map);
+            new int[]
+            { 40, 41 }, 3, 1);
+    acf.addMap(cdna.getSequenceAt(0).getDatasetSequence(),
+            protein.getSequenceAt(0).getDatasetSequence(), map);
 
     // map second dna to second protein seq
-    map = new MapList(new int[] { 20, 20, 22, 23, 24, 26 }, new int[] { 50,
-        51 }, 3, 1);
-    acf.addMap(cdna.getSequenceAt(1).getDatasetSequence(), protein
-            .getSequenceAt(1).getDatasetSequence(), map);
+    map = new MapList(new int[] { 20, 20, 22, 23, 24, 26 },
+            new int[]
+            { 50, 51 }, 3, 1);
+    acf.addMap(cdna.getSequenceAt(1).getDatasetSequence(),
+            protein.getSequenceAt(1).getDatasetSequence(), map);
 
     // map third dna to third protein seq
-    map = new MapList(new int[] { 30, 30, 32, 34, 36, 37 }, new int[] { 60,
-        61 }, 3, 1);
-    acf.addMap(cdna.getSequenceAt(2).getDatasetSequence(), protein
-            .getSequenceAt(2).getDatasetSequence(), map);
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    map = new MapList(new int[] { 30, 30, 32, 34, 36, 37 },
+            new int[]
+            { 60, 61 }, 3, 1);
+    acf.addMap(cdna.getSequenceAt(2).getDatasetSequence(),
+            protein.getSequenceAt(2).getDatasetSequence(), map);
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     dnaView = new AlignViewport(cdna);
     proteinView = new AlignViewport(protein);
@@ -465,24 +482,21 @@ public class MappingUtilsTest
   public void testFlattenRanges()
   {
     assertEquals("[1, 2, 3, 4]",
-            Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4 })));
-    assertEquals(
-            "[1, 2, 3, 4]",
-            Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 2, 3,
-                4 })));
-    assertEquals(
-            "[1, 2, 3, 4]",
-            Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 1, 2,
-                2, 3, 3, 4, 4 })));
-    assertEquals(
-            "[1, 2, 3, 4, 7, 8, 9, 12]",
-            Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
-                9, 12, 12 })));
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 1, 4 })));
+    assertEquals("[1, 2, 3, 4]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 1, 2, 3, 4 })));
+    assertEquals("[1, 2, 3, 4]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 1, 1, 2, 2, 3, 3, 4, 4 })));
+    assertEquals("[1, 2, 3, 4, 7, 8, 9, 12]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 1, 4, 7, 9, 12, 12 })));
     // trailing unpaired start position is ignored:
-    assertEquals(
-            "[1, 2, 3, 4, 7, 8, 9, 12]",
-            Arrays.toString(MappingUtils.flattenRanges(new int[] { 1, 4, 7,
-                9, 12, 12, 15 })));
+    assertEquals("[1, 2, 3, 4, 7, 8, 9, 12]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 1, 4, 7, 9, 12, 12, 15 })));
   }
 
   /**
@@ -508,11 +522,12 @@ public class MappingUtilsTest
     MapList map = new MapList(new int[] { 1, 6 }, new int[] { 1, 2 }, 3, 1);
     for (int seq = 0; seq < 3; seq++)
     {
-      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
-              .getSequenceAt(seq).getDatasetSequence(), map);
+      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(),
+              protein.getSequenceAt(seq).getDatasetSequence(), map);
     }
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     AlignViewportI dnaView = new AlignViewport(cdna);
     AlignViewportI proteinView = new AlignViewport(protein);
@@ -585,17 +600,19 @@ public class MappingUtilsTest
             FileFormat.Fasta);
     cdna.setDataset(null);
     AlignmentI protein = loadAlignment(
-            ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n", FileFormat.Fasta);
+            ">Seq1\n-KA-S\n>Seq2\n--L-QY\n>Seq3\nQ-V-M\n",
+            FileFormat.Fasta);
     protein.setDataset(null);
     AlignedCodonFrame acf = new AlignedCodonFrame();
     MapList map = new MapList(new int[] { 1, 9 }, new int[] { 1, 3 }, 3, 1);
     for (int seq = 0; seq < 3; seq++)
     {
-      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(), protein
-              .getSequenceAt(seq).getDatasetSequence(), map);
+      acf.addMap(cdna.getSequenceAt(seq).getDatasetSequence(),
+              protein.getSequenceAt(seq).getDatasetSequence(), map);
     }
-    List<AlignedCodonFrame> acfList = Arrays.asList(new AlignedCodonFrame[]
-    { acf });
+    List<AlignedCodonFrame> acfList = Arrays
+            .asList(new AlignedCodonFrame[]
+            { acf });
 
     AlignViewportI dnaView = new AlignViewport(cdna);
     AlignViewportI proteinView = new AlignViewport(protein);
@@ -698,8 +715,8 @@ public class MappingUtilsTest
     /*
      * Seq1 has three mappings
      */
-    List<AlignedCodonFrame> result = MappingUtils.findMappingsForSequence(
-            seq1, mappings);
+    List<AlignedCodonFrame> result = MappingUtils
+            .findMappingsForSequence(seq1, mappings);
     assertEquals(3, result.size());
     assertTrue(result.contains(acf1));
     assertTrue(result.contains(acf2));
@@ -776,22 +793,22 @@ public class MappingUtilsTest
      */
     List<AlignedCodonFrame> result = MappingUtils
             .findMappingsForSequenceAndOthers(null, mappings,
-                    Arrays.asList(new SequenceI[] { seq1, seq2 }));
+                    Arrays.asList(new SequenceI[]
+                    { seq1, seq2 }));
     assertTrue(result.isEmpty());
 
     result = MappingUtils.findMappingsForSequenceAndOthers(seq1, null,
-            Arrays.asList(new SequenceI[] { seq1, seq2 }));
+            Arrays.asList(new SequenceI[]
+            { seq1, seq2 }));
     assertTrue(result.isEmpty());
 
     /*
      * Seq1 has three mappings, but filter argument will only accept
      * those to seq2
      */
-    result = MappingUtils.findMappingsForSequenceAndOthers(
-            seq1,
-            mappings,
-            Arrays.asList(new SequenceI[] { seq1, seq2,
-                seq1.getDatasetSequence() }));
+    result = MappingUtils.findMappingsForSequenceAndOthers(seq1, mappings,
+            Arrays.asList(new SequenceI[]
+            { seq1, seq2, seq1.getDatasetSequence() }));
     assertEquals(2, result.size());
     assertTrue(result.contains(acf1));
     assertTrue(result.contains(acf2));
@@ -820,7 +837,8 @@ public class MappingUtilsTest
     dna.createDatasetSequence();
     protein.createDatasetSequence();
     AlignedCodonFrame acf = new AlignedCodonFrame();
-    MapList map = new MapList(new int[] { 8, 16 }, new int[] { 5, 7 }, 3, 1);
+    MapList map = new MapList(new int[] { 8, 16 }, new int[] { 5, 7 }, 3,
+            1);
     acf.addMap(dna.getDatasetSequence(), protein.getDatasetSequence(), map);
     List<AlignedCodonFrame> mappings = new ArrayList<>();
     mappings.add(acf);
@@ -835,7 +853,8 @@ public class MappingUtilsTest
      */
     EditCommand ec = new EditCommand();
     final Edit edit = ec.new Edit(Action.INSERT_GAP,
-            new SequenceI[] { protein }, 4, 2, '-');
+            new SequenceI[]
+            { protein }, 4, 2, '-');
     ec.appendEdit(edit, prot, true, null);
 
     /*
@@ -861,34 +880,29 @@ public class MappingUtilsTest
   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 })));
+            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 })));
+    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 })));
+    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 })));
+    assertEquals("[12, 9, 8, 7, 4, 3, 2]",
+            Arrays.toString(MappingUtils.flattenRanges(new int[]
+            { 12, 12, 9, 7, 4, 2, 1 })));
   }
 
   /**
@@ -1156,85 +1170,115 @@ public class MappingUtilsTest
     /*
      * both forward ranges
      */
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        1, 10 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        2, 10 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        1, 9 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        4, 5 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        0, 9 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        -10, -9 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        1, 11 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        11, 12 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 1, 10 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 2, 10 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 1, 9 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 4, 5 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 0, 9 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { -10, -9 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 1, 11 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 11, 12 }));
 
     /*
      * forward range, reverse query
      */
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        10, 1 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        9, 1 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        10, 2 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        5, 5 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        11, 1 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, new int[] {
-        10, 0 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 10, 1 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 9, 1 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 10, 2 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 5, 5 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 11, 1 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 10, 0 }));
 
     /*
      * reverse range, forward query
      */
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        1, 10 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        1, 9 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        2, 10 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        6, 6 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        6, 11 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        11, 20 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        -3, -2 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 1, 10 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 1, 9 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 2, 10 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 6, 6 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 6, 11 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 11, 20 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { -3, -2 }));
 
     /*
      * both reverse
      */
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        10, 1 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        9, 1 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        10, 2 }));
-    assertTrue(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        3, 3 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        11, 1 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        10, 0 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        12, 11 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 10, 1 }, new int[] {
-        -5, -8 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 10, 1 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 9, 1 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 10, 2 }));
+    assertTrue(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 3, 3 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 11, 1 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 10, 0 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { 12, 11 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 10, 1 }, new int[] { -5, -8 }));
 
     /*
      * bad arguments
      */
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10, 12 },
-            new int[] {
-        1, 10 }));
-    assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 },
-            new int[] { 1 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10, 12 }, new int[] { 1, 10 }));
+    assertFalse(
+            MappingUtils.rangeContains(new int[]
+            { 1, 10 }, new int[] { 1 }));
     assertFalse(MappingUtils.rangeContains(new int[] { 1, 10 }, null));
     assertFalse(MappingUtils.rangeContains(null, new int[] { 1, 10 }));
   }
@@ -1284,4 +1328,22 @@ public class MappingUtilsTest
     assertEquals(1, ranges.size());
     assertEquals(9, ranges.get(0)[1]);
   }
+
+  @Test(groups = "Functional")
+  public void testFindOverlap()
+  {
+    List<int[]> ranges = new ArrayList<>();
+    ranges.add(new int[] { 4, 8 });
+    ranges.add(new int[] { 10, 12 });
+    ranges.add(new int[] { 16, 19 });
+
+    int[] overlap = MappingUtils.findOverlap(ranges, 5, 13);
+    assertArrayEquals(overlap, new int[] { 5, 12 });
+    overlap = MappingUtils.findOverlap(ranges, -100, 100);
+    assertArrayEquals(overlap, new int[] { 4, 19 });
+    overlap = MappingUtils.findOverlap(ranges, 7, 17);
+    assertArrayEquals(overlap, new int[] { 7, 17 });
+    overlap = MappingUtils.findOverlap(ranges, 13, 15);
+    assertNull(overlap);
+  }
 }