X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fviewmodel%2FViewportRangesTest.java;h=67ca6ae20709c8287ad69fe0ab8ab0c1ee2ea091;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=70a36875d44c14008705dae516111d9611d56752;hpb=e54df488cd82761bfb0e9372aeae2acc5a1324d7;p=jalview.git
diff --git a/test/jalview/viewmodel/ViewportRangesTest.java b/test/jalview/viewmodel/ViewportRangesTest.java
index 70a3687..67ca6ae 100644
--- a/test/jalview/viewmodel/ViewportRangesTest.java
+++ b/test/jalview/viewmodel/ViewportRangesTest.java
@@ -1,6 +1,27 @@
+/*
+ * 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 static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import jalview.analysis.AlignmentGenerator;
@@ -12,13 +33,15 @@ import jalview.datamodel.HiddenSequences;
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-public class ViewportRangesTest {
+public class ViewportRangesTest
+{
AlignmentGenerator gen = new AlignmentGenerator(false);
@@ -45,12 +68,12 @@ public class ViewportRangesTest {
}
@Test(groups = { "Functional" })
- public void testViewportRanges()
+ public void testViewportRanges()
{
ViewportRanges vr = new ViewportRanges(al);
-
- assertEquals(vr.getStartRes(),0);
- assertEquals(vr.getEndRes(), al.getWidth()-1);
+
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), al.getWidth() - 1);
assertEquals(vr.getStartSeq(), 0);
assertEquals(vr.getEndSeq(), al.getHeight() - 1);
}
@@ -83,7 +106,6 @@ public class ViewportRangesTest {
vr.setEndSeq(al.getHeight());
assertEquals(vr.getEndSeq(), al.getHeight() - 1);
- // vr.setEndRes(al.getHeight() - 1);
vr.setEndSeq(al.getHeight() - 1);
assertEquals(vr.getEndSeq(), al.getHeight() - 1);
}
@@ -167,6 +189,24 @@ public class ViewportRangesTest {
}
@Test(groups = { "Functional" })
+ public void testSetStartResAndSeq()
+ {
+ ViewportRanges vr = new ViewportRanges(al);
+ vr.setViewportHeight(10);
+ vr.setStartResAndSeq(3, 6);
+ assertEquals(vr.getStartRes(), 3);
+ assertEquals(vr.getStartSeq(), 6);
+ assertEquals(vr.getEndRes(), 3 + vr.getViewportWidth() - 1);
+ assertEquals(vr.getEndSeq(), 6 + vr.getViewportHeight() - 1);
+
+ vr.setStartResAndSeq(10, 25);
+ assertEquals(vr.getStartRes(), 10);
+ assertEquals(vr.getStartSeq(), 19);
+ assertEquals(vr.getEndRes(), 10 + vr.getViewportWidth() - 1);
+ assertEquals(vr.getEndSeq(), 19 + vr.getViewportHeight() - 1);
+ }
+
+ @Test(groups = { "Functional" })
public void testSetViewportHeight()
{
ViewportRanges vr = new ViewportRanges(al);
@@ -346,38 +386,69 @@ public class ViewportRangesTest {
@Test(groups = { "Functional" })
public void testScrollToWrappedVisible()
{
- ViewportRanges vr = new ViewportRanges(al);
+ AlignmentI al2 = gen.generate(60, 30, 1, 5, 5);
+
+ ViewportRanges vr = new ViewportRanges(al2);
+
+ // start with viewport on 5-14
vr.setViewportStartAndWidth(5, 10);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 14);
- vr.scrollToWrappedVisible(0);
+ // scroll to 12 - no change
+ assertFalse(vr.scrollToWrappedVisible(12));
+ assertEquals(vr.getStartRes(), 5);
+
+ // scroll to 2 - back to 0-9
+ assertTrue(vr.scrollToWrappedVisible(2));
assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 9);
- vr.scrollToWrappedVisible(10);
- assertEquals(vr.getStartRes(), 10);
+ // scroll to 9 - no change
+ assertFalse(vr.scrollToWrappedVisible(9));
+ assertEquals(vr.getStartRes(), 0);
- vr.scrollToWrappedVisible(15);
+ // scroll to 12 - moves to 10-19
+ assertTrue(vr.scrollToWrappedVisible(12));
assertEquals(vr.getStartRes(), 10);
+ assertEquals(vr.getEndRes(), 19);
+
+ vr.setStartRes(13);
+ assertEquals(vr.getStartRes(), 13);
+ assertEquals(vr.getEndRes(), 22);
+
+ // scroll to 45 - jumps to 43-52
+ assertTrue(vr.scrollToWrappedVisible(45));
+ assertEquals(vr.getStartRes(), 43);
+ assertEquals(vr.getEndRes(), 52);
}
- // leave until JAL-2388 is merged and we can do without viewport
- /*@Test(groups = { "Functional" })
+ @Test(groups = { "Functional" })
public void testScrollToVisible()
{
ViewportRanges vr = new ViewportRanges(al);
- vr.setViewportStartAndWidth(12,5);
- vr.setViewportStartAndHeight(10,6);
- vr.scrollToVisible(13,14)
-
+ vr.setViewportStartAndWidth(12, 5);
+ vr.setViewportStartAndHeight(10, 6);
+ vr.scrollToVisible(13, 14);
+
// no change
assertEquals(vr.getStartRes(), 12);
assertEquals(vr.getStartSeq(), 10);
-
- vr.scrollToVisible(5,6);
+
+ vr.scrollToVisible(5, 6);
assertEquals(vr.getStartRes(), 5);
assertEquals(vr.getStartSeq(), 6);
-
+
// test for hidden columns too
- }*/
+ al.getHiddenColumns().hideColumns(1, 3);
+ vr.scrollToVisible(13, 3);
+ assertEquals(vr.getStartRes(), 6);
+ assertEquals(vr.getStartSeq(), 3);
+
+ vr.scrollToVisible(2, 9);
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getStartSeq(), 4);
+ }
@Test(groups = { "Functional" })
public void testEventFiring()
@@ -392,7 +463,7 @@ public class ViewportRangesTest {
// one event fired when startRes is called with new value
vr.setStartRes(4);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
l.reset();
// no event fired for same value
@@ -401,7 +472,7 @@ public class ViewportRangesTest {
l.reset();
vr.setStartSeq(4);
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.setStartSeq(4);
@@ -409,7 +480,7 @@ public class ViewportRangesTest {
l.reset();
vr.setEndSeq(10);
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.setEndSeq(10);
@@ -417,7 +488,7 @@ public class ViewportRangesTest {
l.reset();
vr.setStartEndRes(2, 15);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
l.reset();
vr.setStartEndRes(2, 15);
@@ -426,16 +497,18 @@ public class ViewportRangesTest {
// check new value fired by event is corrected startres
vr.setStartEndRes(-1, 5);
- assertTrue(l.verify(1, Arrays.asList("startres"), Arrays.asList(0)));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES),
+ Arrays.asList(0)));
l.reset();
// check new value fired by event is corrected endres
vr.setStartEndRes(0, -1);
- assertTrue(l.verify(1, Arrays.asList("endres"), Arrays.asList(0)));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDRES),
+ Arrays.asList(0)));
l.reset();
vr.setStartEndSeq(2, 15);
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.setStartEndSeq(2, 15);
@@ -448,12 +521,14 @@ public class ViewportRangesTest {
// check new value fired by event is corrected startseq
vr.setStartEndSeq(-1, 5);
- assertTrue(l.verify(1, Arrays.asList("startseq"), Arrays.asList(0)));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ),
+ Arrays.asList(0)));
l.reset();
// check new value fired by event is corrected endseq
vr.setStartEndSeq(0, -1);
- assertTrue(l.verify(1, Arrays.asList("endseq"), Arrays.asList(0)));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ),
+ Arrays.asList(0)));
l.reset();
// reset for later tests
@@ -462,55 +537,71 @@ public class ViewportRangesTest {
// test viewport height and width setting triggers event
vr.setViewportHeight(10);
- assertTrue(l.verify(1, Arrays.asList("endseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ)));
l.reset();
vr.setViewportWidth(18);
- assertTrue(l.verify(1, Arrays.asList("endres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDRES)));
l.reset();
// already has seq start set to 2, so triggers endseq
vr.setViewportStartAndHeight(2, 16);
- assertTrue(l.verify(1, Arrays.asList("endseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.ENDSEQ)));
l.reset();
vr.setViewportStartAndWidth(1, 14);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
l.reset();
// test page up/down triggers event
vr.pageUp();
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.pageDown();
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
// test scrolling triggers event
vr.scrollUp(true);
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.scrollUp(false);
- assertTrue(l.verify(1, Arrays.asList("startseq")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTSEQ)));
l.reset();
vr.scrollRight(true);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
l.reset();
vr.scrollRight(false);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
l.reset();
vr.scrollToVisible(10, 10);
assertTrue(l.verify(4,
- Arrays.asList("startseq", "startseq", "startseq", "startseq")));
+ Arrays.asList(ViewportRanges.STARTSEQ, ViewportRanges.STARTSEQ,
+ ViewportRanges.STARTSEQ, ViewportRanges.STARTSEQ)));
+ l.reset();
+
+ /*
+ * scrollToWrappedVisible does nothing if the target position is
+ * within the current startRes-endRes range
+ */
+ assertFalse(vr.scrollToWrappedVisible(5));
+ assertTrue(l.verify(0, Collections. emptyList()));
l.reset();
- vr.scrollToWrappedVisible(5);
- assertTrue(l.verify(1, Arrays.asList("startres")));
+ vr.scrollToWrappedVisible(25);
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRES)));
+ l.reset();
+
+ // test setStartResAndSeq triggers one event
+ vr.setStartResAndSeq(5, 7);
+ assertTrue(l.verify(1, Arrays.asList(ViewportRanges.STARTRESANDSEQ),
+ Arrays.asList(5, 7)));
+
l.reset();
}
@@ -650,23 +741,23 @@ public class ViewportRangesTest {
vr.setStartEndRes(-1, -1);
assertEquals(vr.getStartRes(), 0);
assertEquals(vr.getEndRes(), 0);
-
+
vr.setStartEndRes(5, 19);
assertEquals(vr.getStartRes(), 5);
assertEquals(vr.getEndRes(), 19);
-
+
// bounds are not constrained to alignment width
// when in wrapped mode
vr.setStartEndRes(88, 888);
assertEquals(vr.getStartRes(), 88);
assertEquals(vr.getEndRes(), 888);
-
+
ViewportRanges vrsmall = new ViewportRanges(smallAl);
vrsmall.setWrappedMode(true);
vrsmall.setStartEndRes(88, 888);
assertEquals(vrsmall.getStartRes(), 88);
assertEquals(vrsmall.getEndRes(), 888);
-
+
// make visible alignment width = 0
smallAl.getHiddenColumns().hideColumns(0, 6);
vrsmall.setStartEndRes(0, 4);
@@ -682,17 +773,17 @@ public class ViewportRangesTest {
vr.setViewportStartAndWidth(2, 6);
assertEquals(vr.getViewportWidth(), 6);
assertEquals(vr.getStartRes(), 2);
-
+
// reset -ve values of start to 0
vr.setViewportStartAndWidth(-1, 7);
assertEquals(vr.getViewportWidth(), 7);
assertEquals(vr.getStartRes(), 0);
-
+
// out of bounds values are not forced to within bounds
vr.setViewportStartAndWidth(35, 5);
assertEquals(vr.getViewportWidth(), 5);
assertEquals(vr.getStartRes(), 35);
-
+
// small alignment doesn't get bounds reset
ViewportRanges vrsmall = new ViewportRanges(smallAl);
vrsmall.setViewportStartAndWidth(0, 63);
@@ -710,7 +801,7 @@ public class ViewportRangesTest {
vr.setStartEndRes(0, 39);
int width = vr.getViewportWidth(); // 40
int partWidth = alignmentWidth % width; // 20
-
+
/*
* there are 3 * 40 remainder 20 residues
* number of widths depends on offset (scroll right)
@@ -730,6 +821,136 @@ public class ViewportRangesTest {
}
}
}
+
+ @Test(groups = { "Functional" })
+ public void testScrollUp_wrapped()
+ {
+ /*
+ * alignment 30 tall and 45 wide
+ */
+ AlignmentI al2 = gen.generate(45, 30, 1, 0, 5);
+
+ /*
+ * wrapped view, 5 sequences high, start at sequence offset 1
+ */
+ ViewportRanges vr = new ViewportRanges(al2);
+ vr.setWrappedMode(true);
+ vr.setViewportStartAndHeight(1, 5);
+
+ /*
+ * offset wrapped view to column 3
+ */
+ vr.setStartEndRes(3, 22);
+
+ int startRes = vr.getStartRes();
+ int width = vr.getViewportWidth();
+ assertEquals(startRes, 3);
+ assertEquals(width, 20);
+
+ // in wrapped mode, we change startRes but not startSeq
+ // scroll down:
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 23);
+
+ // scroll up returns to original position
+ vr.scrollUp(true);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 3);
+
+ // scroll up again returns to 'origin'
+ vr.scrollUp(true);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 0);
+
+ /*
+ * offset 3 columns once more and do some scroll downs
+ */
+ vr.setStartEndRes(3, 22);
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 23);
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 43);
+
+ /*
+ * scroll down beyond end of alignment does nothing
+ */
+ vr.scrollUp(false);
+ assertEquals(vr.getStartSeq(), 1);
+ assertEquals(vr.getStartRes(), 43);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetViewportLocation()
+ {
+ AlignmentI al2 = gen.generate(60, 80, 1, 0, 0);
+
+ ViewportRanges vr = new ViewportRanges(al2);
+
+ // start with viewport on 5-14
+ vr.setViewportStartAndWidth(5, 10);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 14);
+
+ vr.setViewportStartAndHeight(3, 13);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set location to (8,5) - no change
+ vr.setViewportLocation(8, 5);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 14);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set location to (40,50) - change to top left (40,50)
+ vr.setViewportLocation(40, 50);
+ assertEquals(vr.getStartRes(), 40);
+ assertEquals(vr.getEndRes(), 49);
+ assertEquals(vr.getStartSeq(), 50);
+ assertEquals(vr.getEndSeq(), 62);
+
+ // set location past end of alignment - resets to leftmost pos
+ vr.setViewportLocation(63, 85);
+ assertEquals(vr.getStartRes(), 50);
+ assertEquals(vr.getEndRes(), 59);
+ assertEquals(vr.getStartSeq(), 67);
+ assertEquals(vr.getEndSeq(), 79);
+
+ // hide some columns
+ al2.getHiddenColumns().hideColumns(20, 50);
+ vr.setViewportLocation(55, 4);
+ assertEquals(vr.getStartRes(), 19);
+ assertEquals(vr.getEndRes(), 28);
+ assertEquals(vr.getStartSeq(), 4);
+ assertEquals(vr.getEndSeq(), 16);
+
+ // hide some sequences
+ al2.getHiddenSequences().hideSequence(al2.getSequenceAt(3));
+ al2.getHiddenSequences().hideSequence(al2.getSequenceAt(4));
+ vr.setViewportLocation(17, 5);
+ assertEquals(vr.getStartRes(), 17);
+ assertEquals(vr.getEndRes(), 26);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // set wrapped mode
+ vr.setWrappedMode(true);
+ vr.setViewportLocation(1, 8);
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 9);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+
+ // try further down the alignment
+ vr.setViewportLocation(57, 5);
+ assertEquals(vr.getStartRes(), 20);
+ assertEquals(vr.getEndRes(), 29);
+ assertEquals(vr.getStartSeq(), 3);
+ assertEquals(vr.getEndSeq(), 15);
+ }
}
// mock listener for property change events
@@ -751,7 +972,15 @@ class MockPropChangeListener implements ViewportListenerI
{
firecount++;
events.add(evt.getPropertyName());
- newvalues.add((Integer) evt.getNewValue());
+ if (evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ))
+ {
+ newvalues.add(((int[]) evt.getNewValue())[0]);
+ newvalues.add(((int[]) evt.getNewValue())[1]);
+ }
+ else
+ {
+ newvalues.add((Integer) evt.getNewValue());
+ }
}
public boolean verify(int count, List eventslist,