Code Kata – Atari

This Code Kata was set by Keith Braithwaite, at his session TDD As If You Meant It, during Software Craftsmanship 2009.

The challenge is taken from the game of Go. Go is played by two players who alternately place black and white stones on the vacant intersections of a grid of 19×19 lines. A stone is atari if a stone or chain of stones has only one liberty. The liberty is the number of vacant points that are adjacent to a stone or connected group of same coloured stones (diagonals do not count). Some example configurations, with their liberty, are shown in the following pictures:

liberty1liberty2

liberty3liberty4

The Kata is to calculate whether a stone is atari, for an arbitrary collection of stones.

Keith had some rules about how you should proceed with coding, which define an extreme limit of TDD:

  1. Write exactly ONE failing test.
  2. Make the test from (1) pass by first writing implementation code IN THE TEST.
  3. Create a new implementation method/function by:
    • doing extract method on implementation code created as per (2), or
    • moving implementation code as per (2) into an existing implementation method.
  4. Only ever create new methods IN THE TEST CLASS.
  5. Only ever create implementation classes to provide a destination for extracting a method created as per (4).
  6. Populate implementation classes by doing move method from a test class into them.
  7. Refactor as required.
  8. Go to (1).

Some reactions from other attendees of the session are here and here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>