Пример #1
0
 @Test
 public void testHeight() {
   assertEquals(2, root.getHeight()); // depth of a
   assertEquals(1, root.getChildren().get(0).getHeight()); // depth of b
   assertEquals(0, root.getChildren().get(0).getChildren().get(0).getHeight()); // depth of c
   assertEquals(0, root.getChildren().get(0).getChildren().get(1).getHeight()); // depth of d
   assertEquals(0, root.getChildren().get(1).getHeight()); // depth of e
 }
Пример #2
0
 @Test
 public void testPreOrderNumbering() {
   TreeUtils.preOrderNumbering(root);
   assertEquals(0, root.getId()); // id of a
   assertEquals(1, root.getChildren().get(0).getId()); // id of b
   assertEquals(2, root.getChildren().get(0).getChildren().get(0).getId()); // id of c
   assertEquals(3, root.getChildren().get(0).getChildren().get(1).getId()); // id of d
   assertEquals(4, root.getChildren().get(1).getId()); // id of e
 }
Пример #3
0
 @Test
 public void testDepth() {
   TreeUtils.computeDepth(root);
   assertEquals(root.getDepth(), 0);
   assertEquals(root.getChildren().get(0).getDepth(), 1);
   assertEquals(root.getChildren().get(0).getChildren().get(0).getDepth(), 2);
   assertEquals(root.getChildren().get(0).getChildren().get(1).getDepth(), 2);
   assertEquals(root.getChildren().get(1).getDepth(), 1);
 }
Пример #4
0
 @Test
 public void testPostOrderNumbering() {
   TreeUtils.postOrderNumbering(root);
   assertEquals(root.getId(), 4);
   assertEquals(root.getChildren().get(0).getId(), 2);
   assertEquals(root.getChildren().get(0).getChildren().get(0).getId(), 0);
   assertEquals(root.getChildren().get(0).getChildren().get(1).getId(), 1);
   assertEquals(root.getChildren().get(1).getId(), 3);
 }
Пример #5
0
 @Test
 public void testRemoveCompletelyMappedDescendants() {
   dst.getChildren().get(0).setMatched(true);
   dst.getChildren().get(0).getChildren().get(0).getChildren().get(0).setMatched(true);
   dst.getChildren().get(1).setMatched(true);
   dst.getChildren().get(1).getChildren().get(0).setMatched(true);
   dst = TreeUtils.removeCompletelyMapped(dst);
   TreeUtils.computeSize(dst);
   assertTrue(dst.getSize() == 5);
 }
Пример #6
0
 @Test
 public void testBreadthFirstNumbering() {
   System.out.println(root.toCompleteTreeString());
   TreeUtils.breadthFirstNumbering(root);
   System.out.println(root.toCompleteTreeString());
   assertEquals(0, root.getId());
   assertEquals(1, root.getChildren().get(0).getId());
   assertEquals(2, root.getChildren().get(1).getId());
   assertEquals(3, root.getChildren().get(0).getChildren().get(0).getId());
   assertEquals(4, root.getChildren().get(0).getChildren().get(1).getId());
 }
Пример #7
0
 @Test
 public void testDigest() {
   Tree croot = root.deepCopy();
   TreeUtils.computeDigest(root);
   TreeUtils.computeDigest(croot);
   assertTrue(root.getDigest() == croot.getDigest());
   croot.getChildren().get(0).getChildren().get(0).setLabel("x");
   TreeUtils.computeDigest(croot);
   assertFalse(root.getDigest() == croot.getDigest());
   assertEquals("[(a@@0[(b@@1[(c@@3)][(d@@3)])][(e@@2)])]", root.toDigestTreeString());
 }