JAL-2526 correct boundary conditions for sequence left/right of cursor
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 8 Jun 2017 15:14:43 +0000 (16:14 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 8 Jun 2017 15:14:43 +0000 (16:14 +0100)
src/jalview/datamodel/Sequence.java
test/jalview/datamodel/SequenceTest.java

index 8ea6ca3..a442cf0 100755 (executable)
@@ -909,7 +909,7 @@ public class Sequence extends ASequence implements SequenceI
       return curs.residuePosition; // easy case :-)
     }
 
-    if (curs.lastColumnPosition > 0 && curs.lastColumnPosition <= col)
+    if (curs.lastColumnPosition > 0 && curs.lastColumnPosition < col)
     {
       /*
        * sequence lies entirely to the left of col
@@ -918,7 +918,7 @@ public class Sequence extends ASequence implements SequenceI
       return end + 1;
     }
 
-    if (curs.firstColumnPosition > 0 && curs.firstColumnPosition >= col)
+    if (curs.firstColumnPosition > 0 && curs.firstColumnPosition > col)
     {
       /*
        * sequence lies entirely to the right of col
index e657599..90856e8 100644 (file)
@@ -438,6 +438,24 @@ public class SequenceTest
     assertEquals(14, sq.findPosition(99));
     assertEquals("test:Pos13:Col10:startCol3:endCol10:tok12",
             PA.getValue(sq, "cursor").toString());
+
+    /*
+     * gapped sequence ending in non-gap
+     */
+    sq = new Sequence("test/8-13", "--AB-C-DEF");
+    assertEquals(13, sq.findPosition(9));
+    assertEquals("test:Pos13:Col10:startCol3:endCol10:tok0",
+            PA.getValue(sq, "cursor").toString());
+    sq.sequenceChanged();
+    assertEquals(12, sq.findPosition(8));
+    cursor = (SequenceCursor) PA.getValue(sq, "cursor");
+    assertEquals("test:Pos12:Col9:startCol3:endCol10:tok1",
+            cursor.toString());
+    // findPosition with cursor accepts base 1 column values
+    assertEquals(13, ((Sequence) sq).findPosition(10, cursor));
+    assertEquals(13, sq.findPosition(9));
+    assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1",
+            PA.getValue(sq, "cursor").toString());
   }
 
   @Test(groups = { "Functional" })