Пример #1
0
  @Test
  public void buildNodeTree() throws Exception {

    SortingNode<String> root = new SortingNode.Builder<String>().build();
    assertFalse(root.hasChild());
    assertTrue(root.isRoot());
    assertFalse(root.hasParent());

    SortingNode<Integer> tree =
        new SortingNode.Builder<Integer>() //
            .childNode(100)
            .siblingNode(200)
            .childNode(210)
            .siblingNode(220)
            .parent()
            .siblingNode(300)
            .siblingNode(400)
            .childNode(410)
            .siblingNode(420)
            .siblingNode(430)
            .childNode(431)
            .build();

    assertFalse(tree.hasParent());
    assertTrue(tree.isRoot());
    assertFalse(tree.hasParent());

    String expected =
        ""
            + "*\n"
            + "  100\n"
            + "  200\n"
            + "    210\n"
            + "    220\n"
            + "  300\n"
            + "  400\n"
            + "    410\n"
            + "    420\n"
            + "    430\n"
            + "      431";
    assertEquals(expected, tree.prettyPrint());

    SortingNode<Integer> n410 = tree.getChildren().get(3).getChildren().get(0);
    assertFalse(n410.hasChild());
    assertTrue(n410.hasParent());
    assertFalse(n410.isRoot());

    assertEquals("410", n410.prettyPrint());
  }
Пример #2
0
 @Test
 public void emptyRoot() throws Exception {
   SortingNode<Long> emptyRoot = SortingNode.emptyRoot();
   assertFalse(emptyRoot.hasChild());
   assertTrue(emptyRoot.isRoot());
   assertFalse(emptyRoot.hasParent());
 }