From: gmungoc Date: Tue, 4 Jul 2017 15:20:03 +0000 (+0100) Subject: JAL-147 unit tests added, unused setEndRes removed X-Git-Tag: Release_2_10_3b1~132^2~50 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=4eac8fc13cf64f8d43ac807d10aff15aeafd355c;p=jalview.git JAL-147 unit tests added, unused setEndRes removed --- diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index abbc24c..36ed984 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -135,9 +135,10 @@ public class ViewportRanges extends ViewportProperties /* * if not wrapped, don't leave white space at the right margin */ - if (!wrappedMode && (start > getVisibleAlignmentWidth() - 1)) + int lastColumn = getVisibleAlignmentWidth() - 1; + if (!wrappedMode && (start > lastColumn)) { - startRes = Math.max(getVisibleAlignmentWidth() - 1, 0); + startRes = Math.max(lastColumn, 0); } else if (start < 0) { @@ -153,9 +154,9 @@ public class ViewportRanges extends ViewportProperties { endRes = 0; } - else if (!wrappedMode && (end > getVisibleAlignmentWidth() - 1)) + else if (!wrappedMode && (end > lastColumn)) { - endRes = Math.max(getVisibleAlignmentWidth() - 1, 0); + endRes = Math.max(lastColumn, 0); } else { @@ -172,30 +173,6 @@ public class ViewportRanges extends ViewportProperties } /** - * Set last residue visible in the viewport. Fires a property change event. - * - * @param res - * residue position - */ - public void setEndRes(int res) - { - int startres = res; - int width = getViewportWidth(); - - /* - * if not wrapped, don't leave white space at the right margin - */ - if (!wrappedMode) - { - if (startres + width - 1 > getVisibleAlignmentWidth() - 1) - { - startres = getVisibleAlignmentWidth() - width; - } - } - setStartEndRes(startres - width + 1, startres); - } - - /** * Set the first sequence visible in the viewport, maintaining the height. If * the viewport would extend past the last sequence, sets the viewport so it * sits at the bottom of the alignment. Fires a property change event. diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 4c93d71..86f0d62 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -25,6 +26,14 @@ public class ViewportRangesTest { AlignmentI smallAl = gen.generate(7, 2, 2, 5, 5); + @BeforeClass(alwaysRun = true) + public void setUp() + { + gen = new AlignmentGenerator(false); + al = gen.generate(20, 30, 1, 5, 5); + smallAl = gen.generate(7, 2, 2, 5, 5); + } + @BeforeMethod(alwaysRun = true) public void cleanUp() { @@ -65,17 +74,6 @@ public class ViewportRangesTest { } @Test(groups = { "Functional" }) - public void testSetEndRes() - { - ViewportRanges vr = new ViewportRanges(al); - vr.setEndRes(-1); - assertEquals(vr.getEndRes(), 0); - - vr.setEndRes(al.getWidth() - 1); - assertEquals(vr.getEndRes(), al.getWidth() - 1); - } - - @Test(groups = { "Functional" }) public void testSetEndSeq() { ViewportRanges vr = new ViewportRanges(al); @@ -85,7 +83,8 @@ public class ViewportRangesTest { vr.setEndSeq(al.getHeight()); assertEquals(vr.getEndSeq(), al.getHeight() - 1); - vr.setEndRes(al.getHeight() - 1); + // vr.setEndRes(al.getHeight() - 1); + vr.setEndSeq(al.getHeight() - 1); assertEquals(vr.getEndSeq(), al.getHeight() - 1); } @@ -401,15 +400,6 @@ public class ViewportRangesTest { assertTrue(l.verify(0, emptylist)); l.reset(); - vr.setEndRes(10); - assertTrue(l.verify(1, Arrays.asList("startres"))); - l.reset(); - - // no event fired for same value - vr.setEndRes(10); - assertTrue(l.verify(0, emptylist)); - l.reset(); - vr.setStartSeq(4); assertTrue(l.verify(1, Arrays.asList("startseq"))); l.reset(); @@ -556,6 +546,159 @@ public class ViewportRangesTest { assertEquals(2, vr.getWrappedScrollPosition(i), "For " + i); } } + + @Test(groups = { "Functional" }) + public void testPageUpDownWrapped() + { + /* + * 15 sequences, 110 residues wide (+gaps) + */ + AlignmentI al2 = gen.generate(110, 15, 1, 5, 5); + + ViewportRanges vr = new ViewportRanges(al2); + vr.setWrappedMode(true); + + // first row + vr.setViewportStartAndWidth(0, 40); + int width = vr.getViewportWidth(); + assertEquals(width, 40); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 39); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // second row + vr.pageDown(); + assertEquals(vr.getStartRes(), 40); + assertEquals(vr.getEndRes(), 79); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // third and last row + // note endRes is nominal (>width) to preserve viewport width + vr.pageDown(); + assertEquals(vr.getStartRes(), 80); + assertEquals(vr.getEndRes(), 119); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // another pageDown should do nothing + vr.pageDown(); + assertEquals(vr.getStartRes(), 80); + assertEquals(vr.getEndRes(), 119); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // back to second row + vr.pageUp(); + assertEquals(vr.getStartRes(), 40); + assertEquals(vr.getEndRes(), 79); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // back to first row + vr.pageUp(); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 39); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + // another pageUp should do nothing + vr.pageUp(); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 39); + assertEquals(vr.getStartSeq(), 0); + assertEquals(vr.getEndSeq(), 14); + + /* + * simulate scroll right a few positions + */ + vr.setStartRes(5); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 5 + width - 1); // 44 + + vr.pageDown(); // 5-44 shifts to 45-84 + assertEquals(vr.getStartRes(), 45); + assertEquals(vr.getEndRes(), 84); + + vr.pageDown(); // 45-84 shifts to 85-124 + assertEquals(vr.getStartRes(), 85); + assertEquals(vr.getEndRes(), 124); + + vr.pageDown(); // no change - at end already + assertEquals(vr.getStartRes(), 85); + assertEquals(vr.getEndRes(), 124); + + vr.pageUp(); // back we go + assertEquals(vr.getStartRes(), 45); + assertEquals(vr.getEndRes(), 84); + + vr.pageUp(); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 44); + + vr.pageUp(); // back to the start + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 39); + } + + @Test(groups = { "Functional" }) + public void testSetStartEndResWrapped() + { + ViewportRanges vr = new ViewportRanges(al); + vr.setWrappedMode(true); + vr.setStartEndRes(-1, -1); + assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 0); + + vr.setStartEndRes(5, 19); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 19); + + // bounds are not constrained to alignment width + // when in wrapped mode + vr.setStartEndRes(88, 888); + assertEquals(vr.getStartRes(), 88); + assertEquals(vr.getEndRes(), 888); + + ViewportRanges vrsmall = new ViewportRanges(smallAl); + vrsmall.setWrappedMode(true); + vrsmall.setStartEndRes(88, 888); + assertEquals(vrsmall.getStartRes(), 88); + assertEquals(vrsmall.getEndRes(), 888); + + // make visible alignment width = 0 + smallAl.getHiddenColumns().hideColumns(0, 6); + vrsmall.setStartEndRes(0, 4); + assertEquals(vrsmall.getStartRes(), 0); + assertEquals(vrsmall.getEndRes(), 4); + } + + @Test(groups = { "Functional" }) + public void testSetViewportStartAndWidthWrapped() + { + ViewportRanges vr = new ViewportRanges(al); + vr.setWrappedMode(true); + vr.setViewportStartAndWidth(2, 6); + assertEquals(vr.getViewportWidth(), 6); + assertEquals(vr.getStartRes(), 2); + + // reset -ve values of start to 0 + vr.setViewportStartAndWidth(-1, 7); + assertEquals(vr.getViewportWidth(), 7); + assertEquals(vr.getStartRes(), 0); + + // out of bounds values are not forced to within bounds + vr.setViewportStartAndWidth(35, 5); + assertEquals(vr.getViewportWidth(), 5); + assertEquals(vr.getStartRes(), 35); + + // small alignment doesn't get bounds reset + ViewportRanges vrsmall = new ViewportRanges(smallAl); + vrsmall.setViewportStartAndWidth(0, 63); + assertEquals(vrsmall.getViewportWidth(), 7); + assertEquals(vrsmall.getStartRes(), 0); + } } // mock listener for property change events