From 7faa960aada437a5e848562681244c9ec7ccdfb9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 15 Feb 2017 15:45:06 +0000 Subject: [PATCH] JAL-2374 tests for SequenceGroup.contains --- test/jalview/datamodel/SequenceGroupTest.java | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/jalview/datamodel/SequenceGroupTest.java b/test/jalview/datamodel/SequenceGroupTest.java index 4b786c0..65549f2 100644 --- a/test/jalview/datamodel/SequenceGroupTest.java +++ b/test/jalview/datamodel/SequenceGroupTest.java @@ -112,4 +112,75 @@ public class SequenceGroupTest assertNull(sg3.getContext()); } } + + @Test(groups = { "Functional" }) + public void testContains() + { + /* + * essentially the same tests as AlignmentI.findGroup + * but from a particular group's perspective + */ + + SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI"); + SequenceI seq2 = new Sequence("seq2", "---JKLMNO---"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 }); + /* + * add a group consisting of just "DEF" + */ + SequenceGroup sg1 = new SequenceGroup(); + sg1.addSequence(seq1, false); + sg1.setStartRes(3); + sg1.setEndRes(5); + + /* + * test sequence membership + */ + assertTrue(sg1.contains(seq1)); + assertFalse(sg1.contains(seq2)); + + /* + * test sequence+position + */ + + assertFalse(sg1.contains(seq1, 2)); // position not in group + assertFalse(sg1.contains(seq1, 6)); // position not in group + assertFalse(sg1.contains(seq2, 5)); // sequence not in group + assertTrue(sg1.contains(seq1, 3)); // yes + assertTrue(sg1.contains(seq1, 4)); + assertTrue(sg1.contains(seq1, 5)); + + /* + * 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); + + /* + * if a residue is in more than one group, method returns + * the first found (in order groups were added) + */ + assertTrue(sg2.contains(seq1, 4)); + assertTrue(sg2.contains(seq1, 5)); + + /* + * seq2 only belongs to the second group + */ + assertTrue(sg2.contains(seq2, 4)); + assertTrue(sg2.contains(seq2, 5)); + assertTrue(sg2.contains(seq2, 6)); + assertTrue(sg2.contains(seq2, 7)); + assertFalse(sg2.contains(seq2, 3)); + assertFalse(sg2.contains(seq2, 8)); + sg2.setEndRes(8); + assertTrue(sg2.contains(seq2, 8)); + sg2.deleteSequence(seq2, false); + assertFalse(sg2.contains(seq2)); + + } } -- 1.7.10.2