From: gmungoc Date: Thu, 5 Jan 2017 16:31:55 +0000 (+0000) Subject: JAL-2374 unit test for (modified) Alignment.findGroup() X-Git-Tag: Release_2_10_3b1~382 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=976c518ffa15791c680156dd357d33f5a06c3a54;p=jalview.git JAL-2374 unit test for (modified) Alignment.findGroup() --- diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index d2f4b4d..618bac5 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -1131,4 +1131,63 @@ public class AlignmentTest assertSame(pep.getDatasetSequence(), cds.getDBRefs()[0].map.to); } + @Test(groups = { "Functional" }) + public void testFindGroup() + { + SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI"); + SequenceI seq2 = new Sequence("seq2", "---JKLMNO---"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 }); + + assertNull(a.findGroup(null, 0)); + assertNull(a.findGroup(seq1, 1)); + assertNull(a.findGroup(seq1, -1)); + + /* + * add a group consisting of just "DEF" + */ + SequenceGroup sg1 = new SequenceGroup(); + sg1.addSequence(seq1, false); + sg1.setStartRes(3); + sg1.setEndRes(5); + a.addGroup(sg1); + + assertNull(a.findGroup(seq1, 2)); // position not in group + assertNull(a.findGroup(seq1, 6)); // position not in group + assertNull(a.findGroup(seq2, 5)); // sequence not in group + assertSame(a.findGroup(seq1, 3), sg1); // yes + assertSame(a.findGroup(seq1, 4), sg1); + assertSame(a.findGroup(seq1, 5), sg1); + + /* + * add a group consisting of + * EF-- + * KLMN + */ + SequenceGroup sg2 = new SequenceGroup(); + sg2.addSequence(seq1, false); + sg2.addSequence(seq2, false); + sg2.setStartRes(4); + sg2.setEndRes(7); + a.addGroup(sg2); + + assertNull(a.findGroup(seq1, 2)); // unchanged + assertSame(a.findGroup(seq1, 3), sg1); // unchanged + /* + * if a residue is in more than one group, method returns + * the first found (in order groups were added) + */ + assertSame(a.findGroup(seq1, 4), sg1); + assertSame(a.findGroup(seq1, 5), sg1); + + /* + * seq2 only belongs to the second group + */ + assertSame(a.findGroup(seq2, 4), sg2); + assertSame(a.findGroup(seq2, 5), sg2); + assertSame(a.findGroup(seq2, 6), sg2); + assertSame(a.findGroup(seq2, 7), sg2); + assertNull(a.findGroup(seq2, 3)); + assertNull(a.findGroup(seq2, 8)); + } + }