Merge branch 'bug/JAL-2682parseId' into develop
authorJim Procter <jprocter@issues.jalview.org>
Mon, 23 Oct 2017 14:59:30 +0000 (15:59 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 23 Oct 2017 14:59:30 +0000 (15:59 +0100)
1  2 
src/jalview/datamodel/Sequence.java
test/jalview/datamodel/SequenceTest.java

Simple merge
@@@ -1674,34 -1665,101 +1674,133 @@@ public class SequenceTes
    }
  
    @Test(groups = { "Functional" })
 +  public void testFindFeatures_largeEndPos()
 +  {
 +    /*
 +     * imitate a PDB sequence where end is larger than end position
 +     */
 +    SequenceI sq = new Sequence("test", "-ABC--DEF--", 1, 20);
 +    sq.createDatasetSequence();
 +  
 +    assertTrue(sq.findFeatures(1, 9).isEmpty());
 +    // should be no array bounds exception - JAL-2772
 +    assertTrue(sq.findFeatures(1, 15).isEmpty());
 +  
 +    // add feature on BCD
 +    SequenceFeature sfBCD = new SequenceFeature("Cath", "desc", 2, 4, 2f,
 +            null);
 +    sq.addSequenceFeature(sfBCD);
 +  
 +    // no features in columns 1-2 (-A)
 +    List<SequenceFeature> found = sq.findFeatures(1, 2);
 +    assertTrue(found.isEmpty());
 +  
 +    // columns 1-6 (-ABC--) includes BCD
 +    found = sq.findFeatures(1, 6);
 +    assertEquals(1, found.size());
 +    assertTrue(found.contains(sfBCD));
 +
 +    // columns 10-11 (--) should find nothing
 +    found = sq.findFeatures(10, 11);
 +    assertEquals(0, found.size());
 +  }
++
++  @Test(groups = { "Functional" })
+   public void testSetName()
+   {
+     SequenceI sq = new Sequence("test", "-ABC---DE-F--");
+     assertEquals("test", sq.getName());
+     assertEquals(1, sq.getStart());
+     assertEquals(6, sq.getEnd());
+     sq.setName("testing");
+     assertEquals("testing", sq.getName());
+     sq.setName("test/8-10");
+     assertEquals("test", sq.getName());
+     assertEquals(8, sq.getStart());
+     assertEquals(13, sq.getEnd()); // note end is recomputed
+     sq.setName("testing/7-99");
+     assertEquals("testing", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd()); // end may be beyond physical end
+     sq.setName("/2-3");
+     assertEquals("", sq.getName());
+     assertEquals(2, sq.getStart());
+     assertEquals(7, sq.getEnd());
+     sq.setName("test/"); // invalid
+     assertEquals("test/", sq.getName());
+     assertEquals(2, sq.getStart());
+     assertEquals(7, sq.getEnd());
+     sq.setName("test/6-13/7-99");
+     assertEquals("test/6-13", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/0-5"); // 0 is invalid - ignored
+     assertEquals("test/0-5", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/a-5"); // a is invalid - ignored
+     assertEquals("test/a-5", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/6-5"); // start > end is invalid - ignored
+     assertEquals("test/6-5", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/5"); // invalid - ignored
+     assertEquals("test/5", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/-5"); // invalid - ignored
+     assertEquals("test/-5", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/5-"); // invalid - ignored
+     assertEquals("test/5-", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName("test/5-6-7"); // invalid - ignored
+     assertEquals("test/5-6-7", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+     sq.setName(null); // invalid, gets converted to space
+     assertEquals("", sq.getName());
+     assertEquals(7, sq.getStart());
+     assertEquals(99, sq.getEnd());
+   }
+   @Test(groups = { "Functional" })
+   public void testCheckValidRange()
+   {
+     Sequence sq = new Sequence("test/7-12", "-ABC---DE-F--");
+     assertEquals(7, sq.getStart());
+     assertEquals(12, sq.getEnd());
+     /*
+      * checkValidRange ensures end is at least the last residue position
+      */
+     PA.setValue(sq, "end", 2);
+     sq.checkValidRange();
+     assertEquals(12, sq.getEnd());
+     /*
+      * end may be beyond the last residue position
+      */
+     PA.setValue(sq, "end", 22);
+     sq.checkValidRange();
+     assertEquals(22, sq.getEnd());
+   }
  }