This time we decided to go back to the basics. Simple straight forward TDD using a really simple problem; FizzBuzz. Or we actually did a variant of it where I presented only one requirement at a time;
- Create a program that writes numbers from 1 to 100 using a special printer class.
- If a number is divisible by three, print Fizz instead of number.
- If a number is divisible by five, print Buzz instead of number. If number is divisible three and five, print FizzBuzz instead of number.
- If the number is more than 3 and not Fizz, Buzz or FizzBuzz; print lots.
- If the number is 11, 42 or 47 disregard all other rules and print Cowabunga.
Since nobody (except me) had seen this kata before it was interesting to see how a simple design evolved into a pretty big and chunky thing that could be refactored into something nice. It is truly amazing to see how such a simple problem can take so long to solve (in little over 2 hours we actually only implemented 1-3 but considering the design 4 and 5 should probably only take another 10 minutes. But I guess that is what makes this a great kata. The problem is so simple but yet can be solved in so many ways.
And the reason to have the printer class was to force the use of an interface we could fake in the tests. Maybe an overkill but and we never used that class in our tests at all. Just the way it should be, wrapping and faking all external dependencies. This is what the external dependency implementation looked like:
1: public class Printer
3: private Random _random = new Random();
5: public Printer(int device)
7: if (_random.Next(10) == 0)
8: throw new ArgumentException("Unable to lock device", "device");
11: public void WriteLine(string line)