Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_symmetric property #20

Merged
merged 1 commit into from
Jul 19, 2019
Merged

Add is_symmetric property #20

merged 1 commit into from
Jul 19, 2019

Conversation

gillespiecd
Copy link
Contributor

@gillespiecd gillespiecd commented Jul 18, 2019

Background

I enjoy using binarytree, especially find printing useful in ipython.

I thought it would be fun to add a new property is_symmetric to properties. This comes up sometimes as an exercise with trees -- is it symmetric (a mirror of itself).

Also wanted to learn more about the doctest and coverage modules 👍

Updates

  1. Add new property and function to calculate if binary tree is symmetric

Steps to Reproduce

>>> from binarytree import Node
>>> a = Node(5)
>>> a.is_symmetric
True
>>> a.left = Node(6)
>>> a.is_symmetric
False
>>> a.right = Node(6)
>>> a.is_symmetric
True
>>> a.right.left = Node(7)
>>> a.is_symmetric
False
>>> a.right.right = Node(8)
>>> a.left.left = Node(8)
>>> a.left.right = Node(7)
>>> print(a)

    __5__
   /     \
  6       6
 / \     / \
8   7   7   8

>>> a.is_symmetric
True

@coveralls
Copy link

coveralls commented Jul 18, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 3523749 on gillespiecd:symmetric into 23cb6f1 on joowani:dev.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c0a796d on gillespiecd:symmetric into 23cb6f1 on joowani:dev.

@joowani joowani merged commit 035fec9 into joowani:dev Jul 19, 2019
@joowani
Copy link
Owner

joowani commented Jul 19, 2019

Hi @gillespiecd,

Looks good! Thank you for your interest and contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants