X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FViewportRangesTest.java;h=74cd8f9afb0d4c8369770e8b0bf647e57df2e013;hb=2066caec85bf0b332d924472fcfdbdaa07f56f1e;hp=86f0d62caeb891cc7bd1818337a427f2437a5c46;hpb=4eac8fc13cf64f8d43ac807d10aff15aeafd355c;p=jalview.git diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 86f0d62..74cd8f9 100644 --- a/test/jalview/viewmodel/ViewportRangesTest.java +++ b/test/jalview/viewmodel/ViewportRangesTest.java @@ -1,6 +1,7 @@ package jalview.viewmodel; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import jalview.analysis.AlignmentGenerator; @@ -346,17 +347,41 @@ public class ViewportRangesTest { @Test(groups = { "Functional" }) public void testScrollToWrappedVisible() { - ViewportRanges vr = new ViewportRanges(al); + AlignmentI al2 = gen.generate(60, 30, 1, 5, 5); + + ViewportRanges vr = new ViewportRanges(al2); + + // start with viewport on 5-14 vr.setViewportStartAndWidth(5, 10); + assertEquals(vr.getStartRes(), 5); + assertEquals(vr.getEndRes(), 14); + + // scroll to 12 - no change + assertFalse(vr.scrollToWrappedVisible(12)); + assertEquals(vr.getStartRes(), 5); - vr.scrollToWrappedVisible(0); + // scroll to 2 - back to 0-9 + assertTrue(vr.scrollToWrappedVisible(2)); assertEquals(vr.getStartRes(), 0); + assertEquals(vr.getEndRes(), 9); - vr.scrollToWrappedVisible(10); - assertEquals(vr.getStartRes(), 10); + // scroll to 9 - no change + assertFalse(vr.scrollToWrappedVisible(9)); + assertEquals(vr.getStartRes(), 0); - vr.scrollToWrappedVisible(15); + // scroll to 12 - moves to 10-19 + assertTrue(vr.scrollToWrappedVisible(12)); assertEquals(vr.getStartRes(), 10); + assertEquals(vr.getEndRes(), 19); + + vr.setStartRes(13); + assertEquals(vr.getStartRes(), 13); + assertEquals(vr.getEndRes(), 22); + + // scroll to 45 - jumps to 43-52 + assertTrue(vr.scrollToWrappedVisible(45)); + assertEquals(vr.getStartRes(), 43); + assertEquals(vr.getEndRes(), 52); } // leave until JAL-2388 is merged and we can do without viewport @@ -699,6 +724,37 @@ public class ViewportRangesTest { assertEquals(vrsmall.getViewportWidth(), 7); assertEquals(vrsmall.getStartRes(), 0); } + + @Test(groups = { "Functional" }) + public void testGetWrappedMaxScroll() + { + // generate an ungapped alignment of width 140 + int alignmentWidth = 140; + AlignmentI al2 = gen.generate(alignmentWidth, 15, 1, 0, 5); + ViewportRanges vr = new ViewportRanges(al2); + vr.setStartEndRes(0, 39); + int width = vr.getViewportWidth(); // 40 + int partWidth = alignmentWidth % width; // 20 + + /* + * there are 3 * 40 remainder 20 residues + * number of widths depends on offset (scroll right) + * 4 widths (maxScroll = 3) if offset by 0 or more than 19 columns + * 5 widths (maxScroll = 4) if 1 <= offset <= 19 + */ + for (int col = 0; col < alignmentWidth; col++) + { + int offset = col % width; + if (offset > 0 && offset < partWidth) + { + assertEquals(vr.getWrappedMaxScroll(col), 4, "col " + col); + } + else + { + assertEquals(vr.getWrappedMaxScroll(col), 3, "col " + col); + } + } + } } // mock listener for property change events