These are examples of Exception Test2. Again we run the tests to see them fail and then add the implementation to make them pass.

Although the guard clauses contain duplication, we decide to leave them as is rather than extracting them into a common method. This is because the communication value outweighs the duplication, but it's a personal choice.

A Hand of Cards
We complete the tests and implementation for the deck of cards and our betting pot, and now it's time to look at creating a hand of cards. Again a to-do list is helpful and we come up with the following list.

  • Create a hand that is initially empty
  • Add cards to hand
  • Check if one hand beats another hand
  • Check if a hand is bust Adding a test for an empty hand is straightforward and we move on to adding cards to the hand.

public void testAddACard()
{
  Hand hand = new Hand();
  hand.add(10);
  assertEquals(1, hand.size());
  hand.add(5);
  assertEquals(2, hand.size());
}

We run the tests and then add the implementation.

public void add( int card )
{
  cards.add(new Integer(card));
}

The tests pass and we can't see any duplication in our Hand class. However the implementation we just added to Hand is remarkably similar to the add method on Deck. Looking back at our list of to-dos for deck we remember that we had to check that the deck was valid, we'd better do the same for Hand.

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

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?

What's on?

  • Optus Deal

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