Start by thinking through the requirements and creating a list of test conditions.
In this case its quite clear,
but thinking like a Software Engineer, we can add a couple
of additional use cases that our code needs to handle, but are
not necessarily explicit requirements (e.g. error handling or null checks).
- Do we accept negative numbers?
- Do we accept integers or decimals?
Requirements capture is another ball game, but since we have asked the
questions, then we shall say no on both counts.
Even in this simple example I don't want to mix presentation and logic layers,
so we will aim to produce code to return the desired results,
this can then be incorporated easily into any presentation layer (e.g print to console).
- When a number is divisible by 3 return Fizz
- When a number is divisible by 5 return Buzz
- When a number is divisible by 3 & 5 return FizzBuzz
- All other numbers return that number
- Only accept whole integers in the range 0 to Integer.MAX
Next steps will involve writing unit test cases for each item on the list.
The work is complete when all requirements are met.