How do I write a unit test for an in order traversal of a binary tree

Java
public void inOrder(){
InOrderTraverse(root);
}

private void inOrderTraverse(TreeNode root){
If( root != null){
inOrderTraverse(root.left);
System.out.print(root.val + “—>”);
inOrderTraverse(root.right);
}
}
Java
public void inOrder(){
InOrderTraverse(root);
}

private void inOrderTraverse(TreeNode root){
If( root != null){
inOrderTraverse(root.left);
System.out.print(root.val + “—>”);
inOrderTraverse(root.right);
}
}
11 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @ukpagrace! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
JavaBot
JavaBot2w ago
Please format your code to make it more readable. For java, it should look like this:
​`​`​`​java
public void foo() {

}
​`​`​`​
​`​`​`​java
public void foo() {

}
​`​`​`​
ayylmao123xdd
ayylmao123xdd2w ago
just call the method for in order traverse and check if the method is called in the proper order you can use something like verify() and to check if the arguments of the method are in the correct order
ukpagrace
ukpagraceOP2w ago
Is verify an assertion, checked but didn’t see it
rangry
rangry2w ago
Yo
ayylmao123xdd
ayylmao123xdd2w ago
yes assertion from mockito
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verify;
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
ukpagrace
ukpagraceOP2w ago
Okay thank you
JavaBot
JavaBot2w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
naveen_galatta
Use verify method
JavaBot
JavaBot6d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server