Kotlinlearncs.online LogoJava
Return to List

Test Writing: Binary Tree Count Non-Leaves

Created By: Geoffrey Challen
/ Version: 2021.4.0

Create a method named countNonLeaves that accepts a single BinaryTree<*>? and counts the number of non-leaves in the tree. As a reminder, a leaf node has no children, so a non-leaf node has at least one child. If the passed tree is null, you can return 0, since an empty tree has no nodes and so no non-leaf nodes.

For reference, cs125.trees.BinaryTree is defined like this:

Test Design Challenge

You're challenge is to write tests for this problem described above.

  • Provide a public class named TestBinaryTreeCounter with a single non-private class method named test that accepts no arguments and does not return a value.
  • If the implementation of the class described above is incorrect, your test method should throw an exception.
  • If it is correct, do not throw an exception.
  • You may want to use Kotlin's assert or check methods