Kotlinlearncs.online LogoJava
Return to List

Test Writing: Binary Tree Count Children Sum to Negative

Created By: Geoffrey Challen
/ Version: 2021.4.0

Create a public class BinaryTreeCounter that provides a single class method named countChildSumToNegative that accepts a single BinaryTree<Integer> and counts the number of nodes in the tree where the values of the node's children sum to a negative number. You should not count nodes that don't have at least one child, but some nodes may only have one child. Keep in mind that not every node has a right or left child, so you'll need to check for null carefully. However, you can assume that all of the values in the tree are non-null Integers.

For reference, cs125.trees.BinaryTree has the following public properties:

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 Java's assert method