I’m pretty much back on track for the 12 TDDs of Christmas as I’ve managed to find the time to complete day three’s task on the correct day (shock!). As with previous days, the code’s available at BitBucket: https://bitbucket.org/CraigHawker/12-tdds-of-christmas.

Today’s task was a nice little task: to create a “hint array” for a given input of mine fields (think the numbers that appear within Minesweeper). I altered the implementation slightly to make it a bit more .NET-y by passing in structured data rather than strings but I don’t think this really affected the task much.
The task wasn’t complicated but it did allow me to try and approach creation of tests, and therefore creation of the actual methods, in a much more structured way. Unlike with the first task, this task allowed me to start with a zero size array and move up through 1×1, through to 3×1 (with mines in different places), then 3×3, then further. At each step I tried to implement only the smallest amount of code to achieve the test passing. I didn’t quite accomplish this as my mind tends to go into overdrive and wants to implement a few more switch statements than are actually required at each stage, but I was much more forceful with myself than I normally would be.

Thanks to @tjlytle who provided a few test cases at https://gist.github.com/4401086, too.

Items in this series:

  1. 12 TDDs of Christmas (day one: Calc Stats)
  2. 12 TDDs of Christmas (day two: Number Names)
  3. 12 TDDs of Christmas (day three: Mine Field)
  4. 12 TDDs of Christmas (day four: Monty Hall, day five: FizzBuzz and day six: Recently-Used List)
  5. 12 TDDs of Christmas (day seven: Template Engine)
  6. 12 TDDs of Christmas (day eight: ranges)