import java.util.Arrays;
import java.util.List;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
AlignmentI smallAl = gen.generate(7, 2, 2, 5, 5);
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ gen = new AlignmentGenerator(false);
+ al = gen.generate(20, 30, 1, 5, 5);
+ smallAl = gen.generate(7, 2, 2, 5, 5);
+ }
+
@BeforeMethod(alwaysRun = true)
public void cleanUp()
{
}
@Test(groups = { "Functional" })
- public void testSetEndRes()
- {
- ViewportRanges vr = new ViewportRanges(al);
- vr.setEndRes(-1);
- assertEquals(vr.getEndRes(), 0);
-
- vr.setEndRes(al.getWidth() - 1);
- assertEquals(vr.getEndRes(), al.getWidth() - 1);
- }
-
- @Test(groups = { "Functional" })
public void testSetEndSeq()
{
ViewportRanges vr = new ViewportRanges(al);
vr.setEndSeq(al.getHeight());
assertEquals(vr.getEndSeq(), al.getHeight() - 1);
- vr.setEndRes(al.getHeight() - 1);
+ // vr.setEndRes(al.getHeight() - 1);
+ vr.setEndSeq(al.getHeight() - 1);
assertEquals(vr.getEndSeq(), al.getHeight() - 1);
}
assertTrue(l.verify(0, emptylist));
l.reset();
- vr.setEndRes(10);
- assertTrue(l.verify(1, Arrays.asList("startres")));
- l.reset();
-
- // no event fired for same value
- vr.setEndRes(10);
- assertTrue(l.verify(0, emptylist));
- l.reset();
-
vr.setStartSeq(4);
assertTrue(l.verify(1, Arrays.asList("startseq")));
l.reset();
assertEquals(2, vr.getWrappedScrollPosition(i), "For " + i);
}
}
+
+ @Test(groups = { "Functional" })
+ public void testPageUpDownWrapped()
+ {
+ /*
+ * 15 sequences, 110 residues wide (+gaps)
+ */
+ AlignmentI al2 = gen.generate(110, 15, 1, 5, 5);
+
+ ViewportRanges vr = new ViewportRanges(al2);
+ vr.setWrappedMode(true);
+
+ // first row
+ vr.setViewportStartAndWidth(0, 40);
+ int width = vr.getViewportWidth();
+ assertEquals(width, 40);
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 39);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // second row
+ vr.pageDown();
+ assertEquals(vr.getStartRes(), 40);
+ assertEquals(vr.getEndRes(), 79);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // third and last row
+ // note endRes is nominal (>width) to preserve viewport width
+ vr.pageDown();
+ assertEquals(vr.getStartRes(), 80);
+ assertEquals(vr.getEndRes(), 119);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // another pageDown should do nothing
+ vr.pageDown();
+ assertEquals(vr.getStartRes(), 80);
+ assertEquals(vr.getEndRes(), 119);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // back to second row
+ vr.pageUp();
+ assertEquals(vr.getStartRes(), 40);
+ assertEquals(vr.getEndRes(), 79);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // back to first row
+ vr.pageUp();
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 39);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ // another pageUp should do nothing
+ vr.pageUp();
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 39);
+ assertEquals(vr.getStartSeq(), 0);
+ assertEquals(vr.getEndSeq(), 14);
+
+ /*
+ * simulate scroll right a few positions
+ */
+ vr.setStartRes(5);
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 5 + width - 1); // 44
+
+ vr.pageDown(); // 5-44 shifts to 45-84
+ assertEquals(vr.getStartRes(), 45);
+ assertEquals(vr.getEndRes(), 84);
+
+ vr.pageDown(); // 45-84 shifts to 85-124
+ assertEquals(vr.getStartRes(), 85);
+ assertEquals(vr.getEndRes(), 124);
+
+ vr.pageDown(); // no change - at end already
+ assertEquals(vr.getStartRes(), 85);
+ assertEquals(vr.getEndRes(), 124);
+
+ vr.pageUp(); // back we go
+ assertEquals(vr.getStartRes(), 45);
+ assertEquals(vr.getEndRes(), 84);
+
+ vr.pageUp();
+ assertEquals(vr.getStartRes(), 5);
+ assertEquals(vr.getEndRes(), 44);
+
+ vr.pageUp(); // back to the start
+ assertEquals(vr.getStartRes(), 0);
+ assertEquals(vr.getEndRes(), 39);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetStartEndResWrapped()
+ {
+ ViewportRanges vr = new ViewportRanges(al);
+ vr.setWrappedMode(true);
+ 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);
+ assertEquals(vrsmall.getStartRes(), 0);
+ assertEquals(vrsmall.getEndRes(), 4);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testSetViewportStartAndWidthWrapped()
+ {
+ ViewportRanges vr = new ViewportRanges(al);
+ vr.setWrappedMode(true);
+ 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);
+ assertEquals(vrsmall.getViewportWidth(), 7);
+ assertEquals(vrsmall.getStartRes(), 0);
+ }
}
// mock listener for property change events