From db438b70796b94abcc873a2dde1d3d46189346ed Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 1 Nov 2016 16:59:41 +0000 Subject: [PATCH] JAL-345 JAL-1738 new tests (failing) for SearchResultsI.markColumns --- test/jalview/datamodel/SearchResultsTest.java | 77 ++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/test/jalview/datamodel/SearchResultsTest.java b/test/jalview/datamodel/SearchResultsTest.java index e3cbb00..3118d2a 100644 --- a/test/jalview/datamodel/SearchResultsTest.java +++ b/test/jalview/datamodel/SearchResultsTest.java @@ -25,7 +25,7 @@ import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; -import jalview.datamodel.SearchResults.Match; +import java.util.BitSet; import org.testng.annotations.Test; @@ -189,4 +189,79 @@ public class SearchResultsTest assertEquals(2, m.getStart()); assertEquals(5, m.getEnd()); } + + /** + * test markColumns for creating column selections + */ + @Test(groups = { "Functional" }) + public void testMarkColumns() + { + int marked = 0; + SequenceI seq1 = new Sequence("", "abcdefghijklm"); + SequenceI seq2 = new Sequence("", "abcdefghijklm"); + SequenceGroup s1g=new SequenceGroup(), s2g=new SequenceGroup(), sallg=new SequenceGroup(); + s1g.addSequence(seq1, false); + s2g.addSequence(seq2, false); + sallg.addSequence(seq1, false); + sallg.addSequence(seq2, false); + + SearchResultsI sr = new SearchResults(); + BitSet bs = new BitSet(); + + sr.addResult(seq1, 1,1); + sr.addResult(seq2, 1,2); + + // set start/end range for groups to cover matches + + s1g.setStartRes(0); + s1g.setEndRes(5); + s2g.setStartRes(0); + s2g.setEndRes(5); + sallg.setStartRes(0); + sallg.setEndRes(5); + + /* + * just seq1 + */ + marked = sr.markColumns(s1g, bs); + // check the bitset cardinality before checking the return value + assertEquals("Didn't mark expected number", 1, bs.cardinality()); + assertEquals("Didn't return count of number of bits marked", 1, marked); + assertTrue("Didn't mark expected position", bs.get(0)); + // now check return value for marking the same again + assertEquals( + "Didn't count number of bits marked for existing marked set", + 0, + sr.markColumns(s1g, bs)); + bs.clear(); + + /* + * just seq2 + */ + marked = sr.markColumns(s2g, bs); + assertEquals("Didn't mark expected number", 2, bs.cardinality()); + assertEquals("Didn't return count of number of bits marked", 2, marked); + assertTrue("Didn't mark expected position (1)", bs.get(0)); + assertTrue("Didn't mark expected position (2)", bs.get(0)); + + /* + * both seq1 and seq2 + * should be same as seq2 + */ + BitSet allbs = new BitSet(); + assertEquals(2, sr.markColumns(sallg, allbs)); + assertEquals(bs, allbs); + + // now check range selecvtion + + /* + * limit s2g to just the second column, sallg to the first column + */ + s2g.setStartRes(1); + s2g.setEndRes(1); + sallg.setEndRes(0); + BitSet tbs; + assertEquals(1, sr.markColumns(s2g, tbs = new BitSet())); + assertEquals(1, sr.markColumns(sallg, tbs = new BitSet())); + } } -- 1.7.10.2