1 29 package jegg.type; 30 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 34 import sun.security.krb5.internal.i; 35 36 import jegg.impl.TestBase; 37 38 41 public class NodeTest extends TestBase 42 { 43 static 44 { 45 setTestClass(NodeTest.class); 46 } 47 private Node nodeA, nodeA1, nodeA2; 48 private Node nodeB, nodeB1, nodeB2; 49 private Node nodeC, nodeC1, nodeC2; 50 51 54 public NodeTest(String n) 55 { 56 super(n); 57 } 58 59 62 protected void setup() 63 { 64 nodeA = new Node(TypeA.class); 65 nodeA1 = new Node(TypeA1.class); 66 nodeA2 = new Node(TypeA2.class); 67 nodeB = new Node(TypeB.class); 68 nodeB1 = new Node(TypeB1.class); 69 nodeB2 = new Node(TypeB2.class); 70 nodeC = new Node(TypeC.class); 71 nodeC1 = new Node(TypeC1.class); 72 nodeC2 = new Node(TypeC2.class); 73 } 74 75 78 protected void teardown() 79 { 80 } 82 83 public void test1() 84 { 85 nodeA.insert(nodeC); 86 nodeA.insert(nodeB); 87 88 assertNotNull(nodeA.findNearest(TypeB.class)); 89 assertNotNull(nodeA.findNearest(TypeC.class)); 90 91 Collection a_branches = nodeA.getBranches(); 92 assertNotNull(a_branches); 93 assertEquals(1,a_branches.size()); 94 95 Node b = (Node) a_branches.iterator().next(); 96 assertNotNull(b); 97 assertEquals(nodeB.getType(), b.getType()); 98 99 Collection b_branches = b.getBranches(); 100 assertNotNull(b_branches); 101 assertEquals(1,b_branches.size()); 102 103 Node c = (Node) b_branches.iterator().next(); 104 assertNotNull(c); 105 assertEquals(nodeC.getType(), c.getType()); 106 } 107 108 public void test2() 109 { 110 nodeA.insert(nodeC); 111 nodeA.insert(nodeC1); 112 nodeA.insert(nodeC2); 113 114 Collection a_branches = nodeA.getBranches(); 115 assertNotNull(a_branches); 116 assertEquals(1,a_branches.size()); 117 118 Node c = (Node) a_branches.iterator().next(); 119 assertNotNull(c); 120 assertEquals(nodeC.getType(), c.getType()); 121 122 Collection c_branches = c.getBranches(); 123 assertNotNull(c_branches); 124 assertEquals(2,c_branches.size()); 125 126 Iterator it = c_branches.iterator(); 127 Node c1 = (Node) it.next(); 128 Node c2 = (Node) it.next(); 129 assertTrue( 130 nodeC1.getType().equals(c1.getType()) || 131 nodeC2.getType().equals(c1.getType())); 132 assertTrue( 133 nodeC1.getType().equals(c2.getType()) || 134 nodeC2.getType().equals(c2.getType())); 135 assertFalse(c1.getType().equals(c2.getType())); 136 } 137 138 public void test3() 139 { 140 nodeA.insert(nodeC1); 141 nodeA.insert(nodeC2); 142 nodeA.insert(nodeC); 143 144 Collection a_branches = nodeA.getBranches(); 145 assertNotNull(a_branches); 146 assertEquals(1,a_branches.size()); 147 148 Node c = (Node) a_branches.iterator().next(); 149 assertNotNull(c); 150 assertEquals(nodeC.getType(), c.getType()); 151 152 Collection c_branches = c.getBranches(); 153 assertNotNull(c_branches); 154 assertEquals(2,c_branches.size()); 155 156 Iterator it = c_branches.iterator(); 157 Node c1 = (Node) it.next(); 158 Node c2 = (Node) it.next(); 159 assertTrue( 160 nodeC1.getType().equals(c1.getType()) || 161 nodeC2.getType().equals(c1.getType())); 162 assertTrue( 163 nodeC1.getType().equals(c2.getType()) || 164 nodeC2.getType().equals(c2.getType())); 165 assertFalse(c1.getType().equals(c2.getType())); 166 } 167 168 public void test4() 169 { 170 nodeA.insert(nodeC1); 171 nodeA.insert(nodeC2); 172 nodeA.insert(nodeC); 173 nodeA.insert(nodeB1); 174 nodeA.insert(nodeB2); 175 nodeA.insert(nodeB); 176 179 Collection a_branches = nodeA.getBranches(); 180 assertNotNull(a_branches); 181 assertEquals(1,a_branches.size()); 182 183 Node b = (Node) a_branches.iterator().next(); 184 assertNotNull(b); 185 assertEquals(nodeB.getType(), b.getType()); 186 187 Collection b_branches = b.getBranches(); 188 assertNotNull(b_branches); 189 assertEquals(3,b_branches.size()); 190 191 Iterator it = b_branches.iterator(); 192 Node b1 = (Node) it.next(); 193 Node b2 = (Node) it.next(); 194 Node b3 = (Node) it.next(); 195 assertTrue( 196 nodeB1.getType().equals(b1.getType()) || 197 nodeB2.getType().equals(b1.getType()) || 198 nodeC.getType().equals(b1.getType())); 199 assertTrue( 200 nodeB1.getType().equals(b2.getType()) || 201 nodeB2.getType().equals(b2.getType()) || 202 nodeC.getType().equals(b2.getType())); 203 assertTrue( 204 nodeB1.getType().equals(b3.getType()) || 205 nodeB2.getType().equals(b3.getType()) || 206 nodeC.getType().equals(b3.getType())); 207 Node c = null; 208 if (nodeC.getType().equals(b1.getType())) c = b1; 209 if (nodeC.getType().equals(b2.getType())) c = b2; 210 if (nodeC.getType().equals(b3.getType())) c = b3; 211 212 Collection c_branches = c.getBranches(); 213 assertNotNull(c_branches); 214 assertEquals(2,c_branches.size()); 215 it = c_branches.iterator(); 216 Node c1 = (Node) it.next(); 217 Node c2 = (Node) it.next(); 218 assertTrue( 219 nodeC1.getType().equals(c1.getType()) || 220 nodeC1.getType().equals(c2.getType())); 221 assertTrue( 222 nodeC2.getType().equals(c1.getType()) || 223 nodeC2.getType().equals(c2.getType())); 224 } 225 226 public void test5() 227 { 228 nodeB.insert(nodeB1); 229 nodeB.insert(nodeB2); 230 assertFalse(nodeB.insert(nodeA)); 231 assertTrue(nodeA.insert(nodeB)); 232 } 233 } 234 | Popular Tags |