From: kiramt Date: Tue, 7 Mar 2017 14:27:58 +0000 (+0000) Subject: JAL-2388 Additional unit tests X-Git-Tag: Release_2_10_2~3^2~92^2~47 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1f015ae6034c51f7e7ab619fe428943899755d1c;p=jalview.git JAL-2388 Additional unit tests --- diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 34b7aff..1f18a10 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -193,7 +193,7 @@ public class OverviewDimensions int yAsSeq = Math.round((float) y * alheight / sequencesHeight); // get viewport height in sequences - int vpheight = props.getEndSeq() - props.getStartSeq(); + int vpheight = props.getEndSeq() - props.getStartSeq() + 1; // get where y should be when accounting for hidden rows // if y is in a hidden row region, shift up - but we still need absolute @@ -211,7 +211,7 @@ public class OverviewDimensions // went past the end of the alignment, adjust backwards endSeq = alheight; // recalc yAsSeq backwards from endSeq - yAsSeq = endSeq - vpheight; + yAsSeq = endSeq - vpheight + 1; } // convert absolute positions back to visible alignment positions for @@ -253,7 +253,8 @@ public class OverviewDimensions boxWidth = Math .round((float) (endRes - startRes + 1) * width / alwidth); // boxHeight is the height in sequences translated to pixels - boxHeight = Math.round((float) (endSeq - startSeq) * sequencesHeight + boxHeight = Math.round((float) (endSeq - startSeq + 1) + * sequencesHeight / alheight); } diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index be8154c..d9d7546 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -23,7 +23,6 @@ package jalview.viewmodel; import static org.testng.Assert.assertEquals; import jalview.analysis.AlignmentGenerator; -import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; @@ -70,10 +69,10 @@ public class OverviewDimensionsTest { AlignFrame af; AlignViewport av; - AlignmentI al; OverviewDimensions od; + // cached widths and heights int boxWidth; int boxHeight; int viewHeight; @@ -98,8 +97,6 @@ public class OverviewDimensionsTest { Jalview.main(new String[] { "-nonews", "-props", "test/jalview/testProps.jvprops" }); - Cache.applicationProperties.setProperty("SHOW_IDENTITY", - Boolean.TRUE.toString()); af = new FileLoader().LoadFileWaitTillLoaded(al.toString(), DataSourceType.PASTE); @@ -138,11 +135,6 @@ public class OverviewDimensionsTest { od.setBoxPosition(av.getAlignment() .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); - init(); - } - - private void init() - { av.showAllHiddenColumns(); av.showAllHiddenSeqs(); av.setSelectionGroup(null); @@ -174,6 +166,7 @@ public class OverviewDimensionsTest { try { Thread.sleep(50); + av.getAlignPanel().setScrollValues(0, 0); viewHeight = av.getEndSeq() - av.getStartSeq(); viewWidth = av.getEndRes() - av.getStartRes(); } catch (InterruptedException e) @@ -424,17 +417,18 @@ public class OverviewDimensionsTest { // 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(od.getBoxX(), - Math.round ((lastHiddenCol + 1) * od.getWidth() / alwidth)); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round (xpos * alwidth / od.getWidth())); - */ + int xpos = 10; + mouseClick(od, xpos, 0); + assertEquals( + od.getBoxX(), + Math.round((float) (lastHiddenCol + 1) * od.getWidth() + / alwidth)); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); + assertEquals(od.getScrollRow(), 0); + assertEquals(od.getScrollCol(), 0); + // click to right of hidden columns, box moves to click point testBoxIsAtClickPoint(40, 0); assertEquals(od.getScrollRow(), 0); @@ -446,7 +440,7 @@ public class OverviewDimensionsTest { // of alignment // box position is adjusted away from the edge // overly large boxX value reset to width-boxWidth - int xpos = 100; + xpos = 100; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); assertEquals(od.getBoxY(), 5); @@ -476,7 +470,7 @@ public class OverviewDimensionsTest { assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); - // hide columns 60-68, no change to box position or dimensions + // hide columns 63-73, no change to box position or dimensions int firstHidden = 63; int lastHidden = 73; hideColumns(firstHidden, lastHidden); @@ -521,35 +515,31 @@ public class OverviewDimensionsTest { assertEquals(od.getScrollRow(), 0); // move box so boxX is in hidden cols, box overhangs at right - // box width back to normal, boxX and scrollCol move to right of hidden area - // TODO currently this test fails in the Jalview GUI, there is a gap between - // the rhs of the hidden area and the box - /* xpos = 50; - mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), - (lastHidden + 1) * scalew * av.getCharWidth()); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth())); - assertEquals(od.getScrollRow(), 0);*/ + // 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(od.getScrollCol(), firstHidden - 1); + assertEquals(od.getScrollRow(), 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 - // TODO currently this test fails in the Jalview GUI because boxX is - // calculated - // based on the current boxWidth, which includes hidden columns, thereby - // pushing - // the box off the end of the alignment. So boxX is adjusted backwards - // unnecessarily. - /* xpos = 72; - testBoxIsAtClickPoint(xpos, 0); - assertEquals(od.getScrollRow(), 0); - assertEquals(od.getScrollCol(), - Math.round(xpos * alwidth / od.getWidth()) - - lastHidden);*/ + xpos = 75; + testBoxIsAtClickPoint(xpos, 0); + assertEquals(od.getScrollRow(), 0); + assertEquals(od.getScrollCol(), + Math.round(xpos * alwidth / od.getWidth()) + - (lastHidden - firstHidden + 1)); // move box so it goes beyond full width of alignment // boxX, scrollCol adjusted back, box width normal @@ -584,9 +574,9 @@ public class OverviewDimensionsTest { assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); - // hide columns 140-157, no change to box position or dimensions + // hide columns 140-164, no change to box position or dimensions int firstHidden = 140; - int lastHidden = 157; + int lastHidden = 164; hideColumns(firstHidden, lastHidden); od.setBoxPosition(av.getAlignment() .getHiddenSequences(), av.getColumnSelection(), av.getPosProps()); @@ -606,21 +596,19 @@ public class OverviewDimensionsTest { // click to left of hidden cols, with overlap // boxX and scrollCol adjusted for hidden cols, width normal - // TODO this fails because setBoxPosition screws up the hidden cols calc - // only works in GUI because of AlignmentPanel::setScrollValues - /*xpos = 115 - boxWidth; - mouseClick(od, xpos, 0); - 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 = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth; + mouseClick(od, xpos, 0); + assertEquals( + od.getBoxX(), + Math.round((firstHidden - 1) * od.getWidth() / alwidth) + - boxWidth); + 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); + */ // click in hidden cols // boxX and scrollCol adjusted for hidden cols, width normal // TODO breaks as above test @@ -830,22 +818,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // move viewport to end of alignment, need to account for hidden rows - // because of how alignment panel/overview panel are implemented - - // AlignViewport adjusts endSeq using Alignment height which excludes hidden - // rows if we happen to be at the bottom of the alignment - // od.setBoxPosition adjusts endSeq to include hidden rows - // od.checkValid adjusts scroll position to exclude hidden rows - // TODO this test fails because of the above! - - /* moveViewport(0, 525 - viewHeight - lastHidden - 1); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - (525 - viewHeight) * scaleh - * av.getCharHeight()); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight);*/ + // move viewport to end of alignment + moveViewport(0, 525 - viewHeight - lastHidden - 1); + assertEquals(od.getBoxX(), 0); + assertEquals( + od.getBoxY(), + Math.round((float) (525 - viewHeight) * od.getSequencesHeight() + / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -861,23 +842,22 @@ public class OverviewDimensionsTest { // move viewport to start of alignment: // box, height etc as in non-hidden case - // TODO fails with boxy=12 because that's what setBoxPosition sets it to! - /*moveViewport(0, 0); + moveViewport(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight);*/ + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to straddle hidden rows - // TODO also fails with boxY out by 12 - /*moveViewport(0, 198); + moveViewport(0, 198); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()), - 1.5); + assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight() + / alheight)); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight - + ((lastHidden - firstHidden) * scaleh * av.getCharHeight()), - 1.5);*/ + + Math.round((float) (lastHidden - firstHidden + 1) + * od.getSequencesHeight() + / alheight)); } /** @@ -900,18 +880,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxHeight(), boxHeight); // move viewport to end of alignment - // TODO fails with wrong boxHeight who knows why - /*moveViewport(0, firstHidden - viewHeight - 1); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), - Math.round ((firstHidden - viewHeight - 1) - * scaleh * av.getCharHeight())); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals( - od.getBoxHeight(), - boxHeight - + Math.round ((lastHidden - firstHidden + 1) * scaleh * av - .getCharHeight()));*/ + // viewport sits above hidden rows and does not include them + moveViewport(0, firstHidden - viewHeight - 1); + assertEquals(od.getBoxX(), 0); + assertEquals( + od.getBoxY(), + Math.round((float) (firstHidden - viewHeight - 1) + * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } @@ -946,15 +923,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - // click in hidden rows - // TODO fails because boxHeight is 27 not 25 (possible rounding issue) - /* mouseClick(od, 0, 0); - assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth); - assertEquals(od.getBoxHeight(), boxHeight - + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()), - 1.5);*/ + // click in hidden rows - same result + mouseClick(od, 0, 0); + assertEquals(od.getBoxX(), 0); + assertEquals( + od.getBoxY(), + Math.round((float) (lastHiddenRow + 1) + * od.getSequencesHeight() / alheight)); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // click below hidden rows mouseClick(od, 0, 150);