JAL-2388 Unit tests and tidies
[jalview.git] / test / jalview / viewmodel / OverviewDimensionsTest.java
index 8ceadba..1ea07ea 100644 (file)
@@ -137,7 +137,7 @@ public class OverviewDimensionsTest
     ViewportPositionProps props = new ViewportPositionProps(al1);
 
     OverviewDimensions od = new OverviewDimensions(props, true);
-    int scaledHeight = 266;
+    int scaledHeight = 267;
     assertEquals(od.getGraphHeight(), defaultGraphHeight);
     assertEquals(od.getSequencesHeight(), scaledHeight);
     assertEquals(od.getWidth(), maxWidth);
@@ -225,7 +225,7 @@ public class OverviewDimensionsTest
 
     // overly large boxX value reset to width-boxWidth
     mouseClick(od, 100, 6);
-    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
+    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
     assertEquals(od.getBoxY(), 6);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
@@ -243,13 +243,17 @@ public class OverviewDimensionsTest
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(od.getScrollCol(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
+
+    // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
+    // and round rounds to 508; however we get 507 working with row values
+    // hence the subtraction of 1
     assertEquals(od.getScrollRow(),
             Math.round((float) od.getBoxY() * alheight
-                    / od.getSequencesHeight()));
+                    / od.getSequencesHeight()) - 1);
 
     // click past end of alignment, as above
     mouseClick(od, 3000, 5);
-    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
+    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(od.getScrollCol(),
@@ -313,7 +317,6 @@ public class OverviewDimensionsTest
     assertEquals(od.getBoxHeight(), boxHeight);
 
     // try to click in hidden cols, check box does not move
-    // this test currently fails as the overview box does not behave like this!
     int xpos = 10;
     mouseClick(od, xpos, 0);
     assertEquals(
@@ -339,7 +342,7 @@ public class OverviewDimensionsTest
     // overly large boxX value reset to width-boxWidth
     xpos = 100;
     mouseClick(od, xpos, 5);
-    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
+    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
     assertEquals(od.getBoxY(), 5);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
@@ -440,7 +443,7 @@ public class OverviewDimensionsTest
     // boxX, scrollCol adjusted back, box width normal
     xpos = 3000;
     mouseClick(od, xpos, 5);
-    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
+    assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
     assertEquals(od.getBoxY(), 5);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
@@ -492,44 +495,40 @@ public class OverviewDimensionsTest
     xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
     mouseClick(od, xpos, 0);
     assertEquals(od.getBoxX(),
-            Math.round((firstHidden - 1) * od.getWidth() / alwidth)
-                    - boxWidth);
+            Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
+                    - boxWidth + 1);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(od.getScrollCol(),
-            Math.round(od.getBoxX() * alwidth / od.getWidth()));
+            Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
     assertEquals(od.getScrollRow(), 0);
 
     // click in hidden cols
     // boxX and scrollCol adjusted for hidden cols, width normal
-    // TODO breaks as above test
-    /*xpos = 115;
-    assertEquals(
-            od.getBoxX(),
-            Math.round((firstHidden - 1) * scalew * av.getCharWidth())
-                    - od.getBoxWidth());
+    xpos = 115;
+    assertEquals(od.getBoxX(),
+            Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
+                    - boxWidth + 1);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(od.getScrollCol(),
-            Math.round(od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);*/
+            Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
+    assertEquals(od.getScrollRow(), 0);
 
     // click off end of alignment
     // boxX and scrollCol adjusted for hidden cols, width normal
-    // TODO breaks as above test
-    /*    xpos = 3000;
-        assertEquals(
-                od.getBoxX(),
-                Math.round((firstHidden - 1) * scalew * av.getCharWidth())
-                        - od.getBoxWidth());
-        assertEquals(od.getBoxY(), 0);
-        assertEquals(od.getBoxWidth(), boxWidth);
-        assertEquals(od.getBoxHeight(), boxHeight);
-        assertEquals(od.getScrollCol(),
-                Math.round(od.getBoxX() * alwidth / od.getWidth()));
-        assertEquals(od.getScrollRow(), 0);*/
+    xpos = 3000;
+    assertEquals(od.getBoxX(),
+            Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
+                    - boxWidth + 1);
+    assertEquals(od.getBoxY(), 0);
+    assertEquals(od.getBoxWidth(), boxWidth);
+    assertEquals(od.getBoxHeight(), boxHeight);
+    assertEquals(od.getScrollCol(),
+            Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
+    assertEquals(od.getScrollRow(), 0);
   }
 
   /**
@@ -683,7 +682,7 @@ public class OverviewDimensionsTest
             Math.round((float) 102 * od.getWidth() / alwidth));
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth
-                    + Math.round((float) (lastHidden - firstHidden)
+                    + Math.round((float) (lastHidden - firstHidden + 1)
                             * od.getWidth() / alwidth));
     assertEquals(od.getBoxHeight(), boxHeight);
   }
@@ -850,7 +849,7 @@ public class OverviewDimensionsTest
     // hide rows in middle and check updated box position is correct
     // no changes
     int firstHiddenRow = 50;
-    int lastHiddenRow = 60;
+    int lastHiddenRow = 54;
     hideSequences(firstHiddenRow, lastHiddenRow);
 
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
@@ -861,34 +860,32 @@ public class OverviewDimensionsTest
     assertEquals(od.getBoxHeight(), boxHeight);
 
     // click above hidden rows, so that box overlaps
-    int ypos = 40;
-    // TODO test fails because box does not change height - dealt with by scroll
-    // values
-    /*    mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
-        assertEquals(od.getBoxX(), 0);
-        assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
-                1.5);
-        assertEquals(od.getBoxWidth(), boxWidth);
-        assertEquals(
-                od.getBoxHeight(),
-                boxHeight
-                        + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
-                                .getCharHeight()));
-    */
+    int ypos = 35; // column value in residues
+    mouseClick(od, 0,
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
+    assertEquals(od.getBoxX(), 0);
+    assertEquals(od.getBoxY(),
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
+    assertEquals(od.getBoxWidth(), boxWidth);
+    assertEquals(
+            od.getBoxHeight(),
+            boxHeight
+                    + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
+                            * od.getSequencesHeight() / alheight));
+
     // click so that box straddles hidden rows
-    ypos = 48;
-    // TODO test fails because box does not change height - dealt with by scroll
-    // values
-    /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
+    ypos = 44; // column value in residues
+    mouseClick(od, 0,
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxX(), 0);
-    assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
-            1.5);
+    assertEquals(od.getBoxY(),
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(
             od.getBoxHeight(),
             boxHeight
-                    + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
-                            .getCharHeight()));*/
+                    + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
+                            * od.getSequencesHeight() / alheight));
   }
 
   /**
@@ -931,29 +928,28 @@ public class OverviewDimensionsTest
 
     // click above hidden rows so box overlaps
     // boxY moved upwards, boxHeight remains same
-    // TODO fails with boxY located at row 497 - correction done by
-    // setScrollValues
-    /*   ypos = 497; // row 497
-       mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
-       assertEquals(od.getBoxX(), 0);
-       assertEquals(
-               od.getBoxY(),
-               Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
-               1.5);
-       assertEquals(od.getBoxWidth(), boxWidth);
-       assertEquals(od.getBoxHeight(), boxHeight);*/
+    ypos = 497; // row 497
+    mouseClick(od, 0,
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
+    assertEquals(od.getBoxX(), 0);
+    assertEquals(
+            od.getBoxY(),
+            Math.round((float) (firstHidden - viewHeight)
+                    * od.getSequencesHeight() / alheight));
+    assertEquals(od.getBoxWidth(), boxWidth);
+    assertEquals(od.getBoxHeight(), boxHeight);
 
     // click within hidden rows
     ypos = 505;
-    // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
-    /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
+    mouseClick(od, 0,
+            Math.round((float) ypos * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxX(), 0);
     assertEquals(
             od.getBoxY(),
-            Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
-            1.5);
+            Math.round((firstHidden - viewHeight) * od.getSequencesHeight()
+                    / alheight));
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getBoxHeight(), boxHeight);*/
+    assertEquals(od.getBoxHeight(), boxHeight);
   }
 
   /*