-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Pcc45 #844
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
Merged
Merged
Pcc45 #844
Changes from all commits
Commits
Show all changes
3 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
Empty file.
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,17 @@ | ||
| #!/usr/bin/python3 | ||
|
|
||
|
|
||
| def fizzbuzz(num: int): | ||
| """ | ||
| FizzBuzz(int) plays FizzBuzz | ||
| """ | ||
| if not isinstance(num, int): | ||
| raise ValueError("argument should be of type int") | ||
| else: | ||
| if num % 5 == 0 and num % 3 == 0: | ||
| return "FizzBuzz" | ||
| if num % 5 == 0: | ||
| return "Buzz" | ||
| if num % 3 == 0: | ||
| return "Fizz" | ||
| return num | ||
Empty file.
Empty file.
Empty file.
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,39 @@ | ||
| #!/usr/bin/python3 | ||
|
|
||
| import unittest | ||
|
|
||
| from app.fizzbuzz import fizzbuzz | ||
|
|
||
|
|
||
| class TddFizzBuzz(unittest.TestCase): | ||
|
|
||
| def test_fizzbuzz_returns_ints(self): | ||
| samples = [1, 2, 4, 6, 7, 8, 11, 13] | ||
| for sample in samples: | ||
| result = fizzbuzz(sample) | ||
| self.assertEqual(result, sample) | ||
|
|
||
| def test_fizzbuzz_returns_fizz_with_multiples_of_3(self): | ||
| samples = [3, 6, 9, 12] | ||
| for sample in samples: | ||
|
Collaborator
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 can use paremetrize: https://docs.pytest.org/en/6.2.x/parametrize.html |
||
| result = fizzbuzz(sample) | ||
| self.assertEqual(result, "Fizz") | ||
|
|
||
| def test_fizzbuzz_returns_buzz_with_multiples_of_5(self): | ||
| samples = [5, 10, 20, 25] | ||
| for sample in samples: | ||
| result = fizzbuzz(sample) | ||
| self.assertEqual(result, "Buzz") | ||
|
|
||
| def test_fizzbuzz_returns_fizzbuzz_with_multiples_of_3_and_5(self): | ||
| samples = [15, 30, 45, 60] | ||
| for sample in samples: | ||
| result = fizzbuzz(sample) | ||
| self.assertEqual(result, "FizzBuzz") | ||
|
|
||
| def test_fizzbuzz_raises_error_message_if_arg_not_int(self): | ||
|
Collaborator
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. nice descriptive name, I don't mind test function names to be longer |
||
| self.assertRaises(ValueError, fizzbuzz, 'two') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
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,17 @@ | ||
| First time only setup: | ||
| ```bash | ||
| $ git clone https://github.com/mhered/challenges -b community && cd challenges | ||
| $ git remote add upstream https://github.com/pybites/challenges | ||
| ``` | ||
| Init for every new challenge: | ||
| ```bash | ||
| $ git checkout community # return to community branch | ||
| $ git pull upstream community # pull the latest upstream repo | ||
| $ git checkout -b PCC45 # create a branch to work on the challenge | ||
| $ mkdir 45/mhered && cd $_ # work on your own subdirectory | ||
| ``` | ||
| Commit and push code: | ||
| ```bash | ||
| $ git add . && git commit -m 'PCC45 mhered' # commit | ||
| $ git push origin PCC45 # push to your fork | ||
| ``` |
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.
mypy would also catch this, but it does not prevent the function from being used by other types, after a
raiseyou don't need the else so you could dedent the code below one level