X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fanalysis%2FParsePropertiesTest.java;h=221d47ee670b982407f42e7ffbae4ee25e49ac01;hb=ab22918ab8fc67d30dad1fb1ae0f37e51f49df95;hp=a679a469aa8fc8a9c36bac511f3dcb2eeaecfd40;hpb=d07fe6a0891b57a9d707e356f7769395ce94b0da;p=jalview.git diff --git a/test/jalview/analysis/ParsePropertiesTest.java b/test/jalview/analysis/ParsePropertiesTest.java index a679a46..221d47e 100644 --- a/test/jalview/analysis/ParsePropertiesTest.java +++ b/test/jalview/analysis/ParsePropertiesTest.java @@ -1,16 +1,18 @@ package jalview.analysis; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Before; -import org.junit.Test; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNull; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; +import java.util.List; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + public class ParsePropertiesTest { @@ -21,7 +23,7 @@ public class ParsePropertiesTest /** * Construct an alignment with 4 sequences with varying description format */ - @Before + @BeforeMethod public void setUp() { SequenceI[] seqs = new SequenceI[] @@ -44,12 +46,9 @@ public class ParsePropertiesTest * more 'number characters' (0-9+.), i.e. greedily matches any trailing * numeric part of the string */ - @Test + @Test(groups ={ "Functional" }) public void testGetScoresFromDescription() { - // TODO - test the regex actually used by Jalview? - // \\W*([-+eE0-9.]+) - // see AlignFrame.extractScores_actionPerformed String regex = ".*([-0-9.+]+)"; final int count = pp.getScoresFromDescription("my Score", "my Score Description", regex, true); @@ -83,7 +82,7 @@ public class ParsePropertiesTest * character, followed by at least one 'number character', then any trailing * characters. */ - @Test + @Test(groups ={ "Functional" }) public void testGetScoresFromDescription_twoScores() { String regex = ".*([-0-9.+]+).+([-0-9.+]+).*"; @@ -138,4 +137,57 @@ public class ParsePropertiesTest assertEquals("my Score Description (column 1)", anns[1].description); assertEquals("my Score_1", anns[1].label); } + + /** + * Test with a regex that looks for numbers separated by words - as currently + * used in Jalview (May 2015) + * + * @see AlignFrame.extractScores_actionPerformed + */ + @Test(groups ={ "Functional" }) + public void testGetScoresFromDescription_wordBoundaries() + { + String regex = "\\W*([-+eE0-9.]+)"; + List seqs = al.getSequences(); + seqs.get(0).setDescription("Ferredoxin"); + seqs.get(1).setDescription(" Ferredoxin-1, chloroplast precursor"); + seqs.get(2).setDescription("GH28E30p"); + seqs.get(3).setDescription("At1g10960/T19D16_12"); + final int count = pp.getScoresFromDescription("description column", + "score in description column ", regex, true); + assertEquals(3, count); + + /* + * No score parsable from seq1 description + */ + AlignmentAnnotation[] anns = al.getSequenceAt(0).getAnnotation(); + assertNull(anns); + + /* + * Seq2 description has a '1' in it + */ + anns = al.getSequenceAt(1).getAnnotation(); + assertEquals(1, anns.length); + assertEquals(1d, anns[0].getScore(), 0.001d); + + /* + * Seq3 description has '28E30' in it + * + * Note: 1.8E308 or larger would result in 'Infinity' + */ + anns = al.getSequenceAt(2).getAnnotation(); + assertEquals(1, anns.length); + assertEquals(2.8E31d, anns[0].getScore(), 0.001d); + + /* + * Seq4 description has several numbers in it + */ + anns = al.getSequenceAt(3).getAnnotation(); + assertEquals(5, anns.length); + assertEquals(1d, anns[0].getScore(), 0.001d); + assertEquals(10960d, anns[1].getScore(), 0.001d); + assertEquals(19d, anns[2].getScore(), 0.001d); + assertEquals(16d, anns[3].getScore(), 0.001d); + assertEquals(12d, anns[4].getScore(), 0.001d); + } }