@Test public void depthFirst() throws Exception { assertEquals( Collections.<Integer>emptyList(), SortingNode.<Integer>emptyRoot().depthFirst().collect(toList())); 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(); assertEquals( asList(100, 200, 210, 220, 300, 400, 410, 420, 430, 431), tree.depthFirst().collect(toList())); SortingNode<Integer> n400 = tree.getChildren().get(3); assertEquals(asList(400, 410, 420, 430, 431), n400.depthFirst().collect(toList())); }
@Test public void emptyRoot() throws Exception { SortingNode<Long> emptyRoot = SortingNode.emptyRoot(); assertFalse(emptyRoot.hasChild()); assertTrue(emptyRoot.isRoot()); assertFalse(emptyRoot.hasParent()); }