X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FMappingUtilsTest.java;h=9239ba596269f43cb57c3468a584e3a055b84346;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=d0269d869b66ec468c8e8631f9610f38a9f33baf;hpb=7c1fb6e8bb8c267d38b15f0b80c9a2b5e53cde4b;p=jalview.git diff --git a/test/jalview/util/MappingUtilsTest.java b/test/jalview/util/MappingUtilsTest.java index d0269d8..9239ba5 100644 --- a/test/jalview/util/MappingUtilsTest.java +++ b/test/jalview/util/MappingUtilsTest.java @@ -22,9 +22,10 @@ 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.AssertJUnit.fail; +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import java.awt.Color; import java.io.IOException; @@ -37,7 +38,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import jalview.api.AlignViewportI; -import jalview.bin.Cache; +import jalview.bin.Console; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; @@ -58,14 +59,14 @@ import jalview.io.FileFormat; import jalview.io.FileFormatI; import jalview.io.FormatAdapter; + public class MappingUtilsTest { @BeforeClass(alwaysRun = true) public void setUp() { - Cache.initLogger(); + Console.initLogger(); } - @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() @@ -1329,41 +1330,32 @@ public class MappingUtilsTest assertEquals(1, ranges.size()); assertEquals(9, ranges.get(0)[1]); } - + @Test(groups = "Functional") - public void testListToArray() + public void testFindOverlap() { List ranges = new ArrayList<>(); - - int[] result = MappingUtils.listToArray(ranges); - assertEquals(result.length, 0); - ranges.add(new int[] {24, 12}); - result = MappingUtils.listToArray(ranges); - assertEquals(result.length, 2); - assertEquals(result[0], 24); - assertEquals(result[1], 12); - ranges.add(new int[] {-7, 30}); - result = MappingUtils.listToArray(ranges); - assertEquals(result.length, 4); - assertEquals(result[0], 24); - assertEquals(result[1], 12); - assertEquals(result[2], -7); - assertEquals(result[3], 30); - try - { - MappingUtils.listToArray(null); - fail("Expected exception"); - } catch (NullPointerException e) - { - // expected - } + 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); } /** * Test mapping a sequence group where sequences in and outside the group * share a dataset sequence (e.g. alternative CDS for the same gene) *

- * This scenario doesn't arise after JAL-3763 changes, but test left as still valid + * This scenario doesn't arise after JAL-3763 changes, but test left as still + * valid + * * @throws IOException */ @Test(groups = { "Functional" }) @@ -1459,4 +1451,59 @@ public class MappingUtilsTest assertEquals(0, mappedGroup.getStartRes()); assertEquals(1, mappedGroup.getEndRes()); // two columns } + + // new for 2.12 + @Test(groups = "Functional") + public void testAddRange() + { + int[] range = { 1, 5 }; + List ranges = new ArrayList<>(); + + // add to empty list: + MappingUtils.addRange(range, ranges); + assertEquals(1, ranges.size()); + assertSame(range, ranges.get(0)); + + // extend contiguous (same position): + MappingUtils.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): + MappingUtils.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: + MappingUtils.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): + MappingUtils.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): + MappingUtils.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: + MappingUtils.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 + MappingUtils.addRange(new int[] { 11, 12 }, ranges); + assertEquals(4, ranges.size()); + assertEquals(11, ranges.get(3)[0]); + assertEquals(12, ranges.get(3)[1]); + } }