For this Kata I practiced Test Driven Development by completed another FizzBuzz example.
- PyTest 3.7 or higher
- Python 5.4.1 or higher
- Red, Green, Refactor
- Write the tests in test_fizzbuzz.py and the 'production' code in fizzbuzz.py
- It is ideal to write the smallest amount of code you can to make the test pass.
- The names of the tests should also be named as testing functionality (ex.'test_fizz') never 'divisible_by_three'.
Even though we refactored while we were writing the coding, this program can be refactored a little more by taking the calculations out of fizzbuzz and putting them in a 'helpers.py' file.
In this file you would have functions/modules like is_fizzbuzz(),is_fizz(), is_buzz()
- These functions would have the conditionals
if (num % 3 == 0) and (num % 5 == 0):
result = 'FizzBuzz'
elif num % 3 == 0:
result = 'Fizz'
elif num % 5 == 0:
result = 'Buzz'
- This will allow for the logic to be hidden in the fizzbuzz.py file and it will just import the is_fizzbuzz(),isfizz(),isbuzz() modules from the helpers.py file.