Kotlinlearncs.online LogoJava
Return to List

Test Writing: BinaryTree Count Greater Than

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a method countGreaterThan that accepts a BinaryTree<Int>? and an Int and returns a count of the number of nodes in the tree that contain a value greater than the passed value. If the passed tree is null you should return 0.

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

As a result, tree.value is an Int which you can compare to the threshold value in the usual way.

Test Design Challenge

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

  • Provide a public class named TestBinaryTreeCountGreaterThan 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