Created
August 5, 2014 07:03
-
-
Save rockarts/f3572a936c36a8be8443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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