public Match(SequenceI seq, int start, int end)
{
sequence = seq;
- this.start = start;
- this.end = end;
+
+ /*
+ * always hold in forwards order, even if given in reverse order
+ * (such as from a mapping to a reverse strand); this avoids
+ * trouble for routines that highlight search results etc
+ */
+ if (start <= end)
+ {
+ this.start = start;
+ this.end = end;
+ }
+ else
+ {
+ this.start = end;
+ this.end = start;
+ }
}
public SequenceI getSequence()
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.datamodel.SearchResults.Match;
+
import org.testng.annotations.Test;
public class SearchResultsTest
sr2.addResult(seq1, 6, 8);
assertEquals(sr1.hashCode(), sr2.hashCode());
}
+
+ /**
+ * Verify that SearchResults$Match constructor normalises start/end to the
+ * 'forwards' direction
+ */
+ @Test(groups = { "Functional" })
+ public void testMatchConstructor()
+ {
+ SequenceI seq1 = new Sequence("", "abcdefghijklm");
+ Match m = new SearchResults().new Match(seq1, 2, 5);
+ assertSame(seq1, m.getSequence());
+ assertEquals(2, m.getStart());
+ assertEquals(5, m.getEnd());
+
+ // now a reverse mapping:
+ m = new SearchResults().new Match(seq1, 5, 2);
+ assertSame(seq1, m.getSequence());
+ assertEquals(2, m.getStart());
+ assertEquals(5, m.getEnd());
+ }
}