[Thousand-Oaks-pm] TDD workshop (TicTacToe sample)

David Oswald daoswald at gmail.com
Thu Oct 11 17:18:51 PDT 2012


I had a little time last night after getting the kids to bed and
played some more with our TDD Tic-Tac-Toe problem.

The code can be viewed here: https://gist.github.com/3876537#

Just for fun the engine that detects or rejects a win is a regex.  Oh,
and I didn't implement "x wins" and "o wins", instead just "winner"
that returns "x", "o", or undef.

Games should be a list that looks like qw( x4 o2 x0 o3 x8 )  .... (x
wins).  The board's positions are numbered 0..8:

0 1 2
3 4 5
6 7 8

Use it like this:


my $winner = TicTac->new->play_moves( qw/ x4 o2 x0 o3 x8 / );
print "$winner wins\n" if defined $winner;



Devel::Cover says:

---------------------------- ------ ------ ------ ------ ------ ------ ------
File                           stmt   bran   cond    sub    pod   time  total
---------------------------- ------ ------ ------ ------ ------ ------ ------
lib/TicTac.pm                 100.0  100.0  100.0  100.0    0.0  100.0   95.5
Total                         100.0  100.0  100.0  100.0    0.0  100.0   95.5
---------------------------- ------ ------ ------ ------ ------ ------ ------

I'm not sure, but I think the 4.5% deduction is because there's no
documentation covering the public methods.

Thanks Peter for a fun workshop.

Dave

-- 

David Oswald
daoswald at gmail.com


More information about the Thousand-Oaks-pm mailing list