JAL-147 corrected calculation of vertical scroll position and max
[jalview.git] / test / jalview / viewmodel / ViewportRangesTest.java
index 86f0d62..70a3687 100644 (file)
@@ -699,6 +699,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