-
Notifications
You must be signed in to change notification settings - Fork 0
Proper parenthetics #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
serashioda
wants to merge
12
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
12 commits
Select commit
Hold shift + click to select a range
dd852d9
fixed docstring errors
aac934e
fixed docstring errors
f971f9a
fixed docstring errors
9801a07
completed tests for parenthetics.py
bfdd5ca
wrote paranthetics using previous Stack functions. Tests written and …
0ac9159
Update README.md
serashioda afd2560
Update
serashioda e4b3bfe
Update
serashioda db28faa
updated tests for 100% coverage.
c194248
updated tests for 100% coverage.
3f4808f
minor merge conflict
84b5aa6
remove print statements. update .gitignore.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,5 +89,3 @@ ENV/ | |
|
|
||
| # Rope project settings | ||
| .ropeproject | ||
|
|
||
| bin/ | ||
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
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 |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| """Implementation of the Bit Counting Kata.""" | ||
|
|
||
| """Implemntation of the Bit Counting Kata.""" | ||
|
|
||
|
|
||
| def count_bits(n): | ||
| """Convert a number to binary and counts the number of 1 bits.""" | ||
| print(n) | ||
| val = bin(n) | ||
| print(val) | ||
| return val.count("1") |
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,85 @@ | ||
| """Implementation of the Kata Proper Parenthetics.""" | ||
|
|
||
|
|
||
| def parenthetics(uni_string): | ||
| """Take unicode string as input and return value.""" | ||
| stack = Stack() | ||
| charac_array = list(uni_string) | ||
| for charac in charac_array: | ||
| if charac == '(': | ||
| stack.push(charac) | ||
| elif charac == ')': | ||
| if stack.size() == 0: | ||
| return -1 | ||
| else: | ||
| stack.pop() | ||
| if stack.size() == 0: | ||
| return 0 | ||
| elif stack.size() > 0: | ||
|
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. no need for this |
||
| return 1 | ||
|
|
||
|
|
||
| class Stack(object): | ||
| """Create stack of parenthetics.""" | ||
|
|
||
| def __init__(self): | ||
| """Create a new stack, from LinkedList using composition.""" | ||
| self._linkedlist = LinkedList() | ||
|
|
||
| def push(self, value): | ||
| """Push a new value on top of the stack.""" | ||
| self._linkedlist.push(value) | ||
|
|
||
| def size(self): | ||
| """Return side of a.""" | ||
| return self._linkedlist.size() | ||
|
|
||
| def pop(self): | ||
| """Pop the first value of the stack.""" | ||
| return self._linkedlist.pop() | ||
|
|
||
|
|
||
| """Python implementation of a linked list.""" | ||
|
|
||
|
|
||
| class Node(): | ||
| """Instantiate a Node.""" | ||
|
|
||
| def __init__(self, value=None, next=None): | ||
| """Instantiate a node with value and next params.""" | ||
| self.value = value | ||
| self.next = next | ||
|
|
||
|
|
||
| class LinkedList(): | ||
| """Instantiate a Linked List.""" | ||
|
|
||
| def __init__(self): | ||
| """Instantiate an empty Linked list.""" | ||
| self.head = None | ||
|
|
||
| def push(self, val): | ||
| """Push a new node as the head of the linked list.""" | ||
| new_node = Node(val, self.head) | ||
| self.head = new_node | ||
|
|
||
| def pop(self): | ||
| """Pop first value off linked list and return value.""" | ||
| # if self.head is None: | ||
| if self.head is not None: | ||
| pop_head = self.head.value | ||
| self.head = self.head.next | ||
| return pop_head | ||
| else: | ||
| raise IndexError('cannot pop from empty list') | ||
|
|
||
| def size(self): | ||
| """Return the length of the linked list.""" | ||
| if self.head is not None: | ||
| size = 1 | ||
| curr = self.head | ||
| while curr.next is not None: | ||
| size += 1 | ||
| curr = curr.next | ||
| return size | ||
| return 0 | ||
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,28 @@ | ||
| """Tests for parenthetics module.""" | ||
|
|
||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| PAREN_TABLE = [ | ||
| ['((()))', 0], | ||
| ['((())', 1], | ||
| [')))(((', -1] | ||
|
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. You need more test cases. |
||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("uni_string, result", PAREN_TABLE) | ||
| def test_parenthetics(uni_string, result): | ||
| """Test the parenthetics function.""" | ||
| from parenthetics import parenthetics | ||
| assert parenthetics(uni_string) == result | ||
|
|
||
|
|
||
| def test_pop_empty(): | ||
| """Test the parenthetics function.""" | ||
| from parenthetics import LinkedList | ||
| list = LinkedList() | ||
| try: | ||
| list.pop() | ||
| except Exception as e: | ||
| assert str(e) == 'cannot pop from empty list' | ||
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.
Why turn this into a list if strings are iterable in both Python 2 and 3?