Skip to content

Instantly share code, notes, and snippets.

@rockarts
Created August 5, 2014 07:03
Show Gist options
  • Select an option

  • Save rockarts/f3572a936c36a8be8443 to your computer and use it in GitHub Desktop.

Select an option

Save rockarts/f3572a936c36a8be8443 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
class TestDeck < MiniTest::Unit::TestCase
def test_that_deck_has_52_cards
deck = Deck.new
assert_equal 52, deck.cards.count
end
def test_that_deck_is_shuffled
deck = Deck.new
original_deck = deck.cards.dup
deck.shuffle
refute_equal original_deck, deck.cards
end
end
class Deck
attr_accessor :cards
def initialize
@cards = []
(2..14).each do |x|
Suits.new.suits.each { |suit| @cards << Card.new(suit, x)}
end
end
def shuffle
@cards.shuffle!
end
end
class Card
attr_accessor :suit, :value
def initialize(suit, value)
@suit = suit
@value = value
end
end
class Suits
attr_accessor :suits
def initialize
@suits = ["hearts", "diamonds", "clubs", "spades"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment