From 6536eebed40b833ad60803e8f2a4b0a9bd395035 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 11 May 2018 12:17:18 +0100 Subject: [PATCH] JAL-2986 additional asserts for SequenceCursor updates --- test/jalview/datamodel/SequenceTest.java | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 67f1081..79bb2bb 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -1427,25 +1427,43 @@ public class SequenceTest { 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 @@ -1453,10 +1471,17 @@ public class SequenceTest */ 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" }) -- 1.7.10.2