Skip to content

Commit e96e1d1

Browse files
authored
Merge pull request #844 from mhered/PCC45
Pcc45
2 parents 214c6f0 + e1248c8 commit e96e1d1

File tree

7 files changed

+73
-0
lines changed

7 files changed

+73
-0
lines changed

45/mhered/app/__init__.py

Whitespace-only changes.

45/mhered/app/fizzbuzz.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python3
2+
3+
4+
def fizzbuzz(num: int):
5+
"""
6+
FizzBuzz(int) plays FizzBuzz
7+
"""
8+
if not isinstance(num, int):
9+
raise ValueError("argument should be of type int")
10+
else:
11+
if num % 5 == 0 and num % 3 == 0:
12+
return "FizzBuzz"
13+
if num % 5 == 0:
14+
return "Buzz"
15+
if num % 3 == 0:
16+
return "Fizz"
17+
return num

45/mhered/fizzbuzz.py

Whitespace-only changes.

45/mhered/test.py

Whitespace-only changes.

45/mhered/test/__init__.py

Whitespace-only changes.

45/mhered/test/test_fizzbuzz.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/python3
2+
3+
import unittest
4+
5+
from app.fizzbuzz import fizzbuzz
6+
7+
8+
class TddFizzBuzz(unittest.TestCase):
9+
10+
def test_fizzbuzz_returns_ints(self):
11+
samples = [1, 2, 4, 6, 7, 8, 11, 13]
12+
for sample in samples:
13+
result = fizzbuzz(sample)
14+
self.assertEqual(result, sample)
15+
16+
def test_fizzbuzz_returns_fizz_with_multiples_of_3(self):
17+
samples = [3, 6, 9, 12]
18+
for sample in samples:
19+
result = fizzbuzz(sample)
20+
self.assertEqual(result, "Fizz")
21+
22+
def test_fizzbuzz_returns_buzz_with_multiples_of_5(self):
23+
samples = [5, 10, 20, 25]
24+
for sample in samples:
25+
result = fizzbuzz(sample)
26+
self.assertEqual(result, "Buzz")
27+
28+
def test_fizzbuzz_returns_fizzbuzz_with_multiples_of_3_and_5(self):
29+
samples = [15, 30, 45, 60]
30+
for sample in samples:
31+
result = fizzbuzz(sample)
32+
self.assertEqual(result, "FizzBuzz")
33+
34+
def test_fizzbuzz_raises_error_message_if_arg_not_int(self):
35+
self.assertRaises(ValueError, fizzbuzz, 'two')
36+
37+
38+
if __name__ == '__main__':
39+
unittest.main()

my notes.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
First time only setup:
2+
```bash
3+
$ git clone https://github.com/mhered/challenges -b community && cd challenges
4+
$ git remote add upstream https://github.com/pybites/challenges
5+
```
6+
Init for every new challenge:
7+
```bash
8+
$ git checkout community # return to community branch
9+
$ git pull upstream community # pull the latest upstream repo
10+
$ git checkout -b PCC45 # create a branch to work on the challenge
11+
$ mkdir 45/mhered && cd $_ # work on your own subdirectory
12+
```
13+
Commit and push code:
14+
```bash
15+
$ git add . && git commit -m 'PCC45 mhered' # commit
16+
$ git push origin PCC45 # push to your fork
17+
```

0 commit comments

Comments
 (0)