From 4a3198610bf947684199326eeb41fefa0a74d9e4 Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 13 Jul 2017 15:52:20 +0100 Subject: [PATCH] JAL-2613 Unit tests and a fix. Phew. --- src/jalview/datamodel/HiddenSequences.java | 2 +- .../viewmodel/OverviewDimensionsHideHidden.java | 3 - .../viewmodel/OverviewDimensionsShowHidden.java | 7 +- .../OverviewDimensionsShowHiddenTest.java | 141 +++++++++----------- 4 files changed, 68 insertions(+), 85 deletions(-) diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index a98b10e..ed07290 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -310,7 +310,7 @@ public class HiddenSequences return startRow - visibleDistance; } - int index = startRow; + int index = Math.min(startRow, hiddenSequences.length - 1); int count = 0; while ((index > -1) && (count < visibleDistance)) { diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index fe20195..c5ce19b 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -73,9 +73,6 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions // Convert y value to sequence position // - // convert y to residues - // int yAsSeq = Math.round((float) y * alheight / sequencesHeight); - // get viewport height in sequences // add 1 because height includes both endSeq and startSeq int vpheight = ranges.getViewportHeight(); diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index be69db9..1bd96ab 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -212,15 +212,14 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden) { int vpx = Math.round((float) mousex * alwidth / width); - return hidden.findColumnPosition(hidden.subtractVisibleColumns( - ranges.getViewportWidth() / 2, vpx)); + return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2, + vpx); } @Override protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) { int vpy = Math.round((float) mousey * alheight / sequencesHeight); - return hidden.findIndexWithoutHiddenSeqs(hidden.subtractVisibleRows( - ranges.getViewportHeight() / 2, vpy)); + return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy); } } diff --git a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java index fef7548..7b4c65c 100644 --- a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java @@ -236,18 +236,18 @@ public class OverviewDimensionsShowHiddenTest // overly large boxY value reset to sequenceHeight - boxHeight mouseClick(od, 10, 520); - assertEquals(od.getBoxX(), 10); + assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, + assertEquals(0, 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( - vpranges.getStartSeq() + vpranges.getViewportWidth() / 2, + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1); @@ -256,28 +256,29 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); assertEquals( - vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); // move viewport so startRes non-zero and then mouseclick - moveViewportH(50); + moveViewportH(20); // click at viewport position int oldboxx = od.getBoxX(); int oldboxy = od.getBoxY(); - mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2); - assertEquals(od.getBoxX(), oldboxx + 5); + mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6, + od.getBoxY() + od.getBoxHeight() / 2 + 3); + assertEquals(od.getBoxX(), oldboxx + 6); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes() + vpranges.getViewportWidth() / 2, + assertEquals(vpranges.getStartRes(), Math.round((float) od.getBoxX() * alwidth / od.getWidth())); - assertEquals(od.getBoxY(), oldboxy + 2); + assertEquals(od.getBoxY(), oldboxy + 3); assertEquals( - vpranges.getStartSeq() + vpranges.getViewportHeight() / 2, + vpranges.getStartSeq(), Math.round((float) od.getBoxY() * alheight / od.getSequencesHeight())); @@ -331,10 +332,15 @@ public class OverviewDimensionsShowHiddenTest assertEquals(vpranges.getStartRes(), 0); // click to right of hidden columns, box moves to click point - testBoxIsAtClickPoint(40, 0); + mouseClick(od, 60 + boxWidth / 2, boxHeight / 2); + assertEquals(od.getBoxX(), 60); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartSeq(), 0); assertEquals(vpranges.getStartRes(), - Math.round((float) 40 * alwidth / od.getWidth()) + Math.round( + (float) 60 * alwidth / od.getWidth()) - (lastHiddenCol + 1)); // click to right of hidden columns such that box runs over right hand side @@ -342,7 +348,7 @@ public class OverviewDimensionsShowHiddenTest // box position is adjusted away from the edge // overly large boxX value reset to width-boxWidth xpos = 100; - mouseClick(od, xpos, 5); + mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); @@ -384,10 +390,10 @@ public class OverviewDimensionsShowHiddenTest // move box so that it overlaps with hidden cols on one side // box width changes, boxX and scrollCol as for unhidden case - int xpos = 55 - boxWidth; // 55 is position in overview approx halfway + int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway // between cols 60 and 70 - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos); + mouseClick(od, xpos, boxHeight / 2); + assertEquals(od.getBoxX(), xpos - boxWidth / 2); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), @@ -395,14 +401,15 @@ public class OverviewDimensionsShowHiddenTest * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartRes(), - Math.round(xpos * alwidth / od.getWidth())); + Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth()) + + 1); // +1 for rounding assertEquals(vpranges.getStartSeq(), 0); // move box so that it completely covers hidden cols // box width changes, boxX and scrollCol as for hidden case - xpos = 33; + xpos = 24 + boxWidth / 2; mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos); + assertEquals(od.getBoxX(), 24); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), @@ -410,42 +417,28 @@ public class OverviewDimensionsShowHiddenTest * od.getWidth() / alwidth)); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartRes(), - Math.round((float) xpos * alwidth / od.getWidth())); - assertEquals(vpranges.getStartSeq(), 0); - - // move box so boxX is in hidden cols, box overhangs at right - // boxX and scrollCol at left of hidden area, box width extends across - // hidden region - xpos = 50; - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), - Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)); - assertEquals(od.getBoxY(), 0); - assertEquals( - od.getBoxWidth(), - boxWidth - + Math.round((float) (lastHidden - firstHidden + 1) - * od.getWidth() / alwidth)); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(vpranges.getStartRes(), firstHidden - 1); + Math.round((float) 24 * alwidth / od.getWidth())); assertEquals(vpranges.getStartSeq(), 0); // move box so boxX is to right of hidden cols, but does not go beyond full // width of alignment // box width, boxX and scrollCol all as for non-hidden case - xpos = 75; - testBoxIsAtClickPoint(xpos, 0); + xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2; + mouseClick(od, xpos, boxHeight / 2); + assertEquals(od.getBoxX(), xpos - boxWidth / 2); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartSeq(), 0); assertEquals(vpranges.getStartRes(), - Math.round(xpos * alwidth / od.getWidth()) - - (lastHidden - firstHidden + 1)); + 75 - (lastHidden - firstHidden + 1)); // move box so it goes beyond full width of alignment // boxX, scrollCol adjusted back, box width normal xpos = 3000; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); - assertEquals(od.getBoxY(), 5); + assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals( @@ -486,24 +479,29 @@ public class OverviewDimensionsShowHiddenTest // click to left of hidden cols, without overlapping // boxX, scrollCol and width as normal - int xpos = 5; - testBoxIsAtClickPoint(xpos, 0); - assertEquals(vpranges.getStartSeq(), 0); - assertEquals(vpranges.getStartRes(), - Math.round((float) xpos * alwidth / od.getWidth())); + int xpos = 30; + int ypos = 6; + testBoxIsAtClickPoint(xpos, ypos); + assertEquals(vpranges.getStartSeq(), Math + .round((float) (ypos - boxHeight / 2) * alheight + / od.getHeight())); + assertEquals(vpranges.getStartRes(), Math.round( + (float) (xpos - boxWidth / 2) * alwidth / od.getWidth())); // click to left of hidden cols, with overlap // boxX and scrollCol adjusted for hidden cols, width normal xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth; - mouseClick(od, xpos, 0); + mouseClick(od, xpos + boxWidth / 2, boxHeight / 2); assertEquals(od.getBoxX(), - Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth) + Math.round((float) (firstHidden - 1) + * od.getWidth() / alwidth) - boxWidth + 1); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(vpranges.getStartRes(), - Math.round((float) od.getBoxX() * alwidth / od.getWidth())); + Math.round((float) (od.getBoxX()) * alwidth + / od.getWidth())); assertEquals(vpranges.getStartSeq(), 0); // click in hidden cols @@ -822,7 +820,7 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxHeight(), boxHeight); // click below hidden rows - mouseClick(od, 0, 150); + mouseClick(od, 0, 150 + boxHeight/2); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 150); assertEquals(od.getBoxWidth(), boxWidth); @@ -859,26 +857,15 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows, so that box overlaps - 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 = 44; // column value in residues + int rowpos = 35; // row value in residues + int centrepos = 43; // centre row mouseClick(od, 0, - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + Math.round((float) centrepos * od.getSequencesHeight() + / alheight)); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + Math.round( + (float) rowpos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals( od.getBoxHeight(), @@ -914,19 +901,19 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // click above hidden rows - int ypos = 40; // row 40 + // click above hidden rows, no overlap + int ypos = 40 + viewHeight / 2; // top is row 40 mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), - Math.round((float) ypos * od.getSequencesHeight() / alheight)); + Math.round((float) 40 * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows so box overlaps // boxY moved upwards, boxHeight remains same - ypos = 497; // row 497 + ypos = 497 + viewHeight / 2; // row 497 mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); @@ -938,7 +925,7 @@ public class OverviewDimensionsShowHiddenTest assertEquals(od.getBoxHeight(), boxHeight); // click within hidden rows - ypos = 505; + ypos = 505 + boxHeight / 2; mouseClick(od, 0, Math.round((float) ypos * od.getSequencesHeight() / alheight)); assertEquals(od.getBoxX(), 0); @@ -992,14 +979,14 @@ public class OverviewDimensionsShowHiddenTest } /* - * Test that the box is positioned with the top left corner at xpos, ypos + * Test that the box is positioned with the centre at xpos, ypos * and with the original width and height */ private void testBoxIsAtClickPoint(int xpos, int ypos) { mouseClick(od, xpos, ypos); - assertEquals(od.getBoxX(), xpos); - assertEquals(od.getBoxY(), ypos); + assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos); + assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); -- 1.7.10.2