interactive-coding-challenges icon indicating copy to clipboard operation
interactive-coding-challenges copied to clipboard

Added __eq__ method to ensure invert_tree_challenge tests pass.

Open gmazzola opened this issue 7 years ago • 1 comments

The invert_tree_challenge Jupyter notebook has a nose unit-test that looks like this:

assert_equal(result, root)

Where result and root are Node objects. I wrote a solution to this challenge that involved creating a new Node object versus re-using the existing one, but this failed because there was no __eq__ method defined in the Node class to enable comparison with other Nodes.

This minor pull request addresses three things:

  1. Changes the __repr__ method to aid debugging.
  2. Adds an __eq__ method to compare nodes in a tree.
  3. Adds a newline at the end of the file.

Thanks!

gmazzola avatar Apr 11 '17 04:04 gmazzola

Hi @gmazzola thanks for the PR! I hope to have this reviewed within the next few days.

donnemartin avatar Apr 12 '17 12:04 donnemartin