From: gmungoc Date: Mon, 24 Apr 2017 11:19:41 +0000 (+0100) Subject: JAL-2424 final contig now an inclusive range X-Git-Tag: Release_2_10_2~3^2~114^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d54f8d3b0bf910b99991441485fd5d42acf1df7d;p=jalview.git JAL-2424 final contig now an inclusive range --- diff --git a/src/jalview/datamodel/AlignmentView.java b/src/jalview/datamodel/AlignmentView.java index 9db9f38..1e34036 100644 --- a/src/jalview/datamodel/AlignmentView.java +++ b/src/jalview/datamodel/AlignmentView.java @@ -970,14 +970,14 @@ public class AlignmentView if (start < fwidth) { viscontigs[nvis] = start; - viscontigs[nvis + 1] = fwidth; // end is inclusive + viscontigs[nvis + 1] = fwidth - 1; // end is inclusive nvis += 2; } return viscontigs; } else { - return new int[] { 0, width }; + return new int[] { 0, width - 1 }; } } diff --git a/test/jalview/datamodel/AlignmentViewTest.java b/test/jalview/datamodel/AlignmentViewTest.java index 594d6e6..b201c7e 100644 --- a/test/jalview/datamodel/AlignmentViewTest.java +++ b/test/jalview/datamodel/AlignmentViewTest.java @@ -22,7 +22,11 @@ package jalview.datamodel; import static org.testng.Assert.assertEquals; +import jalview.gui.AlignFrame; +import jalview.gui.AlignViewport; import jalview.gui.JvOptionPane; +import jalview.io.DataSourceType; +import jalview.io.FileLoader; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -50,4 +54,69 @@ public class AlignmentViewTest assertEquals(av.getVisibleAlignment('$').getSequenceAt(0) .getSequenceAsString(), "A$$CDE"); } + + @Test(groups = { "Functional" }) + public void testGetVisibleContigs() + { + AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( + ">s1\n0123456789\n", DataSourceType.PASTE); + AlignViewport av = af.getViewport(); + AlignmentView view = av.getAlignmentView(true); + + /* + * verify getVisibleContigs returns inclusive [start, end] ranges + * + * no columns hidden + */ + int[] contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 0, 9 }); + + /* + * hide 3 internal columns + */ + av.hideColumns(5, 7); + // the old AlignmentView is now stale! + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 0, 9 }); + // get a fresh AlignmentView + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 0, 4, 8, 9 }); + + // hide first 2 columns + av.hideColumns(0, 1); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 2, 4, 8, 9 }); + + // hide last column + av.hideColumns(9, 9); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 2, 4, 8, 8 }); + + // unhide columns 5-7 + av.showColumn(5); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 2, 8 }); + + // hide columns 2-7 + av.hideColumns(2, 7); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 8, 8 }); + + // hide column 8 + av.hideColumns(8, 8); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] {}); + + // unhide all + av.showAllHiddenColumns(); + view = av.getAlignmentView(true); + contigs = view.getVisibleContigs(); + assertEquals(contigs, new int[] { 0, 9 }); + } }