Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created January 31, 2013 14:57
Show Gist options
  • Save jbrechtel/4683399 to your computer and use it in GitHub Desktop.
Save jbrechtel/4683399 to your computer and use it in GitHub Desktop.
Deck of cards problem part 1

Dealing cards

A deck comprises 52 cards of 4 suits (spades, hearts, clubs, and diamonds). Each suit has 13 cards of values from 2-10, Jack, Queen, King, and Ace.

Write a class to represent a card. The class should have a suit and value property indicating its suit and value.

Write a class that has a draw method.

  • The draw method should accept an integer as an argument.
  • The draw method should return an array of card objects.
  • The array should have as many card objects as specified by the integer argument.
  • Each card should be different.
  • Calling draw multiple times should result in unique cards across each draw invocation.
  • When draw is called and there aren't enough cards remaining in the deck to satisfy the requirement the draw method should return an empty array

Ideas on unit tests

Some tests you could write for this are:

  • calling draw on a deck results in the specified number of cards
  • calling draw on a deck with a number higher than the remaining cards results in an empty array being returned
  • each card returned from draw is different
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment