-
Notifications
You must be signed in to change notification settings - Fork 1
Parenthetics #5
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
jwarren116
wants to merge
9
commits into
master
Choose a base branch
from
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
Parenthetics #5
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bbf0fb2
Fix input to list to be value, not node; Adjust tests to reflect inpu…
jwarren116 65fd38f
Merge branch 'linked-list' of https://github.com/jwarren116/data-stru…
jwarren116 b3c1a78
Remove stack.py and test from branch
jwarren116 6a3035f
Initial creation of tests for parenthetics.py
jwarren116 1a0e6a2
Outline of parenthetics.py
jwarren116 b5b16ab
Fixed cases with closed parens before open parens
jwarren116 c193e65
Add additional tests with text
jwarren116 4b093e1
Clean up code; include docstring explaining return values
jwarren116 776e02d
Update README.md for parenthetics.py
jwarren116 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
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
|
|
||
| def parenthetics(inp): | ||
| """Checks for balanced parenthetic usage in a given input | ||
|
|
||
| Returns 1 if the string has open parenthetics that are not properly closed. | ||
| Returns 0 if the string is balanced. | ||
| Returns -1 if the string has closing parentheses before opening. | ||
|
|
||
| """ | ||
| count = 0 | ||
| for char in inp: | ||
| if char == "(": | ||
| count += 1 | ||
| if char == ")": | ||
| count -= 1 | ||
| if count < 0: | ||
| return -1 | ||
| if count >= 1: | ||
| return 1 | ||
| else: | ||
| return 0 |
This file was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import pytest | ||
| from parenthetics import parenthetics | ||
|
|
||
|
|
||
| def test_single_open(): | ||
| assert parenthetics("(") == 1 | ||
|
|
||
|
|
||
| def test_single_close(): | ||
| assert parenthetics(")") == -1 | ||
|
|
||
|
|
||
| def test_single_balanced(): | ||
| assert parenthetics("()") == 0 | ||
|
|
||
|
|
||
| def test_multi_open_close_1(): | ||
| assert parenthetics("(()") == 1 | ||
|
|
||
|
|
||
| def test_multi_open_close_2(): | ||
| assert parenthetics("())") == -1 | ||
|
|
||
|
|
||
| def test_broken(): | ||
| assert parenthetics("))((") == -1 | ||
|
|
||
|
|
||
| def test_text(): | ||
| assert parenthetics("This is a silly test!") == 0 | ||
|
|
||
|
|
||
| def test_text_parens(): | ||
| assert parenthetics("This is a silly test (but not really that silly)!") == 0 | ||
This file was deleted.
Oops, something went wrong.
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.
I'd like to see a couple more test cases that could possibly break your code. You don't test an empty string, and you don't test anything more complex like (()()))(). It might seem silly to test these because you know that your code will breeze through them, but your tests shouldn't assume anything about your code. When you're working with code, it could change completely over time and if you don't have exhaustive test cases, it could break without you realizing.