diff --git a/45/mhered/app/__init__.py b/45/mhered/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/45/mhered/app/fizzbuzz.py b/45/mhered/app/fizzbuzz.py new file mode 100644 index 00000000..da737556 --- /dev/null +++ b/45/mhered/app/fizzbuzz.py @@ -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 diff --git a/45/mhered/fizzbuzz.py b/45/mhered/fizzbuzz.py new file mode 100644 index 00000000..e69de29b diff --git a/45/mhered/test.py b/45/mhered/test.py new file mode 100644 index 00000000..e69de29b diff --git a/45/mhered/test/__init__.py b/45/mhered/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/45/mhered/test/test_fizzbuzz.py b/45/mhered/test/test_fizzbuzz.py new file mode 100755 index 00000000..be5a7bfc --- /dev/null +++ b/45/mhered/test/test_fizzbuzz.py @@ -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: + 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): + self.assertRaises(ValueError, fizzbuzz, 'two') + + +if __name__ == '__main__': + unittest.main() diff --git a/my notes.md b/my notes.md new file mode 100644 index 00000000..0bbb623b --- /dev/null +++ b/my notes.md @@ -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 +``` \ No newline at end of file