Collecting TDD Katas
I'm not sure why I didn't have this idea earlier. The idea to collect TDD Katas here on this blog seems kind of obvious to me. But anyway, I've been fascinated by this idea ever since I saw the first Kata in Uncle Bob Martin's Clean Code video series. If I remember correctly, then I think I saw him do
Recently then, I ran into this blog post by Peter Provost called Kata - the Only Way to Learn TDD. This blog post mentions 2 TDD Katas, with an exact sequence of recommended tests which I would like to collect here for easier reference.
Before Peter goes into details about the Katas, he mentions the following advice, which also gives the blog post its title:"
Lately I’ve been asked by more and more people inside Microsoft to help them really learn to do TDD. [...] My guidance to them is simple. Do a TDD kata every morning for two weeks. Limit yourself to 30 minutes each morning. Then pick another kata and do it again.
Let's now look at the 2 Katas which he mentions in detail.
The Bowling Game Kata
Uncle Bob breaks this kata down into the following five tests:
- Gutter game scores zero - When you roll all misses, you get a total score of zero.
- All ones scores 20 - When you knock down one pin with each ball, your total score is 20.
- A spare in the first frame, followed by three pins, followed by all misses scores 16.
- A strike in the first frame, followed by three and then four pins, followed by all misses, scores 24.
- A perfect game (12 strikes) scores 300.
The String Calculator Kata
- An empty string returns zero
- A single number returns the value
- Two numbers, comma delimited, returns the sum
- Two numbers, newline delimited, returns the sum
- Three numbers, delimited either way, returns the sum
- Negative numbers throw an exception
- Numbers greater than 1000 are ignored
- A single char delimiter can be defined on the first line (e.g. //# for a ‘#’ as the delimiter)
- A multi char delimiter can be defined on the first line (e.g. //[###] for ‘###’ as the delimiter)
- Many single or multi-char delimiters can be defined (each wrapped in square brackets)