Tasks
The story as it stands is a little too big to tackle on its own, so typically it would be broken down into a set of tasks that enable us to complete the story. For this simple blackjack story the following tasks can be identified.

  • Create a deck of cards
  • Create a betting pot
  • Create a hand of cards
  • Create the game
  • Create a deck of cards

As we break down a story into tasks, we can break a task down into a set of to-do items that will guide our tests. That gives us confidence that when all the tests pass, the task has been completed. For the deck of cards we have the following list of to-dos.

  • Add a card to the deck
  • Deal a card removing it from the deck
  • Check if a deck is empty
  • Check the number of cards in the deck
  • Limit the deck to 52 cards (throw an exception if more are added)
  • Cards are dealt last in last out
  • Shuffle the cards in the deck
  • Check that the added cards are a valid deck

After working through the first few simple tests our to-do list looks like this;

  • Add a card to the deck
  • Deal a card removing it from the deck
  • Check if a deck is empty
  • Check the number of cards in the deck
  • Limit the deck to 52 cards (throw an exception if more are added)
  • Cards are dealt last in last out
  • Shuffle the cards in the deck
  • Check that the added cards are a valid deck

The next test to tackle is dealing a card from the deck. When we write the code for the test method we are acting as a client of the implementation code we have yet to write. This is where we are designing what the interface to our class will look like to those that will have to use it. In this instance we're following the Command/Query Separation Principle5 and code the test as shown below.

Deck class. This is shown in Listing A.

Listing A

All our tests pass and we can't see any duplication or other necessary refactoring, so it should be time to move on the next test. Except that it isn't. Our implementation of the top and remove methods contain a potential problem. What happens if they are called on an empty Deck? Both methods will propagate an IndexOutOfBoundsException from the internal list of cards but we're not currently communicating this. Looking back at our rules for simplicity we see that we need to be communicative. Clients of our class should be made aware of the potential problem. Fortunately we have our tests as a means of communication and we add the following additional tests.

Related links

Comments

1

D. Hoehn - 22/08/05

Just read this and there will be a Certified Scrum Master course in Sydney on the
25th and 26th of this month. You can read more about it here:
http://scrumeducation.com/scrumedu/Cl****/id~32

Apparently it will be held at the Quay West City Hotel, but I am sure
there will be more info when someone signs up. Just so you do nto need
to click the link if costs are an issue,-> "The fee for this course is
1000,- US dollars. It is payable by bank transmission."

Thank you kindly!

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

1

D. Hoehn - 22/08/05

Just read this and there will be a Certified Scrum Master course in Sydney on the 25th and 26th of this ... more

Log in


Sign up | Forgot your password?

  • Staff Microsoft shows off IE9 preview

    This week, highlights from Microsoft's MIX10 conference and more in the Roundup. Read more »

    -- posted by Staff

  • Chris Duckett IE9's H.264 vote killed Ogg

    In a split decision by the judges, the winner of the W3C/WHATWG video codec consensus is H.264, taking home the future of video playback on the internet while loser Ogg goes home with nothing but thoughts of what might have been. Read more »

    -- posted by Chris Duckett

  • Staff Google launches Apps Marketplace

    Google launches and app store, while Mozilla plans to re-write its open-source license. More of this week's news in the Roundup. Read more »

    -- posted by Staff

What's on?

  • Optus Deal

    Broadband + home phone + PlayStation®3 in a single package price!