thomasmueller commented on code in PR #2447:
URL: https://github.com/apache/jackrabbit-oak/pull/2447#discussion_r2273341185


##########
oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/TraverserTest.java:
##########
@@ -348,10 +346,179 @@ public void 
testBreadthFirstOrderTraversalWithRandomTree() {
         Assert.assertEquals(result, 
traverser.breadthFirstTraversal(root).transform(Node::getValue).toList());
     }
 
+    @Test
+    public void testPostOrderTraversalWithNormalTree() {
+        // Create a simple tree structure:
+        //       1
+        //     /   \
+        //    2     3
+        //   / \   / \
+        //  4   5 6   7
+        Node root = new Node(1,
+                new Node(2,
+                        new Node(4),
+                        new Node(5)),
+                new Node(3,
+                        new Node(6),
+                        new Node(7)));
+
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();
+
+        // In post-order: visit left subtree, right subtree, then root
+        Assert.assertEquals(Arrays.asList(4, 5, 2, 6, 7, 3, 1), result);
+    }
+
+    @Test
+    public void testPostOrderTraversalWithNullRoot() {
+        Assert.assertThrows(NullPointerException.class, () -> 
Traverser.postOrderTraversal(null, Node::getChildren));
+    }
+
+    @Test
+    public void testPostOrderTraversalWithSingleNode() {
+        Node root = new Node(1);
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();
+
+        Assert.assertEquals(Collections.singletonList(1), result);
+    }
+
+    @Test
+    public void testPostOrderTraversalWithAsymmetricTree() {
+        // Create an asymmetric tree:
+        //       1
+        //     /   \
+        //    2     3
+        //   /       \
+        //  4         7
+        //   \
+        //    5
+        Node root = new Node(1,
+                new Node(2,
+                        new Node(4,
+                                new Node(5))),
+                new Node(3,
+                        new Node(7)));
+
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();
+
+        // In post-order: visit children before parent
+        Assert.assertEquals(Arrays.asList(5, 4, 2, 7, 3, 1), result);
+    }
+
+    @Test
+    public void testPostOrderTraversalWithNullChildExtractor() {
+        Node root = new Node(1);
+        Assert.assertThrows(NullPointerException.class, () -> 
Traverser.postOrderTraversal(root, null));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testPostOrderTraversalWithNullChildren() {
+        // A tree with some null children
+        Node root = new Node(1,
+                null,
+                new Node(3));
+
+        Traverser.postOrderTraversal(root, 
Node::getChildren).transform(Node::getValue).forEach(System.out::println);
+
+        Assert.fail("Shouldn't reach here");
+    }
+
+    @Test
+    public void testPostOrderTraversalWithDeepTree() {
+        // Create a deep tree with many levels (linked-list-like)
+        Node n1 = new Node(1);
+        Node n2 = new Node(2);
+        Node n3 = new Node(3);
+        Node n4 = new Node(4);
+        Node n5 = new Node(5);
+
+        n1.addChild(n2);
+        n2.addChild(n3);
+        n3.addChild(n4);
+        n4.addChild(n5);
+
+        List<Integer> result = Traverser.postOrderTraversal(n1, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();
+
+        // In post-order: deepest nodes first
+        Assert.assertEquals(Arrays.asList(5, 4, 3, 2, 1), result);
+    }
+
+    @Test
+    public void testPostOrderTraversalWithBinarySearchTree() {
+        // Create a binary search tree structure
+        //        4
+        //      /   \
+        //     2     6
+        //    / \   / \
+        //   1   3 5   7
+        Node root = new Node(4,
+                new Node(2,
+                        new Node(1),
+                        new Node(3)),
+                new Node(6,
+                        new Node(5),
+                        new Node(7)));
+
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren).transform(Node::getValue).toList();
+        Assert.assertEquals(Arrays.asList(1, 3, 2, 5, 7, 6, 4), result);
+    }
+
+    @Test
+    public void testPostOrderTraversalWithTree() {
+        // Create a tree structure
+        //        4
+        //      /   \
+        //   0,2     6
+        //    /       \
+        //  1,3,5   7,8,9
+        Node root = new Node(4,
+                new Node(0),
+                new Node(2,
+                        new Node(1),
+                        new Node(3),
+                        new Node(5)),
+                new Node(6,
+                        new Node(7),
+                        new Node(8),
+                        new Node(9)));
+
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();
+
+        // In post-order: left subtree, right subtree, root
+        Assert.assertEquals(Arrays.asList(0, 1, 3, 5, 2, 7, 8, 9, 6, 4), 
result);
+    }
+
+    // TODO remove this test when we remove guava dependency
+    @Test
+    public void testPostOrderTraversalWithRandomTree() {
+
+        final Node root = getRoot(10000);
+
+        List<Integer> result = Traverser.postOrderTraversal(root, 
Node::getChildren)
+                .transform(Node::getValue)
+                .toList();

Review Comment:
   What the random data does not seem to include is edge cases, like null 
entries, null iterators, iterators that throw exceptions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to