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;
@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
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