Texas Hold'Em - The first test

Starting the kata write-up with a quick introduction into getting started, and the first test. The very first thing is to download Eclipse. I momentarily toyed with the idea of using NetBeans or IntelliJ, but I'm so familiar with Eclipse, it's just easier to stick with it. Also, Helios (Eclipse 3.6) was recently released, so this is an opportunity to try it out.

I should also mention I'm using the latest JDK, 1.6.0_20. And using my new laptop to work on the kata (very exciting).

The Code

The next step is to actually start writing some code. The first thing that seems reasonable is to have some sort of PokerGame class which handles most of the interaction - in terms of knowing about the players, telling it when and which cards are dealt, etc. This class can also tell me the winner of the hand - the real requirement of this kata.

I therefore start with PokerGameTest. Now I need a test. Wanting to start small, it's not actually obvious of the simplest case, but I go for a round with only one player who obviously doesn't fold, so sees all the cards. He is of course the winner of the round:

@Test
public void when_there_is_only_one_player_then_his_hand_should_be_the_winner()

The implementation of this test takes a bit of a leap of faith as well. I have to define the player, the various rounds of dealing and a way to get the results.

I'll start with a simple fluent API and then will refine it as I go.

PokerGame game = new PokerGame();
game.deal("john").holeCards("4d 2d");
game.dealFlop("Ks", "Kd", "9d");
game.dealTurn("6h");
game.dealRiver("Jh");

Assert.assertEquals("john: 4d 2d Ks Kd 9d 6h Jh (Winner)", game.results());

So in this game, there's one player, John, who gets dealt his hand, sees the flop cards, followed by the turn and river cards. As he's the only player, and doesn't fold, the result is that he should be declared the winner of that round.

I next get the test to compile and pass as simply as possible:

public class PokerGame {
  public PokerGame deal(String player) { return this; }
  public PokerGame holeCards(String card1, String card2) { return this; }
  public PokerGame dealFlop(String card, String card2, String card3) { return this; }
  public PokerGame dealTurn(String card1) { return this; }
  public PokerGame dealRiver(String card1) { return this; }
  public String results() {
    return "john: 4d 2d Ks Kd 9d 6h Jh (Winner)";
  }
}

Pass!

Unsurprisingly the test passes - I'm effectively just checking two exact strings as there's no logic within the Game class as yet.

Next time, I'll be looking at this initial test and determining my next moves. Out of this, I expect I'll be off on a little tangent before I come to write another test within the Game suite. As a simple example, I have a question in my mind right off with this initial test about how best to represent the cards: no doubt I'll want to create a class for this.

Following along

As mentioned in the initial intro to this kata, I'll be putting the code into GitHub and will start just referencing the code there. As I think this will turn out to be a fair amount of code, simply pasting it into posts isn't going to work. I will however post snippets of interesting parts or refactorings as and when they come about.


Comment Guidelines
See the FAQ for details on the full rules and guidelines. No Spam. Write clearly and thoughtfully - no bad language.