JAL-1081 unit tests added
[jalview.git] / test / jalview / analysis / RnaTest.java
1 package jalview.analysis;
2
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.fail;
5
6 import jalview.analysis.SecStrConsensus.SimpleBP;
7
8 import java.util.Vector;
9
10 import org.testng.annotations.Test;
11 public class RnaTest
12 {
13   @Test
14   public void testGetSimpleBPs() throws WUSSParseException
15   {
16     String rna = "([{})]"; // JAL-1081 example
17     Vector<SimpleBP> bps = Rna.GetSimpleBPs(rna);
18     assertEquals(3, bps.size());
19
20     /*
21      * the base pairs are added in the order in which the matching base is found
22      */
23     assertEquals(2, bps.get(0).bp5); // {
24     assertEquals(3, bps.get(0).bp3); // }
25     assertEquals(0, bps.get(1).bp5); // (
26     assertEquals(4, bps.get(1).bp3); // )
27     assertEquals(1, bps.get(2).bp5); // [
28     assertEquals(5, bps.get(2).bp3); // ]
29   }
30
31   @Test
32   public void testGetSimpleBPs_unmatchedOpener()
33   {
34     String rna = "(([{})]";
35     try
36     {
37       Rna.GetSimpleBPs(rna);
38       fail("expected exception");
39     } catch (WUSSParseException e)
40     {
41       // expected
42     }
43   }
44
45   @Test
46   public void testGetSimpleBPs_unmatchedCloser()
47   {
48     String rna = "([{})]]";
49     try
50     {
51       Rna.GetSimpleBPs(rna);
52       fail("expected exception");
53     } catch (WUSSParseException e)
54     {
55       // expected
56     }
57   }
58 }