-
-
Notifications
You must be signed in to change notification settings - Fork 352
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 encapsulated #2131
base: main
Are you sure you want to change the base?
Binary search tree encapsulated #2131
Conversation
Hello. Thanks for opening a PR on Exercism. We are currently in a phase of our journey where we have paused community contributions to allow us to take a breather and redesign our community model. You can learn more in this blog post. As such, all issues and PRs in this repository are being automatically closed. That doesn't mean we're not interested in your ideas, or that if you're stuck on something we don't want to help. The best place to discuss things is with our community on the Exercism Community Forum. You can use this link to copy this into a new topic there. Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it. |
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.
The tests file has understandably changed lots. We have to decide whether we want to diverge from the original prob-specs data: https://github.com/exercism/problem-specifications/blob/main/exercises/binary-search-tree/canonical-data.json
@michalporeba I sort of seem to have lost the status of this PR. Do you have any idea? I have some comments that still seem to be unresolved. |
Let's see if this will work (replying by email). I'm on holidays right now
with no computer and a promise to myself not to look at code. I'll have a
look and respond properly when I get back in a week or so.
…On Wed, Aug 9, 2023, 12:09 Erik Schierboom ***@***.***> wrote:
@michalporeba <https://github.com/michalporeba> I sort of seem to have
lost the status of this PR. Do you have any idea? I have some comments that
still seem to be unresolved.
—
Reply to this email directly, view it on GitHub
<#2131 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA5QMFIFWZXP3YIGUAXGJDXUNVX7ANCNFSM6AAAAAAX3HKQ6U>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Enjoy your vacation |
@ErikSchierboom, I was going over the code of the exercises again today and I have noticed something else. The comments above I made after reviewing ten practice exercises. Today I looked at the concept exercises and there is a difference. Concept exercises use messages like this: This is a practice exercise so, for consistency, we should use |
The concept exercises version is superior here, mostly for online editor users as they get a more specific error messages. So we should update the practice exercise's version. |
Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
@ErikSchierboom,I had another look at what I initially proposed, our discussion here, but also the problem specification and similar solutions in a few other object-oriented language tracks. I'll summarise what I found and my current thinking here so we can decide on the direction and complete this work. C++ test_sort(make_tree<uint32_t>({2, 1, 3, 6, 7, 5}), {1, 2, 3, 5, 6, 7}); auto tested = make_tree<uint32_t>({4, 2, 6, 1, 3, 5, 7});
test_leaf<uint32_t>(tested, 4, true, true);
test_leaf<uint32_t>(tested->right(), 6, true, true);
test_leaf<uint32_t>(tested->left()->left(), 1, false, false); The tree is tested with numbers (canonical) and with strings. Ruby implements constructor for initialisation from an array, and the standard tree = Node.new(4)
tree.insert(5)
tree.value.should eq(4)
right = tree.right.not_nil!
right.value.should eq(5) Ruby is also implemented with limited encapsulation and access to the full tree. The implementation is non-generic, but Ruby is a dynamic language. It has four = Bst.new 4
four.insert 2
assert_equal 4, four.data
assert_equal 2, four.left.data A summary of where I am at right now:
Testing is the challenge.
Ideas for the
|
Those all sounds reasonable
Not sure how this is more object-oriented than the previous suggestion, as the goal of the binary search tree is to contain and expose values, not to hide them. My personal preference would be the |
OOP is all bout encapsulation and message passing, not exposing internals making it possible to change implementation of a data structure. That's why we don't have access to the internals of But I think the serialisation idea is perfect. While the implementation is internal, the data can be serialised. |
True, although a binary search tree should be accessible via left/right like methods. 🤷 I mean, the fact that it is a binary tree implies a certain structure, so IMHO it's fine to expose that, as long as the actual internal implementation is not exposed.
Yeah let's do this, I like this best! Thanks for wanting to implement this. |
@ErikSchierboom have a look at the current version when you have a moment. For ordering checks I have used a custom method Should we do it? |
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.
For ordering checks I have used a custom method GetOrderedValues() for now. I'm in two minds about implementing the IEnumerable. I think this would make the exercise even more idiomatic in .net, but it would make it even more complex.
We are doing that in two other places too (dot-dsl and simple-linked-list), so I think it's fine to have people implement IEnumerable<T>
(maybe an .docs/instructions.append.md
file could help).
public int Count | ||
=> throw new NotImplementedException("Please implement the Count property of the BinarySearchTree<T> class."); |
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.
This style is more commonly used in the code base:
public int Count | |
=> throw new NotImplementedException("Please implement the Count property of the BinarySearchTree<T> class."); | |
public int Count => | |
throw new NotImplementedException("Please implement the Count property of the BinarySearchTree<T> class."); |
var tree = new BinarySearchTree(new[] { 4, 2 }); | ||
Assert.Equal(4, tree.Value); | ||
Assert.Equal(2, tree.Left.Value); | ||
var sut = new BinarySearchTree<int>(); |
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.
The binary search tree is generic, but we're only using int
as the type. I think we should also add some non-int type (probably strings).
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.
Yes, I proposed it myself higher up in the comments, so definitely agree. But I wanted first to get the shape of the exercise in the right format before I will add more tests and details like that. It's definitely coming.
As explained and approved on the forum
This is to match with both similar exercise in this and other tracks, as well as with the .net approach to doing things. Binary Search Tree is now an encapsulated structure. To solve the problem a node has to be implemented internally.
The idea is similar to what we have previously implemented in Simple Linked List exercise as discussed on the forum and described in previous PR.
Since the BST structure is a search one, I removed the
IEnumerable
elements and instead added a constraint on theT
to beIComparable
. TheBinarySearchTree<T>
type to implement two properties Count and Depth and two methods Add and Contains.Two remaining questions is
Whether to leave the
where T: IComparable
in the stub or not. As this is a medium difficulty exercise I would be tempted to remove it. Users implementing the solution soon will realise that they cannot compareT
and either they will know aboutIComparable
, or will search for solutions online and find out about it.Whether to add a test that explicitly follows the example from the description.