Kotlinlearncs.online LogoJava
Return to List

Test Writing: Binary Tree Combine Even Strings

Created By: Pranav Narayanan
/ Version: 2025.2.0

Write a method named combineEvenStrings that accepts a single BinaryTree<String> and returns the concatenation of all even length Strings in this tree, in the order current + left + right (post-order traversal).

For example, given the tree:

      "12"
     /    \
  "cs"    "4"

You would return "12cs", by concatenating the current node "12", the left subtree "cs", and the right subtree "" (the right subtree has no even length Strings). If the tree was:

      "24"
     /
  "1"
     \
      "cs"

You would return "24cs", by concatenating the current node "24", and the left subtree "cs" (you ignore "1" because it is not even length). You may need to write a private helper method to solve this problem.

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 TestTreeCombineStrings 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
Report a Problem

Attribution must link to this page: https://www.learncs.online/testtesting/kotlin/binary-tree-combine-even-strings/[email protected]