From 0b9e5a86abed6dc95e11b4e9a58031b3b350780a Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 28 Feb 2017 14:48:56 +0000 Subject: [PATCH] JAL-2388 Removing sources of non-determinism in unit tests --- test/jalview/viewmodel/OverviewDimensionsTest.java | 347 +++++++++++++------- 1 file changed, 224 insertions(+), 123 deletions(-) diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java index 7c40fe9..94fb83f 100644 --- a/test/jalview/viewmodel/OverviewDimensionsTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -37,11 +37,12 @@ import jalview.io.FileLoader; import java.util.List; -import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +@Test(singleThreaded = true) public class OverviewDimensionsTest { boolean showConservationSetting; @@ -84,7 +85,7 @@ public class OverviewDimensionsTest { JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } - @BeforeClass(alwaysRun = true) + @BeforeMethod(alwaysRun = true) public void setUp() { Jalview.main(new String[] { "-nonews", "-props", @@ -112,29 +113,64 @@ public class OverviewDimensionsTest { } } + /* + * wait for Consensus thread to complete + */ + synchronized (this) + { + while (af.getViewport().getConsensusSeq() == null) + { + try + { + wait(50); + } catch (InterruptedException e) + { + } + } + } + // get cached setting for showConservation // reset it in AfterClass! showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true); av = af.getViewport(); + + if (av.isCalcInProgress()) + { + + } + od = new OverviewDimensions(av); + while (av.isCalcInProgress()) + { + try + { + Thread.sleep(50); + } catch (InterruptedException e) + { + System.out.println("Hiding cols interruption"); + } + } + // Initial box sizing - default path through code od.setBoxPosition(); + scalew = (float) od.getWidth() / (av.getAlignment().getWidth() * av.getCharWidth()); scaleh = (float) od.getSequencesHeight() / (av.getAlignment().getHeight() * av.getCharHeight()); - boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) + boxWidth = Math.round((av.getEndRes() - av.getStartRes() + 1) * av.getCharWidth() * scalew); - boxHeight = (int) ((av.getEndSeq() - av.getStartSeq()) + boxHeight = Math.round((av.getEndSeq() - av.getStartSeq()) * av.getCharHeight() * scaleh); viewHeight = av.getEndSeq() - av.getStartSeq(); + + init(); } - @BeforeMethod(alwaysRun = true) - public void init() + private void init() { av.showAllHiddenColumns(); av.showAllHiddenSeqs(); @@ -142,11 +178,23 @@ public class OverviewDimensionsTest { // o/w hidden seqs retain selection group, causes problems later when hiding // sequences + // wait for conservation calc to complete + while (av.isCalcInProgress()) + { + try + { + Thread.sleep(50); + } catch (InterruptedException e) + { + + } + } + mouseClick(od, 0, 0); moveViewport(0, 0); } - @AfterClass(alwaysRun = true) + @AfterMethod(alwaysRun = true) public void tearDown() { Cache.applicationProperties.setProperty("SHOW_CONSERVATION", @@ -270,7 +318,7 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollRow(), - (int) (10 / scaleh / av.getCharHeight())); + Math.round(10 / scaleh / av.getCharHeight())); assertEquals(od.getScrollCol(), 0); // negative boxY value reset to 0 @@ -278,7 +326,8 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), (int) (6 / scalew / av.getCharWidth())); + assertEquals(od.getScrollCol(), + Math.round(6 / scalew / av.getCharWidth())); assertEquals(od.getScrollRow(), 0); // overly large boxX value reset to width-boxWidth @@ -357,32 +406,34 @@ public class OverviewDimensionsTest { // hide cols at start and check updated box position is correct // changes boxX but not boxwidth int lastHiddenCol = 30; - av.hideColumns(0, lastHiddenCol); + hideColumns(0, lastHiddenCol); + od.setBoxPosition(); assertEquals(od.getBoxX(), - (int) ((lastHiddenCol + 1) * scalew * av.getCharWidth())); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + Math.round((lastHiddenCol + 1) * scalew * av.getCharWidth())); + assertEquals(od.getBoxWidth(), boxWidth); + 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(od.getBoxX(), - (int) ((lastHiddenCol + 1) * scalew * av.getCharWidth())); + Math.round ((lastHiddenCol + 1) * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollRow(), 0); assertEquals(od.getScrollCol(), - (int) (xpos / scalew / av.getCharWidth())); + Math.round (xpos / scalew / av.getCharWidth())); */ // click to right of hidden columns, box moves to click point testBoxIsAtClickPoint(40, 0); assertEquals(od.getScrollRow(), 0); assertEquals(od.getScrollCol(), - (int) (40 / scalew / av.getCharWidth()) - - lastHiddenCol, 1.5); + Math.round(40 / scalew / av.getCharWidth()) + - lastHiddenCol, + 1.5); // click to right of hidden columns such that box runs over right hand side // of alignment @@ -391,14 +442,14 @@ public class OverviewDimensionsTest { int xpos = 100; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth(), 1.5); - assertEquals(od.getBoxY(), 5, 1.5); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxY(), 5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (od.getBoxX() / scalew / av.getCharWidth()) + Math.round(od.getBoxX() / scalew / av.getCharWidth()) - lastHiddenCol, 1.5); assertEquals(od.getScrollRow(), - (int) (od.getBoxY() / scaleh / av.getCharHeight()), 1.5); + Math.round(od.getBoxY() / scaleh / av.getCharHeight())); } @@ -419,7 +470,8 @@ public class OverviewDimensionsTest { // hide columns 60-68, no change to box position or dimensions int firstHidden = 60; int lastHidden = 68; - av.hideColumns(firstHidden, lastHidden); + hideColumns(firstHidden, lastHidden); + od.setBoxPosition(); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -432,27 +484,30 @@ public class OverviewDimensionsTest { int xpos = 50 - boxWidth; // 50 is position in overview halfway between cols // 60 and 70 mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos, 1.5); + assertEquals(od.getBoxX(), xpos); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth - + (lastHidden - firstHidden + 1) * scalew * av.getCharWidth(), - 1.5); + assertEquals( + od.getBoxWidth(), + Math.round(boxWidth + (lastHidden - firstHidden + 1) * scalew + * av.getCharWidth())); assertEquals(od.getBoxHeight(), boxHeight); - assertEquals(od.getScrollCol(), (int) (xpos / scalew / av.getCharWidth()), 1.5); + assertEquals(od.getScrollCol(), + Math.round(xpos / scalew / av.getCharWidth())); assertEquals(od.getScrollRow(), 0); // move box so that it completely covers hidden cols // box width changes, boxX and scrollCol as for hidden case xpos = 30; mouseClick(od, xpos, 0); - assertEquals(od.getBoxX(), xpos, 1.5); + assertEquals(od.getBoxX(), xpos); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth - + (lastHidden - firstHidden + 1) * scalew * av.getCharWidth(), - 1.5); + assertEquals( + od.getBoxWidth(), + Math.round(boxWidth + (lastHidden - firstHidden + 1) * scalew + * av.getCharWidth())); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (xpos / scalew / av.getCharWidth()), 1.5); + Math.round(xpos / scalew / av.getCharWidth()), 1.5); assertEquals(od.getScrollRow(), 0); // move box so boxX is in hidden cols, box overhangs at right @@ -467,7 +522,7 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (xpos / scalew / av.getCharWidth()), 1.5); + Math.round(xpos / scalew / av.getCharWidth()), 1.5); assertEquals(od.getScrollRow(), 0);*/ // move box so boxX is to right of hidden cols, but does not go beyond full @@ -483,7 +538,7 @@ public class OverviewDimensionsTest { testBoxIsAtClickPoint(xpos, 0); assertEquals(od.getScrollRow(), 0); assertEquals(od.getScrollCol(), - (int) (xpos / scalew / av.getCharWidth()) + Math.round(xpos / scalew / av.getCharWidth()) - lastHidden, 1.5);*/ // move box so it goes beyond full width of alignment @@ -491,15 +546,14 @@ public class OverviewDimensionsTest { xpos = 3000; mouseClick(od, xpos, 5); assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth(), 1.5); - assertEquals(od.getBoxY(), 5, 1.5); + assertEquals(od.getBoxY(), 5); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (od.getBoxX() / scalew / av.getCharWidth()) - - (lastHidden - firstHidden + 1), - 1.5); + Math.round((od.getBoxX() / scalew / av.getCharWidth()) + - (lastHidden - firstHidden + 1))); assertEquals(od.getScrollRow(), - (int) (od.getBoxY() / scaleh / av.getCharHeight()), 1.5); + Math.round(od.getBoxY() / scaleh / av.getCharHeight())); } @@ -520,7 +574,7 @@ public class OverviewDimensionsTest { // hide columns 140-157, no change to box position or dimensions int firstHidden = 140; int lastHidden = 157; - av.hideColumns(firstHidden, lastHidden); + hideColumns(firstHidden, lastHidden); od.setBoxPosition(); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); @@ -534,7 +588,7 @@ public class OverviewDimensionsTest { testBoxIsAtClickPoint(xpos, 0); assertEquals(od.getScrollRow(), 0); assertEquals(od.getScrollCol(), - (int) (xpos / scalew / av.getCharWidth()), 1.5); + Math.round(xpos / scalew / av.getCharWidth()), 1.5); // click to left of hidden cols, with overlap // boxX and scrollCol adjusted for hidden cols, width normal @@ -544,13 +598,13 @@ public class OverviewDimensionsTest { mouseClick(od, xpos, 0); assertEquals( od.getBoxX(), - (int) ((firstHidden - 1) * scalew * av.getCharWidth()) + Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - od.getBoxWidth(), 1.5); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (od.getBoxX() / scalew / av.getCharWidth()), 1.5); + Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5); assertEquals(od.getScrollRow(), 0);*/ // click in hidden cols @@ -559,13 +613,13 @@ public class OverviewDimensionsTest { /*xpos = 115; assertEquals( od.getBoxX(), - (int) ((firstHidden - 1) * scalew * av.getCharWidth()) + Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - od.getBoxWidth(), 1.5); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (od.getBoxX() / scalew / av.getCharWidth()), 1.5); + Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5); assertEquals(od.getScrollRow(), 0);*/ // click off end of alignment @@ -574,13 +628,13 @@ public class OverviewDimensionsTest { /* xpos = 3000; assertEquals( od.getBoxX(), - (int) ((firstHidden - 1) * scalew * av.getCharWidth()) + Math.round((firstHidden - 1) * scalew * av.getCharWidth()) - od.getBoxWidth(), 1.5); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), - (int) (od.getBoxX() / scalew / av.getCharWidth()), 1.5); + Math.round(od.getBoxX() / scalew / av.getCharWidth()), 1.5); assertEquals(od.getScrollRow(), 0);*/ } @@ -595,29 +649,31 @@ public class OverviewDimensionsTest { moveViewport(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to right moveViewportH(70); - assertEquals(od.getBoxX(), (int) (70 * scalew * av.getCharWidth())); + assertEquals(od.getBoxX(), Math.round(70 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport down moveViewportV(100); - assertEquals(od.getBoxX(), (int) (70 * scalew * av.getCharWidth())); - assertEquals(od.getBoxY(), (int) (100 * scaleh * av.getCharHeight())); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxX(), Math.round(70 * scalew * av.getCharWidth())); + assertEquals(od.getBoxY(), + Math.round(100 * scaleh * av.getCharHeight())); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to bottom right moveViewport(98, 508); - assertEquals(od.getBoxX(), (int) (98 * scalew * av.getCharWidth())); - assertEquals(od.getBoxY(), (int) (508 * scaleh * av.getCharHeight())); + assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth())); + assertEquals(od.getBoxY(), + Math.round(508 * scaleh * av.getCharHeight())); assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -629,23 +685,23 @@ public class OverviewDimensionsTest { { int firstHidden = 0; int lastHidden = 20; - av.hideColumns(firstHidden, lastHidden); + hideColumns(firstHidden, lastHidden); // move viewport to start of alignment moveViewport(0, 0); assertEquals(od.getBoxX(), - (int) ((lastHidden + 1) * scalew * av.getCharWidth())); + Math.round((lastHidden + 1) * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to end of alignment - need to make startRes by removing // hidden cols because of how viewport/overview are implemented moveViewport(98 - lastHidden - 1, 0); - assertEquals(od.getBoxX(), 98 * scalew * av.getCharWidth(), 1.5); + assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -657,43 +713,47 @@ public class OverviewDimensionsTest { { int firstHidden = 65; int lastHidden = 75; - av.hideColumns(firstHidden, lastHidden); + hideColumns(firstHidden, lastHidden); // move viewport before hidden columns moveViewport(3, 0); - assertEquals(od.getBoxX(), (int) (3 * scalew * av.getCharWidth())); + + assertEquals(od.getBoxX(), Math.round(3 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + System.out.println(od.getBoxWidth()); + assertEquals(od.getBoxWidth(), boxWidth); + System.out.println(od.getBoxWidth()); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to left of hidden columns with overlap moveViewport(10, 0); - assertEquals(od.getBoxX(), (int) (10 * scalew * av.getCharWidth())); + assertEquals(od.getBoxX(), Math.round(10 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), boxWidth - + (int) ((lastHidden - firstHidden + 1) * scalew * av - .getCharWidth()), 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + + Math.round((lastHidden - firstHidden + 1) * scalew + * av.getCharWidth())); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to straddle hidden columns moveViewport(60, 0); - assertEquals(od.getBoxX(), (int) (60 * scalew * av.getCharWidth())); + assertEquals(od.getBoxX(), Math.round(60 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), boxWidth - + (int) ((lastHidden - firstHidden + 1) * scalew * av - .getCharWidth()), 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + + Math.round((lastHidden - firstHidden + 1) * scalew + * av +.getCharWidth())); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to right of hidden columns, no overlap moveViewport(80 - (lastHidden - firstHidden + 1), 0); - assertEquals(od.getBoxX(), (int) (80 * scalew * av.getCharWidth()), 1.5); + assertEquals(od.getBoxX(), Math.round(80 * scalew * av.getCharWidth())); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } @@ -706,26 +766,28 @@ public class OverviewDimensionsTest { { int firstHidden = 145; int lastHidden = 157; - av.hideColumns(firstHidden, lastHidden); + hideColumns(firstHidden, lastHidden); // move viewport before hidden columns moveViewport(3, 0); - assertEquals(od.getBoxX(), (int) (3 * scalew * av.getCharWidth()), 1.5); + assertEquals(od.getBoxX(), Math.round(3 * scalew * av.getCharWidth()), + 1.5); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // move viewport to hidden columns // TODO boxwidth includes hidden in overview panel (why?) moveViewport(98, 0); - assertEquals(od.getBoxX(), (int) (98 * scalew * av.getCharWidth()), 1.5); + assertEquals(od.getBoxX(), Math.round(98 * scalew * av.getCharWidth()), + 1.5); assertEquals(od.getBoxY(), 0); assertEquals( od.getBoxWidth(), boxWidth - + (int) ((lastHidden - firstHidden + 1) * scalew * av - .getCharWidth()), 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + + Math.round((lastHidden - firstHidden + 1) * scalew + * av.getCharWidth()), 1.5); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -744,9 +806,9 @@ public class OverviewDimensionsTest { moveViewport(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), - (lastHidden + 1) * scaleh * av.getCharHeight(), 1.5); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + Math.round((lastHidden + 1) * scaleh * av.getCharHeight())); + 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 @@ -790,7 +852,7 @@ public class OverviewDimensionsTest { // TODO also fails with boxY out by 12 /*moveViewport(0, 198); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), (int) (198 * scaleh * av.getCharHeight()), + assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight @@ -814,21 +876,21 @@ public class OverviewDimensionsTest { moveViewport(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + 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(), - (int) ((firstHidden - viewHeight - 1) + Math.round ((firstHidden - viewHeight - 1) * scaleh * av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals( od.getBoxHeight(), boxHeight - + (int) ((lastHidden - firstHidden + 1) * scaleh * av + + Math.round ((lastHidden - firstHidden + 1) * scaleh * av .getCharHeight()), 1.5);*/ } @@ -843,6 +905,7 @@ public class OverviewDimensionsTest { od.setBoxPositionByMouse(0, 0); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getBoxWidth(), boxWidth); assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); @@ -855,9 +918,9 @@ public class OverviewDimensionsTest { od.setBoxPosition(); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), - (int) ((lastHiddenRow + 1) * scaleh * av.getCharHeight())); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + Math.round((lastHiddenRow + 1) * scaleh * av.getCharHeight())); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // click in hidden rows // TODO fails because boxHeight is 27 not 25 (possible rounding issue) @@ -866,15 +929,15 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight - + (int) ((lastHiddenRow + 1) * scaleh * av.getCharHeight()), + + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()), 1.5);*/ // click below hidden rows mouseClick(od, 0, 150); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 150, 1.5); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); } /** @@ -884,10 +947,16 @@ public class OverviewDimensionsTest { @Test(groups = { "Functional" }) public void testFromMouseWithHiddenRowsInMiddle() { + assertEquals(od.getBoxHeight(), 10); + od.setBoxPositionByMouse(0, 0); + + assertEquals(od.getBoxHeight(), 10); + assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); @@ -895,42 +964,46 @@ public class OverviewDimensionsTest { // no changes int firstHiddenRow = 50; int lastHiddenRow = 60; + assertEquals(od.getBoxHeight(), 10); hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1); + assertEquals(od.getBoxHeight(), 10); od.setBoxPosition(); + assertEquals(od.getBoxHeight(), 10); + assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + 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, (int) (ypos / scaleh / av.getCharHeight())); + /* mouseClick(od, 0, Math.round (ypos / scaleh / av.getCharHeight())); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), (int) (ypos / scaleh / av.getCharHeight()), + assertEquals(od.getBoxY(), Math.round (ypos / scaleh / av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals( od.getBoxHeight(), boxHeight - + (int) ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av + + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av .getCharHeight()), 1.5); */ // 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, (int) (ypos / scaleh / av.getCharHeight())); + /*mouseClick(od, 0, Math.round (ypos / scaleh / av.getCharHeight())); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), (int) (ypos / scaleh / av.getCharHeight()), + assertEquals(od.getBoxY(), Math.round (ypos / scaleh / av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals( od.getBoxHeight(), boxHeight - + (int) ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av + + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av .getCharHeight()), 1.5);*/ } @@ -945,6 +1018,7 @@ public class OverviewDimensionsTest { assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); assertEquals(od.getScrollCol(), 0); assertEquals(od.getScrollRow(), 0); @@ -957,28 +1031,28 @@ public class OverviewDimensionsTest { od.setBoxPosition(); assertEquals(od.getBoxX(), 0); assertEquals(od.getBoxY(), 0); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // click above hidden rows int ypos = 40; // row 40 - mouseClick(od, 0, (int) (ypos * scaleh * av.getCharHeight())); + mouseClick(od, 0, Math.round(ypos * scaleh * av.getCharHeight())); assertEquals(od.getBoxX(), 0); - assertEquals(od.getBoxY(), (int) (ypos * scaleh * av.getCharHeight()), - 1.5); - assertEquals(od.getBoxWidth(), boxWidth, 1.5); - assertEquals(od.getBoxHeight(), boxHeight, 1.5); + assertEquals(od.getBoxY(), + Math.round(ypos * scaleh * av.getCharHeight())); + assertEquals(od.getBoxWidth(), boxWidth); + assertEquals(od.getBoxHeight(), boxHeight); // 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, (int) (ypos * scaleh * av.getCharHeight())); + mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight())); assertEquals(od.getBoxX(), 0); assertEquals( od.getBoxY(), - (int) ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), + Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/ @@ -986,11 +1060,11 @@ public class OverviewDimensionsTest { // click within hidden rows ypos = 505; // TODO: fails with wrong boxHeight - correction done by setScrollValues(?) - /*mouseClick(od, 0, (int) (ypos * scaleh * av.getCharHeight())); + /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight())); assertEquals(od.getBoxX(), 0); assertEquals( od.getBoxY(), - (int) ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), + Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()), 1.5); assertEquals(od.getBoxWidth(), boxWidth, 1.5); assertEquals(od.getBoxHeight(), boxHeight, 1.5);*/ @@ -1077,5 +1151,32 @@ public class OverviewDimensionsTest { * hide group */ av.hideSequences(allseqs.get(hideseq), true); + + while (av.isCalcInProgress()) + { + try + { + Thread.sleep(50); + } catch (InterruptedException e) + { + System.out.println("Hiding seqs interruption"); + } + } + } + + private void hideColumns(int firstHidden, int lastHidden) + { + av.hideColumns(firstHidden, lastHidden); + + while (av.isCalcInProgress()) + { + try + { + Thread.sleep(50); + } catch (InterruptedException e) + { + System.out.println("Hiding cols interruption"); + } + } } } -- 1.7.10.2