From 973f509dd763aa57abd60605b5f28292c8cebfe4 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Thu, 12 Nov 2015 13:15:04 +0000 Subject: [PATCH] JAL-753_JAL-1427 basic test cases for SequenceIdMatcher --- test/jalview/analysis/SequenceIdMatcherTest.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/jalview/analysis/SequenceIdMatcherTest.java diff --git a/test/jalview/analysis/SequenceIdMatcherTest.java b/test/jalview/analysis/SequenceIdMatcherTest.java new file mode 100644 index 0000000..be2497a --- /dev/null +++ b/test/jalview/analysis/SequenceIdMatcherTest.java @@ -0,0 +1,86 @@ +package jalview.analysis; + +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; + +import java.util.Arrays; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class SequenceIdMatcherTest +{ + private static SequenceI[] someseqs = { + new Sequence("A|ComplexId", "dummy"), + new Sequence("A|ComplexId|confused", "dummy"), + new Sequence("A|ComplexId|bits_of", "dummy"), + new Sequence("ComplexId", "dummy"), + new Sequence("A|ComplexIdNot", "dummy"), + new Sequence("A ComplexId Id", "dummy"), + new Sequence("complexid", "dummy") }; + + private static SequenceIdMatcher getMatcher() + { + return new SequenceIdMatcher(Arrays.asList(someseqs)); + } + + @Test(groups = { "Functional" }) + public void findSelfAndOthers() + { + for (SequenceI sq : SequenceIdMatcherTest.someseqs) + { + SequenceI[] idmatches = getMatcher().findAllIdMatches(sq.getName()); + Assert.assertTrue( + idmatches.length >= 1, + "Couldn't recover at least one sequence for string '" + + sq.getName() + "'"); + SequenceI[] seqmatches = getMatcher().findIdMatch( + new SequenceI[] { sq }); + Assert.assertTrue(seqmatches.length >= 1, + "Couldn't recover at least one sequence for sequence object called '" + + sq.getName() + "'"); + Assert.assertTrue(seqmatches.length == idmatches.length, + "Different matches found for '" + sq.getName() + "'"); + for (SequenceI sid : idmatches) + { + boolean found = false; + for (SequenceI sobj : seqmatches) + { + if (sid == sobj) + { + found = true; + } + } + Assert.assertTrue( + found, + "Different sequences recovered for Id " + + "and SequenceI (Couldn't find match for '" + + sid.getName() + "')"); + + } + } + } + + @Test(groups = { "Functional" }) + public void testExactMatch() + { + SequenceI[] matches = getMatcher().findAllIdMatches("A|ComplexId"); + Assert.assertTrue(matches.length == 1, + "Exact match failed for 'A|ComplexId'"); + matches = getMatcher().findAllIdMatches("A|ComplexId|confused"); + Assert.assertTrue(matches.length == 1, + "Exact match failed for 'A|ComplexId|confused'"); + matches = getMatcher().findAllIdMatches("A|ComplexId|bits_of"); + Assert.assertTrue(matches.length == 1, + "Exact match failed for 'A|ComplexId|bits_of'"); + matches = getMatcher().findAllIdMatches("A ComplexId Id"); + Assert.assertTrue(matches.length == 1, + "Exact match failed for 'A Complex Id'"); + + } + + public void testContainedMatch() + { + + } +} -- 1.7.10.2