{
Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
- // find F given A
+ // find F given A, check cursor is now at the found position
assertEquals(10, sq.findIndex(13, new SequenceCursor(sq, 8, 2, 0)));
+ SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertEquals(13, cursor.residuePosition);
+ assertEquals(10, cursor.columnPosition);
// find A given F
assertEquals(2, sq.findIndex(8, new SequenceCursor(sq, 13, 10, 0)));
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertEquals(8, cursor.residuePosition);
+ assertEquals(2, cursor.columnPosition);
- // find C given C
+ // find C given C (no cursor update is done for this case)
assertEquals(6, sq.findIndex(10, new SequenceCursor(sq, 10, 6, 0)));
+ SequenceCursor cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertSame(cursor2, cursor);
/*
* sequence 'end' beyond end of sequence returns length of sequence
* (for compatibility with pre-cursor code)
+ * - also verify the cursor is left in a valid state
*/
sq = new Sequence("test/8-99", "-A--B-C-D-E-F--"); // trailing gap case
- sq.findIndex(10); // establishes a cursor
+ assertEquals(7, sq.findIndex(10)); // establishes a cursor
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertEquals(10, cursor.residuePosition);
+ assertEquals(7, cursor.columnPosition);
assertEquals(sq.getLength(), sq.findIndex(65));
+ cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertSame(cursor, cursor2); // not updated for this case!
+
sq = new Sequence("test/8-99", "-A--B-C-D-E-F"); // trailing residue case
sq.findIndex(10); // establishes a cursor
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(sq.getLength(), sq.findIndex(65));
+ cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertSame(cursor, cursor2); // not updated for this case!
/*
* residue after sequence 'start' but before first residue should return
*/
sq = new Sequence("test/8-15", "-A-B-C-"); // leading gap case
sq.findIndex(10); // establishes a cursor
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(0, sq.findIndex(3));
+ cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertSame(cursor, cursor2); // not updated for this case!
+
sq = new Sequence("test/8-15", "A-B-C-"); // leading residue case
sq.findIndex(10); // establishes a cursor
+ cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(0, sq.findIndex(2));
+ cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
+ assertSame(cursor, cursor2); // not updated for this case!
}
@Test(groups = { "Functional" })