X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FViewportRangesTest.java;h=851b1b7173961e3f7af3fbbf224a2a85ae961663;hb=182059d079ef2563d139ab1f0721c466cd648c02;hp=86f0d62caeb891cc7bd1818337a427f2437a5c46;hpb=4eac8fc13cf64f8d43ac807d10aff15aeafd355c;p=jalview.git diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java index 86f0d62..851b1b7 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; @@ -12,6 +13,7 @@ import jalview.datamodel.HiddenSequences; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.testng.annotations.BeforeClass; @@ -346,17 +348,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 @@ -509,9 +535,16 @@ public class ViewportRangesTest { Arrays.asList("startseq", "startseq", "startseq", "startseq"))); l.reset(); - vr.scrollToWrappedVisible(5); - assertTrue(l.verify(1, Arrays.asList("startres"))); + /* + * scrollToWrappedVisible does nothing if the target position is + * within the current startRes-endRes range + */ + assertFalse(vr.scrollToWrappedVisible(5)); + assertTrue(l.verify(0, Collections. emptyList())); l.reset(); + + vr.scrollToWrappedVisible(25); + assertTrue(l.verify(1, Arrays.asList("startres"))); } @Test(groups = { "Functional" }) @@ -699,6 +732,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