From be6ff1dbfb14dce03ac5b89c3a078d44b4ee75f9 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 17 Feb 2017 14:57:39 +0000 Subject: [PATCH] JAL-2388 Incomplete unit tests --- src/jalview/gui/AlignmentPanel.java | 6 +- test/jalview/viewmodel/OverviewDimensionsTest.java | 445 ++++++++++++++++++++ 2 files changed, 448 insertions(+), 3 deletions(-) create mode 100644 test/jalview/viewmodel/OverviewDimensionsTest.java diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index e61b042..3e24b94 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -701,9 +701,6 @@ public class AlignmentPanel extends GAlignmentPanel implements width = av.getColumnSelection().findColumnPosition(width); } - av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth())) - 1); - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); @@ -737,6 +734,9 @@ public class AlignmentPanel extends GAlignmentPanel implements x = 0; } + av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av + .getCharWidth())) - 1); + /* * each scroll adjustment triggers adjustmentValueChanged, which resets the * 'do not scroll complement' flag; ensure it is the same for both diff --git a/test/jalview/viewmodel/OverviewDimensionsTest.java b/test/jalview/viewmodel/OverviewDimensionsTest.java new file mode 100644 index 0000000..39506fc --- /dev/null +++ b/test/jalview/viewmodel/OverviewDimensionsTest.java @@ -0,0 +1,445 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.viewmodel; + +import static org.testng.Assert.assertEquals; + +import jalview.bin.Cache; +import jalview.bin.Jalview; +import jalview.datamodel.Alignment; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; +import jalview.gui.AlignViewport; +import jalview.gui.JvOptionPane; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class OverviewDimensionsTest { + + boolean showConservationSetting; + + SequenceI seq1 = new Sequence( + "Seq1", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq2 = new Sequence( + "Seq2", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq3 = new Sequence( + "Seq3", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq4 = new Sequence( + "Seq4", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq5 = new Sequence( + "Seq5", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq6 = new Sequence( + "Seq6", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq7 = new Sequence( + "Seq7", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq8 = new Sequence( + "Seq8", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq9 = new Sequence( + "Seq9", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq10 = new Sequence( + "Seq10", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq11 = new Sequence( + "Seq11", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq12 = new Sequence( + "Seq12", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq13 = new Sequence( + "Seq13", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq14 = new Sequence( + "Seq14", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq15 = new Sequence( + "Seq15", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq16 = new Sequence( + "Seq16", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq17 = new Sequence( + "Seq17", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq18 = new Sequence( + "Seq18", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq19 = new Sequence( + "Seq19", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq20 = new Sequence( + "Seq20", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq21 = new Sequence( + "Seq21", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq22 = new Sequence( + "Seq22", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC" + + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC" + + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + SequenceI seq23 = new Sequence( + "Seq23", + "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC"); + + + @BeforeClass(alwaysRun = true) + public void setUp() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + + Jalview.main(new String[] { "-nonews", "-props", + "test/jalview/testProps.jvprops" }); + + // get cached setting for showConservation + // reset it in AfterClass! + showConservationSetting = Cache.getDefault("SHOW_CONSERVATION", true); + } + + @AfterClass(alwaysRun = true) + public void tearDown() + { + Cache.applicationProperties.setProperty("SHOW_CONSERVATION", + Boolean.toString(showConservationSetting)); + } + + /** + * Test that the OverviewDimensions constructor sets width and height + * correctly + */ + @Test(groups = { "Functional" }) + public void testConstructor() + { + SequenceI seqa = new Sequence("Seq1", "ABC"); + SequenceI seqb = new Sequence("Seq2", "ABC"); + SequenceI seqc = new Sequence("Seq3", "ABC"); + SequenceI seqd = new Sequence("Seq4", "ABC"); + SequenceI seqe = new Sequence("Seq5", + "ABCABCABCABCABCABCABCABCBACBACBACBAC"); + + Cache.applicationProperties.setProperty("SHOW_CONSERVATION", + Boolean.toString(true)); + + // test for alignment with width > height + SequenceI[] seqs1 = new SequenceI[] { seqa, seqb }; + Alignment al1 = new Alignment(seqs1); + al1.setDataset(null); + AlignViewport av1 = new AlignViewport(al1); + + OverviewDimensions od = new OverviewDimensions(av1); + assertEquals(od.getGraphHeight(), 20); + assertEquals(od.getSequencesHeight(), 266); + assertEquals(od.getWidth(), 400); + assertEquals(od.getHeight(), 286); + + // test for alignment with width < height + SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd }; + Alignment al2 = new Alignment(seqs2); + al2.setDataset(null); + AlignViewport av2 = new AlignViewport(al2); + + od = new OverviewDimensions(av2); + assertEquals(od.getGraphHeight(), 20); + assertEquals(od.getSequencesHeight(), 300); + assertEquals(od.getWidth(), 300); + assertEquals(od.getHeight(), 320); + + // test for alignment with width > height and sequence height scaled below + // min value + SequenceI[] seqs3 = new SequenceI[] { seqe }; + Alignment al3 = new Alignment(seqs3); + al3.setDataset(null); + AlignViewport av3 = new AlignViewport(al3); + + od = new OverviewDimensions(av3); + assertEquals(od.getGraphHeight(), 20); + assertEquals(od.getSequencesHeight(), 40); + assertEquals(od.getWidth(), 400); + assertEquals(od.getHeight(), 60); + + // test for alignment with width < height and width scaled below min value + SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa, + seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd }; + Alignment al4 = new Alignment(seqs4); + al4.setDataset(null); + AlignViewport av4 = new AlignViewport(al4); + + od = new OverviewDimensions(av4); + assertEquals(od.getGraphHeight(), 20); + assertEquals(od.getSequencesHeight(), 300); + assertEquals(od.getWidth(), 120); + assertEquals(od.getHeight(), 320); + + // test for alignment where no conservation annotation is shown + Cache.applicationProperties.setProperty("SHOW_CONSERVATION", + Boolean.toString(false)); + + Alignment al5 = new Alignment(seqs4); + al5.setDataset(null); + AlignViewport av5 = new AlignViewport(al5); + + od = new OverviewDimensions(av5); + assertEquals(od.getGraphHeight(), 0); + assertEquals(od.getSequencesHeight(), 300); + assertEquals(od.getWidth(), 120); + assertEquals(od.getHeight(), 300); + } + + /** + * Test that validation after mouse adjustments to boxX and boxY sets box + * dimensions and scroll values correctly, when there are no hidden rows or + * columns + */ + @Test(groups = { "Functional" }) + public void checkValidNoHidden() + { + seq23.setStart(386); + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + // Initial box sizing - default path through code + OverviewDimensions od = new OverviewDimensions(av); + od.setBoxPosition(); + od.checkValid(); + assertEquals(od.getBoxX(), 0); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getBoxWidth(), 399); + assertEquals(od.getScrollCol(), 0); + assertEquals(od.getScrollRow(), 0); + + // negative boxX value reset to 0 + od.setBoxX(-5); + od.checkValid(); + assertEquals(od.getBoxX(), 0); + + // negative boxY value reset to 0 + od.setBoxY(-2); + od.checkValid(); + assertEquals(od.getBoxY(), 0); + + // overly large boxX value reset to width-boxWidth + od.setBoxX(100); + od.checkValid(); + assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth()); + + // startRes non-zero + av.setStartRes(50); + OverviewDimensions od2 = new OverviewDimensions(av); + od2.setBoxPosition(); + od2.checkValid(); + assertEquals(od2.getBoxX(), 61); + assertEquals(od2.getScrollCol(), 49); + } + + /** + * Test setting of the box position, when there are hidden cols at the start + * of the alignment + */ + @Test(groups = { "Functional" }) + public void testSetBoxPosWithHiddenColsAtStart() + { + seq23.setStart(386); + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + av.setStartRes(50); + OverviewDimensions od = new OverviewDimensions(av); + + // hiding columns before current position: changes boxX but not scrollCol or + // boxwidth + + // do a reset + av.showAllHiddenColumns(); + od.setBoxPosition(); + od.checkValid(); + int prevWidth = od.getBoxWidth(); + + // hide cols at start and check updated box position is correct + // changes boxX but not scrollCol or boxwidth + int lastHiddenCol = 50; + av.hideColumns(0, 50); + od.setBoxPosition(); + assertEquals(od.getBoxX(), 124); + assertEquals(od.getScrollCol(), lastHiddenCol - 1); + assertEquals(od.getBoxWidth(), prevWidth); + + // set the box position by moving viewport & check it goes to the right + // place + + // update the box position via mouse and check it goes to the right place + } + + @Test(groups = { "Functional" }) + public void testSetBoxPosWithHiddenColsAtEnd() + { + + } + + @Test(groups = { "Functional" }) + public void testSetBoxPosWithHiddenColsMiddle() + { + seq23.setStart(386); + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + av.setStartRes(50); + OverviewDimensions od = new OverviewDimensions(av); + + // hiding columns after current position: changes end position but not start + // so scrollCol and boxX do not change but boxWidth does + float scalew = od.getWidth() / al.getWidth(); + int prevWidth = od.getBoxWidth(); + int prevX = od.getBoxX(); + av.hideColumns(108, 110); + od.setBoxPosition(); + assertEquals(od.getBoxX(), prevX); + assertEquals(od.getScrollCol(), 49); + // assertEquals(od2.getBoxWidth(), prevWidth + ((int) 2 * av.getCharWidth() + // / scalew)); + } + + @Test(groups = { "Functional" }) + public void testSetBoxPosWithHiddenRowsAtStart() + { + seq23.setStart(386); + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + av.setStartRes(50); + OverviewDimensions od = new OverviewDimensions(av); + + // account for hidden rows + SequenceI[] hidden = { seq2, seq3, seq4, seq5, seq6, seq7 }; + av.showAllHiddenColumns(); + av.hideSequence(hidden); + od.checkValid(); + assertEquals(od.getBoxY(), 0); + assertEquals(od.getScrollRow(), 0); + } + + /** + * Test that the box position is set correctly + */ + @Test(groups = { "Functional" }) + public void setBoxPosition() + { + + SequenceI[] seqs = new SequenceI[] { seq1, seq2, seq3, seq4, seq5, + seq6, seq7, seq8, seq9, seq10, seq11, seq12, seq13, seq14, seq15, + seq16, seq17, seq18, seq19, seq20, seq21, seq22, seq23 }; + Alignment al = new Alignment(seqs); + al.setDataset(null); + AlignViewport av = new AlignViewport(al); + + // Test box is in expected location when there are no hidden rows or columns + + OverviewDimensions od = new OverviewDimensions(av); + od.setBoxPosition(); + + assertEquals(od.getBoxHeight(), 81); + assertEquals(od.getBoxWidth(), 400); + assertEquals(od.getBoxX(), 0); + assertEquals(od.getBoxY(), 0); + + // Account for hidden rows + SequenceI[] hidden = { seq2, seq3, seq4 }; + av.hideSequence(hidden); + + OverviewDimensions od1 = new OverviewDimensions(av); + od1.setBoxPosition(); + + assertEquals(od1.getBoxHeight(), 80); + assertEquals(od1.getBoxWidth(), 400); + assertEquals(od1.getBoxX(), 0); + assertEquals(od1.getBoxY(), 0); + + // Account for hidden columns + av.hideColumns(10, 15); + av.showAllHiddenSeqs(); + + OverviewDimensions od2 = new OverviewDimensions(av); + od2.setBoxPosition(); + + assertEquals(od2.getBoxHeight(), 81); + assertEquals(od2.getBoxWidth(), 422); + assertEquals(od2.getBoxX(), 0); + assertEquals(od2.getBoxY(), 0); + + // Account for hidden rows and cols + av.hideSequence(hidden); + OverviewDimensions od3 = new OverviewDimensions(av); + od3.setBoxPosition(); + + assertEquals(od3.getBoxHeight(), 80); + assertEquals(od3.getBoxWidth(), 422); + assertEquals(od3.getBoxX(), 0); + assertEquals(od3.getBoxY(), 0); + } +} -- 1.7.10.2