1 package jalview.datamodel.features;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import jalview.datamodel.Range;
8 import jalview.datamodel.SequenceFeature;
10 import java.util.ArrayList;
11 import java.util.List;
13 import junit.extensions.PA;
15 import org.testng.annotations.Test;
17 public class NCNodeTest
19 @Test(groups = "Functional")
22 Range r1 = new Range(10, 20);
23 NCNode<Range> node = new NCNode<Range>(r1);
24 assertEquals(node.getBegin(), 10);
25 Range r2 = new Range(10, 15);
28 List<Range> contents = new ArrayList<Range>();
29 node.getEntries(contents);
30 assertEquals(contents.size(), 2);
31 assertTrue(contents.contains(r1));
32 assertTrue(contents.contains(r2));
36 groups = "Functional",
37 expectedExceptions = { IllegalArgumentException.class })
38 public void testAdd_invalidRangeStart()
40 Range r1 = new Range(10, 20);
41 NCNode<Range> node = new NCNode<Range>(r1);
42 assertEquals(node.getBegin(), 10);
43 Range r2 = new Range(9, 15);
48 groups = "Functional",
49 expectedExceptions = { IllegalArgumentException.class })
50 public void testAdd_invalidRangeEnd()
52 Range r1 = new Range(10, 20);
53 NCNode<Range> node = new NCNode<Range>(r1);
54 assertEquals(node.getBegin(), 10);
55 Range r2 = new Range(12, 21);
59 @Test(groups = "Functional")
60 public void testGetEntries()
62 Range r1 = new Range(10, 20);
63 NCNode<Range> node = new NCNode<Range>(r1);
64 List<Range> entries = new ArrayList<Range>();
66 node.getEntries(entries);
67 assertEquals(entries.size(), 1);
68 assertTrue(entries.contains(r1));
70 // clearing the returned list does not affect the NCNode
72 node.getEntries(entries);
73 assertEquals(entries.size(), 1);
74 assertTrue(entries.contains(r1));
76 Range r2 = new Range(15, 18);
79 node.getEntries(entries);
80 assertEquals(entries.size(), 2);
81 assertTrue(entries.contains(r1));
82 assertTrue(entries.contains(r2));
86 * Tests for the contains method (uses entry.equals() test)
88 @Test(groups = "Functional")
89 public void testContains()
91 SequenceFeature sf1 = new SequenceFeature("type", "desc", 1, 10, 2f,
93 SequenceFeature sf2 = new SequenceFeature("type", "desc", 1, 10, 2f,
95 SequenceFeature sf3 = new SequenceFeature("type", "desc", 1, 10, 2f,
97 NCNode<SequenceFeature> node = new NCNode<SequenceFeature>(sf1);
99 assertFalse(node.contains(null));
100 assertTrue(node.contains(sf1));
101 assertTrue(node.contains(sf2)); // sf1.equals(sf2)
102 assertFalse(node.contains(sf3)); // !sf1.equals(sf3)
106 * Test method that checks for valid structure. Valid means that all
107 * subregions (if any) lie within the root range, and that all subregions have
110 @Test(groups = "Functional")
111 public void testIsValid()
113 Range r1 = new Range(10, 20);
114 Range r2 = new Range(14, 15);
115 Range r3 = new Range(16, 17);
116 NCNode<Range> node = new NCNode<Range>(r1);
121 * node has root range [10-20] and contains an
122 * NCList of [14-15, 16-17]
124 assertTrue(node.isValid());
125 PA.setValue(r1, "start", 15);
126 assertFalse(node.isValid()); // r2 not within r1
127 PA.setValue(r1, "start", 10);
128 assertTrue(node.isValid());
129 PA.setValue(r1, "end", 16);
130 assertFalse(node.isValid()); // r3 not within r1
131 PA.setValue(r1, "end", 20);
132 assertTrue(node.isValid());
133 PA.setValue(r3, "start", 12);
134 assertFalse(node.isValid()); // r3 should precede r2