Repository navigation
Add exercise tree-building - #1642
Conversation
317b46e to
4c77f98
Compare
|
Add new exercise tree-building, ready for review. |
|
@FridaTveit Hi can you help me review this? Thank you |
|
Thanks for wanting to add a new exercise @junming403, we really appreciate it! 🙂 Anyone in the @exercism/java group can review it. However, we're all doing this as volunteers so please be patient. We'll review it as soon as we have time 🙂 Thanks again for wanting to contribute! 🙂 |
My apologies. |
|
Any feedback regarding if I am doing it in the right way will be appreciated. |
|
@FridaTveit Sorry to bother again, can I ask generally what is the expected time to get some feedback for an opened PR? I was actually planning to add more exercises if everything went well. |
|
@junming403 I'm afraid we don't have an expected time to get round to reviewing. We all have either full time jobs or are in full time education. We always try to review things as soon as possible, but it can be hard to find time especially if it's a whole new exercise (as that takes longer to review) and at busy times (I'm moving house at the moment). But one of us will get back to you as soon as we can 🙂 If you're eager to do other things in the meantime you can always start another exercise on this track, or update the test suite of any exercise on this track so that it's up to date with the canonical data, contribute to any other language track or contribute to the problem-specifications repo. We do appreciate all contributions, even if it takes as a while to review them 🙂 |
|
Thank you for the prompt reply. I am sorry if the ask sounds like an urge. I am not really mean to urge for the review, just eager to contribute more as I am really interested in doing this : ) |
|
That's great, I'm glad you want to contribute! 🙂 And I'm sorry it's taking us a while to review this, we will try to get to it as soon as possible! 🙂 |
FridaTveit
left a comment
There was a problem hiding this comment.
Thank you for adding this exercise @junming403, it's looking good! I've had a quick look and left a few comments. Let me know if you have any questions about anything and I'll try to get back to you as soon as possible 🙂
| "slug": "tree-building", | ||
| "uuid": "aeaed0e4-0973-4035-8bc5-07480849048f", | ||
| "core": false, | ||
| "unlocked_by": null, |
There was a problem hiding this comment.
This needs to be set. In general we try to set it to an exercise with similar topics 🙂
There was a problem hiding this comment.
Any suggestions for what it should be set to?
There was a problem hiding this comment.
Also, this should be moved to where the other difficulty 7 exercises are in this file 🙂
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
|
|
||
| public class BuildTree { |
There was a problem hiding this comment.
This class and its the buildTree method can probably be package private instead of public? 🙂
There was a problem hiding this comment.
I still think this can be package private (so you can just omit the access modifier) 🙂
| private String message; | ||
|
|
||
| public InvalidRecordsException(String msg) { | ||
| this.message = msg; |
There was a problem hiding this comment.
I think you can just do super(msg) here. Then you don't need the private parameter or to override the getMessage method 🙂
Also, minor thing, but message might be a better name for the method parameter. I prefer to avoid abbreviations where possible as it can make the code just a little bit harder to read 🙂
| @@ -0,0 +1,72 @@ | |||
| import java.util.ArrayList; | |||
There was a problem hiding this comment.
This should not contain the entire implementation. Please see some of the other exercises as an example and see the instructions in our contributing guide 🙂
There was a problem hiding this comment.
yes but i notice in the problem specification, this exercise is a bit special, it is about Refactor a tree building algorithm. Thus in general a naive solution would be given and the task is to refactor it into a more elegant and efficient solution.
There was a problem hiding this comment.
Ah, fair enough! I missed that, sorry 🙂
| assertNull(root); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
All tests except the first one should be ignored, as per our policies 🙂
| } | ||
|
|
||
| @Test | ||
| public void test_recordsWithMoreThanTwoChildren() throws InvalidRecordsException { |
There was a problem hiding this comment.
Please use camel case in naming 🙂
| assertNodeIsLeaf(root.children.get(1).children.get(0), 6); | ||
| } | ||
|
|
||
| @Test(expected = InvalidRecordsException.class) |
There was a problem hiding this comment.
Please use ExpectedException as per our policies 🙂
| "uuid": "aeaed0e4-0973-4035-8bc5-07480849048f", | ||
| "core": false, | ||
| "unlocked_by": null, | ||
| "difficulty": 4, |
There was a problem hiding this comment.
I think this exercise is harder than 4. Maybe 7 would be a better difficulty? 🙂
|
Thank you for the review @FridaTveit , I have updated and ready for the next round of review! Any suggestions for what should be a proper prerequisite for this exercise? |
FridaTveit
left a comment
There was a problem hiding this comment.
Nice markups, thank you! 😄
I've left a few more comments, let me know if you have any questions about anything 🙂
| "slug": "tree-building", | ||
| "uuid": "aeaed0e4-0973-4035-8bc5-07480849048f", | ||
| "core": false, | ||
| "unlocked_by": null, |
There was a problem hiding this comment.
Also, this should be moved to where the other difficulty 7 exercises are in this file 🙂
| import java.util.Comparator; | ||
| import java.util.HashMap; | ||
|
|
||
| public class BuildTree { |
There was a problem hiding this comment.
I still think this can be package private (so you can just omit the access modifier) 🙂
|
|
||
| public class BuildTree { | ||
|
|
||
| protected TreeNode buildTree(ArrayList<Record> records) throws InvalidRecordsException { |
There was a problem hiding this comment.
Why is this set to protected? 🙂
| @@ -0,0 +1,72 @@ | |||
| import java.util.ArrayList; | |||
There was a problem hiding this comment.
Ah, fair enough! I missed that, sorry 🙂
|
|
||
| public class TreeNode { | ||
| private int nodeId; | ||
| public ArrayList<TreeNode> children; |
There was a problem hiding this comment.
It's best practice to use getters and setters instead of making fields public 🙂
| import org.junit.Test; | ||
| import org.junit.rules.ExpectedException; | ||
|
|
||
|
|
There was a problem hiding this comment.
Minor nitpick: you don't need this extra empty line 🙂
| test.buildTree(records); | ||
| } | ||
|
|
||
| private void assertNodeIsLeaf(TreeNode node, int nodeId) { |
There was a problem hiding this comment.
It looks like this doesn't just check if the node is leaf, it also checks the node id. This is a bit unexpected and also doesn't follow the rule that a method should only do one thing. So I would keep this method as just checking if a node is a leaf, and just check the node id inline in each test 🙂 What do you think? 🙂
There was a problem hiding this comment.
Good point! I have inlined node id check
| assertNodeIsLeaf(root.children.get(0), 1); | ||
| assertNodeIsLeaf(root.children.get(1), 2); | ||
| assertNodeIsLeaf(root.children.get(2), 3); | ||
|
|
There was a problem hiding this comment.
You don't need this extra empty line 🙂
| assertEquals(node.children.size(), 0); | ||
| } | ||
|
|
||
| private void assertNodeIsBranch(TreeNode node, int nodeId, int childrenCount) { |
There was a problem hiding this comment.
Same for this, I would move the node id check out of this method. And I would rename it to something like assertNodeIsBranchWithNNumberOfChildren. Otherwise it's not obvious that it also checks the number of children 🙂
| @@ -0,0 +1,17 @@ | |||
| public class Record { | |||
There was a problem hiding this comment.
Everything here (and in general) that's public could probably also be package private 🙂
|
Hi, thank you for the review, I have updated accordingly and ready for next round! |
|
Hi sorry for the mistake, I have fixed the lint error now it passes the check. Can help me review again see if everything is okay? |
|
@FridaTveit Hi sorry for the nagging, would you mind help me review this again if you get time? Thank you. |
|
Can anyone help me review this? |
FridaTveit
left a comment
There was a problem hiding this comment.
This is looking really good @junming403, just a couple of small changes to make and then it's ready to merge 🙂
| "slug": "tree-building", | ||
| "uuid": "aeaed0e4-0973-4035-8bc5-07480849048f", | ||
| "core": false, | ||
| "unlocked_by": null, |
There was a problem hiding this comment.
This still needs to be filled in. I think I suggested linked-list before, what do you think about that? 🙂
|
|
||
| @Ignore("Remove to run test") | ||
| @Test | ||
| public void testCycleInDirectly() throws InvalidRecordsException { |
There was a problem hiding this comment.
I think this should be testCycleIndirectly 🙂
|
@FridaTveit Thank you so much for the review, I have done the necessary changes! |
FridaTveit
left a comment
There was a problem hiding this comment.
Looks great, thanks! 🙂
Thanks for adding this exercise @junming403!
Implement exercise tree building
Reviewer Resources:
Track Policies