-
Notifications
You must be signed in to change notification settings - Fork 0
Stack #2
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
base: master
Are you sure you want to change the base?
Stack #2
Conversation
|
|
||
| def __init__(self, iterable=None): | ||
| """Instantiate stack.""" | ||
| self.linked_list = LinkedList(iterable) |
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.
Good use of composition!
| """Instantiate stack.""" | ||
| self.linked_list = LinkedList(iterable) | ||
| self.length = self.linked_list.length | ||
| self.head_node = self.linked_list.head_node |
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.
However, since you have all of the linked lists's functionality here, do you really need to assign a head_node variable? What purpose is it serving?
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.
If we want to check the value of the head node, we need to assign it in the Stack, correct?
I suppose we could get it using my_stack.linked_list.headnode, but isnt that kind of ugly?
src/stack.py
Outdated
| """Remove and return the current head node.""" | ||
| old_head_node = self.linked_list.pop() | ||
| self.head_node = self.linked_list.head_node | ||
| return old_head_node |
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.
Similar to my comments on your linked list, your Stack should just return the value on top of the stack, not the whole Node.
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.
Our linked_list pop now returns a value, which means the stack does too. Are you objecting to the name?
src/test_stack.py
Outdated
| """Test for Stack init.""" | ||
| from stack import Stack | ||
| new_stack = Stack() | ||
| assert new_stack.length == 0 |
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.
You guys need to fix your tests so there's only one assert statement per test function. The reason for this is so you can get a more granular understanding of what cases/scenarios fail and which don't.
A big problem is that if one assertion is false, the function exits and the rest of the tests are not evaluated, so you are denied more information about the success/failure of your tests. Separate those concerns. Be explicit.
And once again, use fixtures and parametrization. It can save you from so much of this messy multi-line test function malarkey.
| @@ -0,0 +1,15 @@ | |||
| """The setup for Mailroom distribution.""" | |||
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 mailroom? I just wanted my fancy data structures!
pull request for the Stack Data Structure.
Contains the Stack module and testing module.