Skip to content
Merged

Pcc45 #844

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 45/mhered/app/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions 45/mhered/app/fizzbuzz.py
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):
Copy link
Collaborator

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 raise you don't need the else so you could dedent the code below one level

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 added 45/mhered/fizzbuzz.py
Empty file.
Empty file added 45/mhered/test.py
Empty file.
Empty file added 45/mhered/test/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions 45/mhered/test/test_fizzbuzz.py
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
17 changes: 17 additions & 0 deletions my notes.md
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
```