JAL-3490 unit test for ignore hidden regions with selection group
[jalview.git] / test / jalview / analysis / FinderTest.java
index 78a27ac..725be33 100644 (file)
@@ -401,7 +401,7 @@ public class FinderTest
    * result
    */
   @Test(groups = "Functional")
-  public void testFind_maximalResultOnly()
+  public void testFindAll_maximalResultOnly()
   {
     Finder f = new Finder(av);
     f.findAll("M+", false, false, false);
@@ -495,7 +495,7 @@ public class FinderTest
    * Test finding next match of a sequence pattern in a selection group
    */
   @Test(groups = "Functional")
-  public void testFind_inSelection()
+  public void testFindNext_inSelection()
   {
     /*
      * select sequences 2 and 3, columns 4-6 which contains
@@ -549,7 +549,7 @@ public class FinderTest
    * Test finding all matches of a search pattern in a selection group
    */
   @Test(groups = "Functional")
-  public void testFind_findAllInSelection()
+  public void testFindAll_inSelection()
   {
     /*
      * select sequences 2 and 3, columns 4-6 which contains
@@ -795,7 +795,7 @@ public class FinderTest
   }
 
   @Test(groups = "Functional")
-  public void testFind_skipHiddenColumns()
+  public void testFind_ignoreHiddenColumns()
   {
     /*
      * 0    5   9
@@ -878,5 +878,32 @@ public class FinderTest
     assertSame(match.getSequence(), al.getSequenceAt(0));
     assertEquals(match.getStart(), 14); // G
     assertEquals(match.getEnd(), 14);
+
+    /*
+     * now select columns 0-9 and search for A.*H
+     * this should match in the second sequence (split as 3 matches)
+     * but not the first (as H is outside the selection)
+     */
+    SequenceGroup selection = new SequenceGroup();
+    selection.setStartRes(0);
+    selection.setEndRes(9);
+    al.getSequences().forEach(seq -> selection.addSequence(seq, false));
+    av.setSelectionGroup(selection);
+    f.findAll("A.*H", false, false, true);
+    searchResults = f.getSearchResults();
+    assertEquals(searchResults.getSize(), 3);
+    // match made of contiguous matches A, DE, H
+    match = searchResults.getResults().get(0);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 1); // A
+    assertEquals(match.getEnd(), 1);
+    match = searchResults.getResults().get(1);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 4); // D
+    assertEquals(match.getEnd(), 5); // E
+    match = searchResults.getResults().get(2);
+    assertSame(match.getSequence(), al.getSequenceAt(1));
+    assertEquals(match.getStart(), 7); // H (there is no G)
+    assertEquals(match.getEnd(), 7);
   }
 }