From: gmungoc Date: Wed, 2 Dec 2020 20:37:16 +0000 (+0000) Subject: JAL-3751 second occurrence of bug squashed X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fbug%2FJAL-3751_revisited;p=jalview.git JAL-3751 second occurrence of bug squashed --- diff --git a/src/jalview/util/MapList.java b/src/jalview/util/MapList.java index 745f367..6b65713 100644 --- a/src/jalview/util/MapList.java +++ b/src/jalview/util/MapList.java @@ -960,15 +960,6 @@ public class MapList boolean newForward = range[1] >= range[0]; /* - * contiguous range in the same direction - just update endpoint - */ - if (lastForward == newForward && last[1] == range[0]) - { - last[1] = range[1]; - return; - } - - /* * next range starts at +1 in forward sense - update endpoint */ if (lastForward && newForward && range[0] == last[1] + 1) diff --git a/test/jalview/util/MapListTest.java b/test/jalview/util/MapListTest.java index cf10aba..ff3488f 100644 --- a/test/jalview/util/MapListTest.java +++ b/test/jalview/util/MapListTest.java @@ -661,7 +661,15 @@ public class MapListTest MapList ml2 = new MapList(new int[] { 15, 16 }, new int[] { 58, 53 }, 1, 3); ml.addMapList(ml2); - assertEquals("[ [11, 16] ] 1:3 to [ [72, 53] ]", ml.toString()); + assertEquals("[ [11, 15] [15, 16] ] 1:3 to [ [72, 58] [58, 53] ]", ml.toString()); + + MapList ml3 = new MapList(new int[] { 11, 15 }, new int[] { 72, 58 }, 1, + 3); + + MapList ml4 = new MapList(new int[] { 15, 16 }, new int[] { 1, 6 }, 1, + 3); + ml3.addMapList(ml4); + assertEquals("[ [11, 15] [15, 16] ] 1:3 to [ [72, 58] [1, 6] ]", ml3.toString()); } @Test(groups = "Functional") @@ -675,47 +683,51 @@ public class MapListTest assertEquals(1, ranges.size()); assertSame(range, ranges.get(0)); - // extend contiguous (same position): + // extend overlapping (same position): MapList.addRange(new int[] { 5, 10 }, ranges); - assertEquals(1, ranges.size()); + assertEquals(2, ranges.size()); assertEquals(1, ranges.get(0)[0]); - assertEquals(10, ranges.get(0)[1]); + assertEquals(5, ranges.get(0)[1]); + assertEquals(5, ranges.get(1)[0]); + assertEquals(10, ranges.get(1)[1]); // extend contiguous (next position): MapList.addRange(new int[] { 11, 15 }, ranges); - assertEquals(1, ranges.size()); + assertEquals(2, ranges.size()); assertEquals(1, ranges.get(0)[0]); - assertEquals(15, ranges.get(0)[1]); + assertEquals(5, ranges.get(0)[1]); + assertEquals(5, ranges.get(1)[0]); + assertEquals(15, ranges.get(1)[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]); + assertEquals(3, ranges.size()); + assertEquals(16, ranges.get(2)[0]); + assertEquals(10, ranges.get(2)[1]); - // extend reverse contiguous (same position): + // extend reverse overlapping (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]); + assertEquals(4, ranges.size()); + assertEquals(10, ranges.get(3)[0]); + assertEquals(8, ranges.get(3)[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]); + assertEquals(4, ranges.size()); + assertEquals(10, ranges.get(3)[0]); + assertEquals(6, ranges.get(3)[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]); + assertEquals(5, ranges.size()); + assertEquals(6, ranges.get(4)[0]); + assertEquals(9, ranges.get(4)[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]); + assertEquals(6, ranges.size()); + assertEquals(11, ranges.get(5)[0]); + assertEquals(12, ranges.get(5)[1]); } /**