From 13a51d07c7bdc6d567eff0eea3bb7ee36edee34a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 1 Oct 2020 12:42:32 +0100 Subject: [PATCH] JAL-3761 failing tests for locateInFrom/To with overlapping ranges --- test/jalview/util/MapListTest.java | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/jalview/util/MapListTest.java b/test/jalview/util/MapListTest.java index 71fbdfd..4017055 100644 --- a/test/jalview/util/MapListTest.java +++ b/test/jalview/util/MapListTest.java @@ -957,4 +957,57 @@ public class MapListTest 1); assertTrue(ml.isToForwardStrand()); } + + /** + * Test for mapping with overlapping ranges + */ + @Test(groups = { "Functional" }) + public void testLocateInFrom_withOverlap() + { + int[] codons = new int[] { 1, 12, 12, 17 }; + int[] protein = new int[] { 1, 6 }; + MapList ml = new MapList(codons, protein, 3, 1); + assertEquals("[1, 3]", Arrays.toString(ml.locateInFrom(1, 1))); + assertEquals("[4, 6]", Arrays.toString(ml.locateInFrom(2, 2))); + assertEquals("[7, 9]", Arrays.toString(ml.locateInFrom(3, 3))); + assertEquals("[10, 12]", Arrays.toString(ml.locateInFrom(4, 4))); + assertEquals("[12, 14]", Arrays.toString(ml.locateInFrom(5, 5))); + assertEquals("[15, 17]", Arrays.toString(ml.locateInFrom(6, 6))); + assertEquals("[1, 6]", Arrays.toString(ml.locateInFrom(1, 2))); + assertEquals("[1, 9]", Arrays.toString(ml.locateInFrom(1, 3))); + assertEquals("[1, 12]", Arrays.toString(ml.locateInFrom(1, 4))); + assertEquals("[1, 12, 12, 14]", Arrays.toString(ml.locateInFrom(1, 5))); + assertEquals("[1, 12, 12, 17]", Arrays.toString(ml.locateInFrom(1, 6))); + assertEquals("[4, 9]", Arrays.toString(ml.locateInFrom(2, 3))); + assertEquals("[7, 12, 12, 17]", Arrays.toString(ml.locateInFrom(3, 6))); + + assertNull(ml.locateInFrom(0, 0)); + assertNull(ml.locateInFrom(1, 7)); + assertNull(ml.locateInFrom(-1, 1)); + } + + /** + * Test for mapping with overlapping ranges + */ + @Test(groups = { "Functional" }) + public void testLocateInTo_withOverlap() + { + int[] codons = new int[] { 1, 12, 12, 17 }; + int[] protein = new int[] { 1, 6 }; + MapList ml = new MapList(codons, protein, 3, 1); + assertEquals("[1, 1]", Arrays.toString(ml.locateInTo(1, 1))); + assertEquals("[1, 3]", Arrays.toString(ml.locateInTo(3, 8))); + assertEquals("[1, 4]", Arrays.toString(ml.locateInTo(2, 11))); + assertEquals("[1, 4]", Arrays.toString(ml.locateInTo(3, 11))); + + // we want 'greedy' mapping of base 12 to both peptides it codes for + assertEquals("[4, 5]", Arrays.toString(ml.locateInTo(12, 12))); + assertEquals("[4, 5]", Arrays.toString(ml.locateInTo(11, 12))); + assertEquals("[4, 6]", Arrays.toString(ml.locateInTo(11, 15))); + assertEquals("[6, 6]", Arrays.toString(ml.locateInTo(15, 17))); + + assertNull(ml.locateInTo(0, 0)); + assertNull(ml.locateInTo(1, 18)); + assertNull(ml.locateInTo(-1, 1)); + } } -- 1.7.10.2