X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fanalysis%2FRnaTest.java;fp=test%2Fjalview%2Fanalysis%2FRnaTest.java;h=2c51a1ba01752ef157198c99461d661f53bcd934;hb=0715e493687eeb93d3b3f39cd1ff25e2671ce0e9;hp=5801437cc932210ce62c42d5fde451afd198c792;hpb=ba66677097af3b383a2b3a01228d374dc7a4b1f9;p=jalview.git diff --git a/test/jalview/analysis/RnaTest.java b/test/jalview/analysis/RnaTest.java index 5801437..2c51a1b 100644 --- a/test/jalview/analysis/RnaTest.java +++ b/test/jalview/analysis/RnaTest.java @@ -21,6 +21,9 @@ package jalview.analysis; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.fail; import jalview.analysis.SecStrConsensus.SimpleBP; @@ -35,11 +38,12 @@ public class RnaTest public void testGetSimpleBPs() throws WUSSParseException { String rna = "([{})]"; // JAL-1081 example - Vector bps = Rna.GetSimpleBPs(rna); + Vector bps = Rna.getSimpleBPs(rna); assertEquals(3, bps.size()); /* * the base pairs are added in the order in which the matching base is found + * (popping the stack of unmatched opening brackets) */ assertEquals(2, bps.get(0).bp5); // { assertEquals(3, bps.get(0).bp3); // } @@ -55,25 +59,143 @@ public class RnaTest String rna = "(([{})]"; try { - Rna.GetSimpleBPs(rna); + Rna.getSimpleBPs(rna); fail("expected exception"); } catch (WUSSParseException e) { - // expected + // error reported as after end of input string + assertEquals(rna.length(), e.getProblemPos()); } } @Test(groups = { "Functional" }) public void testGetSimpleBPs_unmatchedCloser() { - String rna = "([{})]]"; + String rna = "([{})]]]"; try { - Rna.GetSimpleBPs(rna); + Rna.getSimpleBPs(rna); fail("expected exception"); } catch (WUSSParseException e) { - // expected + // error reported as at first unmatched close + assertEquals(6, e.getProblemPos()); + } + + /* + * a variant where we have no opening bracket of the same type + * as the unmatched closing bracket (no stack rather than empty stack) + */ + rna = "((()])"; + try + { + Rna.getSimpleBPs(rna); + fail("expected exception"); + } catch (WUSSParseException e) + { + assertEquals(4, e.getProblemPos()); + } + } + + @Test(groups = { "Functional" }) + public void testGetRNASecStrucState() + { + assertNull(Rna.getRNASecStrucState(null)); + for (int i = 0; i <= 255; i++) + { + String s = String.valueOf((char) i); + String ss = Rna.getRNASecStrucState(s); + + /* + * valid SS chars are a-z, A-Z, and various brackets; + * anything else is returned as a space + */ + if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') + || "()[]{}<>".indexOf(s) > -1) + { + assertEquals("" + i, s, ss); + } + else + { + assertEquals(" ", ss); + } + } + + /* + * a string is processed character by character + */ + assertEquals("a [K ]z} {Q b(w)p> are closing bracket symbols + */ + for (int i = 0; i <= 255; i++) + { + boolean isClosing = Rna.isClosingParenthesis((char) i); + if ((i >= 'a' && i <= 'z') || i == ')' || i == '}' || i == ']' + || i == '>') + { + assertTrue(String.format("close base pair %c", i), isClosing); + } + else + { + assertFalse(String.format("close base pair %c", i), isClosing); + } + } + } + + @Test(groups = { "Functional" }) + public void testIsCanonicalOrWobblePair() + { + String bases = "acgtuACGTU"; + for (int i = 0; i < bases.length(); i++) + { + for (int j = 0; j < bases.length(); j++) + { + char first = bases.charAt(i); + char second = bases.charAt(j); + boolean result = Rna.isCanonicalOrWobblePair(first, second); + String pair = new String(new char[] { first, second }) + .toUpperCase(); + if (pair.equals("AT") || pair.equals("TA") || pair.equals("AU") + || pair.equals("UA") || pair.equals("GC") + || pair.equals("CG") || pair.equals("GT") + || pair.equals("TG") || pair.equals("GU") + || pair.equals("UG")) + { + assertTrue(pair + " should be valid", result); + } + else + { + assertFalse(pair + " should be invalid", result); + } + } + } + } + + @Test(groups = { "Functional" }) + public void testIsOpeningParenthesis() + { + /* + * only A-Z, ([{< are opening bracket symbols + */ + for (int i = 0; i <= 255; i++) + { + boolean isOpening = Rna.isOpeningParenthesis((char) i); + if ((i >= 'A' && i <= 'Z') || i == '(' || i == '{' || i == '[' + || i == '<') + { + assertTrue(String.format("Open base pair %c", i), isOpening); + } + else + { + assertFalse(String.format("Open base pair %c", i), isOpening); + } } } }