-
Notifications
You must be signed in to change notification settings - Fork 0
proper parenthetics with tests, stack, linked list #3
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
Open
julienawilson
wants to merge
2
commits into
master
Choose a base branch
from
proper-parenthetics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-18 Bytes
(99%)
src/__pycache__/test_binary_list_to_number.cpython-27-PYTEST.pyc
Binary file not shown.
Binary file modified
BIN
-18 Bytes
(99%)
src/__pycache__/test_count_positives_sum_negatives.cpython-27-PYTEST.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-18 Bytes
(99%)
src/__pycache__/test_reverse_and_mirror.cpython-27-PYTEST.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """Implementation of Linked_List data type.""" | ||
|
|
||
|
|
||
| class LinkedList(object): | ||
| """Class representation of linked list.""" | ||
|
|
||
| def __init__(self, iterable=None): | ||
| """Instantiate linked list.""" | ||
| self.head_node = None | ||
| self.length = 0 | ||
| try: | ||
| for item in iterable: | ||
| self.push(item) | ||
| except TypeError: | ||
| if iterable: | ||
| return "Please only enter iterable values" | ||
|
|
||
| def push(self, contents): | ||
| """Add node to this linked list.""" | ||
| self.head_node = Node(contents, self.head_node) | ||
| self.length += 1 | ||
|
|
||
| def pop(self): | ||
| """Remove and return the current head node.""" | ||
| if not self.head_node: | ||
| return "Linked list is already empty" | ||
| old_head_node = self.head_node | ||
| self.head_node = self.head_node.next_node | ||
| self.length -= 1 | ||
| return old_head_node.contents | ||
|
|
||
| def size(self): | ||
| """Return the current size of this linked list.""" | ||
| return self.length | ||
|
|
||
| def search(self, search_value): | ||
| """Return the node with the searched contents if found.""" | ||
| if self.length: | ||
| if search_value == self.head_node.contents: | ||
| return self.head_node | ||
| current_node = self.head_node | ||
| while current_node.contents != search_value: | ||
| if current_node.next_node is None: | ||
| return None | ||
| current_node = current_node.next_node | ||
| return current_node | ||
| else: | ||
| return None | ||
|
|
||
| def remove(self, remove_node): | ||
| """Remove a node from linked list.""" | ||
| if remove_node == self.head_node: | ||
| self.head_node = self.head_node.next_node | ||
| self.length -= 1 | ||
| return None | ||
| elif remove_node is None: | ||
| raise ValueError("Provided value not in list.") | ||
| current_node = self.head_node | ||
| while current_node.next_node != remove_node: | ||
| current_node = current_node.next_node | ||
| current_node.next_node = current_node.next_node.next_node | ||
| self.length -= 1 | ||
|
|
||
| def display(self): | ||
| """Return the tuple of all values in linked list.""" | ||
| if self.length == 0: | ||
| return None | ||
| else: | ||
| new_list = [self.head_node.contents] | ||
| current_node = self.head_node | ||
| while current_node.next_node is not None: | ||
| current_node = current_node.next_node | ||
| new_list.append(current_node.contents) | ||
| return tuple(new_list) | ||
|
|
||
|
|
||
| class Node(object): | ||
| """Class representation of linked list node.""" | ||
|
|
||
| def __init__(self, contents, next_node): | ||
| """Instantiate linked list node.""" | ||
| self.contents = contents | ||
| self.next_node = next_node |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """Ensure the same number of opening and closing parenthetics in a string.""" | ||
|
|
||
| from stack import Stack | ||
|
|
||
|
|
||
| def proper_parenthetics(input_string): | ||
| """Ensure the balance of opening and closing parenthtics.""" | ||
| parenthetics_stack = Stack() | ||
| for i in input_string: | ||
| if i == '(': | ||
| parenthetics_stack.push(i) | ||
| if i == ')': | ||
| if parenthetics_stack.head_node is None: | ||
| return -1 | ||
| else: | ||
| parenthetics_stack.pop() | ||
| if parenthetics_stack.head_node is None: | ||
| return 0 | ||
| return 1 | ||
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """Implementation of Stack data type.""" | ||
|
|
||
| from linked_list import LinkedList | ||
|
|
||
|
|
||
| class Stack(object): | ||
| """Class representation of a stack.""" | ||
|
|
||
| def __init__(self, iterable=None): | ||
| """Instantiate stack.""" | ||
| self.linked_list = LinkedList(iterable) | ||
| self.length = self.linked_list.length | ||
| self.head_node = self.linked_list.head_node | ||
|
|
||
| def push(self, contents): | ||
| """Add node to this stack.""" | ||
| self.linked_list.push(contents) | ||
| self.head_node = self.linked_list.head_node | ||
|
|
||
| def pop(self): | ||
| """Remove and return the current head node.""" | ||
| old_head_node_value = self.linked_list.pop() | ||
| self.head_node = self.linked_list.head_node | ||
| return old_head_node_value |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Tests for proper_parenthetics.""" | ||
| import pytest | ||
|
|
||
|
|
||
| ASSERTIONS = [ | ||
| ['(', 1], | ||
| ['(This is (a string)', 1], | ||
| ['()', 0], | ||
| ['some (strings) and (others)', 0], | ||
| ['((Nestes)ones)', 0], | ||
| [')', -1], | ||
| ['(bloop))', -1], | ||
| [')its backwards(', -1] | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("input, result", ASSERTIONS) | ||
| def test_proper_parenthetics(input, result): | ||
| """Test proper_parenthetics for proper output in test cases.""" | ||
| from proper_parenthetics import proper_parenthetics | ||
| assert proper_parenthetics(input) == result |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Better variable names plz