Skip to content

tree-building : implement exercise#796

Merged
ilya-khadykin merged 4 commits intoexercism:masterfrom
clapmyhands:implement/tree-building
Oct 26, 2017
Merged

tree-building : implement exercise#796
ilya-khadykin merged 4 commits intoexercism:masterfrom
clapmyhands:implement/tree-building

Conversation

@clapmyhands
Copy link
Copy Markdown
Contributor

@clapmyhands clapmyhands commented Oct 12, 2017

resolves #741

@clapmyhands clapmyhands changed the title [WIP] tree-building : implement exercise tree-building : implement exercise Oct 18, 2017
Copy link
Copy Markdown
Contributor

@ilya-khadykin ilya-khadykin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

Looks good to me


def validateRecord(record):
if record.equal_id() and record.record_id != 0:
raise ValueError
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably provide the cause of the exception

if record.equal_id() and record.record_id != 0:
raise ValueError
elif (not record.equal_id()) and record.parent_id >= record.record_id:
raise ValueError
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same

def validateRecord(record):
if record.equal_id() and record.record_id != 0:
raise ValueError
elif (not record.equal_id()) and record.parent_id >= record.record_id:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant parentheses

@clapmyhands
Copy link
Copy Markdown
Contributor Author

@m-a-ge I've change it according to the review. Please check again and let me know if there's anything else to change 😄 .


def assert_node_is_branch(self, node, node_id, children_count):
self.assertEqual(node.node_id, node_id)
self.assertFalse(len(node.children) == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertNotEqual(len(node.children), 0) would be clearer.


def assert_node_is_leaf(self, node, node_id):
self.assertEqual(node.node_id, node_id)
self.assertTrue(len(node.children) == 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEqual(len(node.children), 0) would be clearer.

@clapmyhands
Copy link
Copy Markdown
Contributor Author

clapmyhands commented Oct 25, 2017

@cmccandless I've changed it according to your review. Also I've been thinking, do I need to put some reason on the test where a ValueError need to be raised?

@cmccandless
Copy link
Copy Markdown
Contributor

@clapmyhands If I understand you correctly, do you mean something like this?

with self.assertRaisesRegexp(ValueError, 'No root node'):
    BuildTree(records)

If that's what you mean, that would be a good idea 👍

@clapmyhands
Copy link
Copy Markdown
Contributor Author

@cmccandless I don't think it's possible. At least in my current code it can't since the checking of 'no root node' is the same as checking of 'non continuous'

reason being:

raise ValueError

can cover multiple failing cases.

I was thinking more in line of comments like so:

# no root node
with self.assertRaises(ValueError):
            BuildTree(records)

the name of the test might already be self-explanatory but for some tests such as

def test_cycle_directly(self):

it might be good to have further explanation on why that gives an error.

p.s: what do you think about changing

self.assertIs(root, None)

to

self.assertIsNone(root)

@cmccandless
Copy link
Copy Markdown
Contributor

@clapmyhands self.assertIsNone is perfect.

I agree that a few changes would be required to provide accurate exception details, but as a fellow programmer I would caution you against using the word "impossible" lightly 😉. At this time, this track does not have a requirement for exceptions to contain details, so I will leave it up to you whether to:

  • Refactor example.py (and because tree-building is a refactoring exercise, tree_building.py would need refactoring as well) to include exception details, and check for correct details in tree_building_test.py using assertRaisesRegexp

OR

  • Add comments in tree_building_test.py as you have suggested.

Whichever you decide, I believe that should be enough to merge.

@clapmyhands
Copy link
Copy Markdown
Contributor Author

@cmccandless I've changed it to use self.assertIsNone and added comment where I think is needed. Please review once more and let me know if there's anything else I need to change 😄

@cmccandless
Copy link
Copy Markdown
Contributor

@clapmyhands I've left a couple comments. Just some consistency stuff.

@clapmyhands
Copy link
Copy Markdown
Contributor Author

@cmccandless I've added comment for consistency.

@ilya-khadykin ilya-khadykin merged commit 1095e28 into exercism:master Oct 26, 2017
@ilya-khadykin
Copy link
Copy Markdown
Contributor

Thanks for working on this, @clapmyhands!

@clapmyhands
Copy link
Copy Markdown
Contributor Author

@m-a-ge @cmccandless Thanks for being patient with me through it all. New contributor and hopefully a lasting one 😄

@clapmyhands clapmyhands deleted the implement/tree-building branch October 27, 2017 09:32
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.

tree-building: implement exercise

3 participants