Unittesting FizzBuzz
Posted by jpluimers on 2021/02/23
Keep a version history of how you approach the below TDD driven approach, then discuss it with one of your co-workers.
Note there is no “right” approach, though probably you will experience that some environments and approaches may lead to code that is better, for instance because it is:
- easier to explain
- shorter
- more performant
The above 3 might points bite each other (;
Based on FizzBuzz: One Simple Interview Question – YouTube.
Write initial tests
Write unit tests for this unit under test in pseudo code:
type OutputMethod: method(string Value) class FizzBuzzGame: method Construct(OutputMethod Value) method Process(int Value)
Unit test that captures Output
with a certain set of Values, then tests for the four possible combinations:
- number
- Fizz
- Buzz
- FizzBuzz
and also ensures that the passed OutputMethod
is being called once for each call to Process
.
Extend the tests
Now extend the tests to cover the below multiples and all the permutations caused by the longer list. Think carefully about the permutations.
- 3 -> Fizz
- 5 -> Buzz
- 7 -> Fuzz
- 11 -> Bizz
- 13 -> Biff
Write the unit under test
The least tricky bit should be this step.
Be sure to test the solution with your co-workers as well.
Non positive numbers.
Did you think about negative numbers?
Did you think about the number zero?
What would you do about them in the tests and unit under test?
–jeroen
Related
- [Archive.is] “Fizz” “Buzz” “Fuzz” “Bizz” “Biff” – Google Search
- [WayBack] The FizzBuzz “game” in C with input validation and ability to easily extend to more numbers/words · GitHub
- [Archive.is] FizzBuzz: One Simple Interview Question – Tom Scott : curiousvideos
- [Archive.is] Writing FizzBuzz in bash : bash
- [WayBack] FizzBuzz in Bash with no Modulus or for/while loops – Grayson Kent
- [WayBack] Repl.it – GleamingShockedLlama
- [WayBack] List of 4 Letter Words in Scrabble | Unscramblerer.com
Leave a Reply