-
-
Notifications
You must be signed in to change notification settings - Fork 550
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
binary-search-tree: implement canonical-data.json #940
Changes from 1 commit
0c589fa
86dd64e
7c13fb8
5d23849
0ea99f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"exercise": "binary-search-tree", | ||
"version": "1.0.0", | ||
"comments": [ | ||
"For simplicity only positive integer is considered as valid data,", | ||
"null should be replaced by the respective language equivalent or -1", | ||
"if the language does not have any.", | ||
|
||
"The purpose of ths exercise is to create a data structure which", | ||
"makes sure the data is always sorted, hence the exercise should", | ||
"not make use of any sort() functions or sorting algorithms." | ||
], | ||
"cases": [{ | ||
"description": "insert invalid/null data into the tree", | ||
"property": "insert", | ||
"value": null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar reasoning as #925: I don't think it is good to have this case.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I stated in the comments : if the specific track does not have any equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't understand why -1 is invalid for any reason other than "the comments of this file say so". I think it is a strange restriction to only allow positive numbers. It seems like the restriction is there for the sole purpose of classifying some numbers to be invalid, allowing there to be a test for inserting invalid values. If that is the sole purpose of the restriction, I would think it just makes more sense to not have the restriction and not have this test. Further, if negative values are to be deemed invalid values for the tree being tested, that seems like information that is very important to be added in description.md, where students will see it, not canonical-data.json (where students will not see it!). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the exercise is supposed to teach how to implement a data structure. And a data structure should know the difference between valid and invalid data before inserting it. Now some languages do not have static type checking whereas some don't have equivalent of null. But we still need to draw a line between the two. And I agree the description.md might need an update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this case should exist, because if we draw a line between valid and invalid data and specify in the description we should also have a test case to check against it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I expect that for a BST, by contract, the criterion for validity is a standard "are two elements comparable against each other?". I therefore also expect that this is the criterion that the tests will use, rather than a different standard ("is the number positive?", etc.) So then, in a language with static type checking, this would get enforced by the type system. In a language without one, now it gets interesting. We could consider a test of adding in "hello" to a tree that already contains a 6, for example. This would fail. However, is it the student's responsibility to write the code that checks for that? The failure might happen without the student having to write any additional code. If it would, then there is no value in having this test.
This makes it useful to keep the standard criterion for validity. If the exercise adds in an additional criterion, students may wonder why it exists and/or whether they have to add such an additional restriction in any future BSTs they write. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess the case for invalid data should exist but anything other than an integer should be considered as invalid. Right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right.
Only if it is useful. I haven't been convinced it is useful because in most cases the student doesn't need to write any code to pass the test. Okay, I can name at least one language where I can't tell whether #902 is telling us "yes, put such cases in the canonical-data.json and let languages that don't need the test ignore it" or "no, don't put such cases in and let languages that need the tests add them". I am thinking the number of languages that benefit from the case is lower than the number of languages that don't, if that helps decide. I still say no. Remember that it's not necessary to convince me, it's only necessary to convince those who approve the pull request. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A BST is about comperability, and I do not see why string and integer should not be comparable to each other... In the erlang VM (and therefore in at least 3 languages on exercism) there is a total order defined over all values possible. Also after having read the introductionary comment, where you state that we only use positiv numbers as valid input, I'd use an unsigned int in statically typed languages. But you have specified So independently how I look at it, I do not feel that this test is necessary in any way. |
||
"expected": false | ||
}, | ||
{ | ||
"description": "insert a number into the tree", | ||
"property": "insert", | ||
"value": 6, | ||
"expected": true | ||
}, | ||
{ | ||
"description": "insert a number that already exist", | ||
"property": "insert", | ||
"value": 6, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see how we can understand that the number already exists, using the information provided in this case. If we suppose that we are inserting into a tree that already had |
||
"expected": false | ||
}, | ||
{ | ||
"description": "search invalid/null data", | ||
"property": "search", | ||
"value": null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar reasoning as #925: I don't think it is good to have this case.
|
||
"expected": false | ||
}, | ||
{ | ||
"description": "search a number that exists", | ||
"property": "search", | ||
"value": 6, | ||
"expected": true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we know that 6 exists in the tree? What tree is this search being performed on? |
||
}, | ||
{ | ||
"description": "search a number that does not exist", | ||
"property": "search", | ||
"value": 11, | ||
"expected": false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we know that 11 does not exist in the tree? What tree is this search being performed on? |
||
}, | ||
{ | ||
"description": "traverse the data in ascending order", | ||
"property": "ascendingOrder", | ||
"comments": [ | ||
"Assuming the data is entered in this order :", | ||
"6 -> 1 -> 3 -> 2 -> 5" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like these values should be an array of numbers, rather than forcing people to parse this string, splitting by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it but i wasn't sure if i should add a new key called "state" which represents the data entered in the tree at that case in that specific order. This new key "state" will also prove useful in previous cases where its not clear what data the tree currently has. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there has to be such a key. You could call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um. maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not even sure how to read this...
or is it
or
Some implementations ask for implementing a function that creates a BST from a list, growing the tree from the first item to the last. Roughly like this: foldl Leaf (\ x t -> insert t x) list In the introductionary comment we could explain that a property |
||
], | ||
"expected": [1, 2, 3, 5, 6] | ||
}, | ||
{ | ||
"description": "traverse the data in descending order", | ||
"property": "descendingOrder", | ||
"comments": [ | ||
"Assuming the data is entered in this order :", | ||
"6 -> 1 -> 3 -> 2 -> 5" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like these values should be an array of numbers, rather than forcing people to parse this string, splitting by |
||
], | ||
"expected": [6, 5, 3, 2, 1] | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unclear on how this sentence affects someone implementing this exercise for a given track, and I don't think there was any danger of anyone using a sorting function for this exercise anyway? Will you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well as i understand this exercise from description.md the purpose is to create a data structure which represent sorted data and specifically binary search tree. Usage of any sort() function or algorithm will defeat its purpose don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
I don't think it is likely that anyone will think to use a sorting function, because they should already be at the point where they're inserting nodes into a tree.
Therefore, I don't think it is useful to have this text here, and I will find it confusing becuase I will read it and think "why are you telling me this?"
It could be that I am biased and this text does help those who see it from a different point of view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Therefore current implementations of the testsuite do test for usually internal/private functions of such a datastructure.
They ask for the left or right subtree of the root node and assert if its value is correct given the insertion order.
The do roughly the following:
So not only testing if the tree contains the values, but also if it is built correctly is not possible by just using a
sort
function, since original order of insertion dictates the structure of the tree.So I do not think that bullet 1 is a concern if you are testing for internals in this canonical data. If you do not, please add those tests.
A person that is new to the BST, will see the README.md which explains the exercise to solve. The comments in the canonical data are meant as a guidance/help for the implementor of a testsuite/a generator, not to describe the actual exercise.
Because of this two reasons, I am with @petertseng and think this part of the comment should be removed,