Решение на Четвърта задача от Никола Терзиев

Обратно към всички решения

Към профила на Никола Терзиев

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 46 успешни тест(а)
  • 11 неуспешни тест(а)

Код

class Card
attr_reader :rank, :suit
SUITS = [:spades, :hearts, :diamonds, :clubs]
RANKS = [*(2..10).collect{ | x | x.to_s.to_sym}, :jack, :queen, :king, :ace]
def initialize(rank, suit)
rank = rank.to_s.to_sym
suit = suit.to_s.to_sym
raise ArgumentError, 'Argument is not known rank' unless RANKS.include? rank
raise ArgumentError, 'Argument is not known suit' unless SUITS.include? suit
@rank = rank
@suit = suit
end
def to_s
"#{@rank.capitalize} of #{@suit.capitalize}"
end
def self.suits
SUITS
end
def self.ranks
RANKS
end
end
class BaseDeck
include Enumerable
ALLOWED_RANKS = Card.ranks
ALLOWED_SUITS = Card.suits
def initialize(deck = generate_default_deck)
@deck = deck
end
def generate_default_deck
deck = Array.new
self.class::ALLOWED_RANKS.product(self.class::ALLOWED_SUITS)
.each { |rank, suit| deck.push(Card.new(rank, suit)) }
deck
end
public
def each(&block)
@deck.each(&block)
end
def size
@deck.size
end
def draw_top_card
@deck.shift
end
def draw_bottom_card
@deck.pop
end
def top_card
@deck.last
end
def bottom_card
@deck.first
end
def shuffle
@deck.shuffle!
end
def sort
@deck.sort! { |x,y|
suits_comp = compare_suits(x,y)
suits_comp == 0 ? compare_ranks(y,x) : suits_comp
}
end
def deal
raise "NotImplementedError"
end
def to_s
@deck.map(&:to_s).join("\n")
end
private
def compare_suits(first, second)
ALLOWED_SUITS.find_index(first.suit) <=>
ALLOWED_SUITS.find_index(second.suit)
end
def compare_ranks(first, second)
self.class::ALLOWED_RANKS.find_index(first.rank) <=>
self.class::ALLOWED_RANKS.find_index(second.rank)
end
end
class WarDeck < BaseDeck
CARDS_IN_HAND = 26
def deal
WarHand.new(@deck.take(CARDS_IN_HAND),
self.class::ALLOWED_RANKS,
self.class::ALLOWED_SUITS)
end
end
class BeloteDeck < BaseDeck
ALLOWED_RANKS = [:"7", :"8", :"9", :jack, :queen, :king, :"10", :ace]
CARDS_IN_HAND = 8
def deal
BeloteHand.new(@deck.take(CARDS_IN_HAND),
self.class::ALLOWED_RANKS,
self.class::ALLOWED_SUITS)
end
end
class SixtySixDeck < BaseDeck
ALLOWED_RANKS = [:"9", :jack, :queen, :king, :"10", :ace]
CARDS_IN_HAND = 6
def deal
SixtySixHand.new(@deck.take(CARDS_IN_HAND),
self.class::ALLOWED_RANKS,
self.class::ALLOWED_SUITS)
end
end
class Hand
attr_reader :cards, :allowed_ranks, :allowed_suits
def initialize(cards, allowed_ranks, allowed_suits)
@cards = cards
@allowed_ranks = allowed_ranks
@allowed_suits = allowed_suits
end
def size
@cards.length
end
def fetch_cards(ranks, exclude_suits = [])
@cards.select{ |card| ranks.include? card.rank \
and not exclude_suits.include? card.suit }
end
def filter_cards_by_suit(cards, suit)
cards.select{ |card| card.suit == suit }
end
def cards_exist_in_any_suite?(cards, length)
cards.group_by { |card|
card.suit
}.select{ |suit, cards|
cards.length >= length }.length > 0
end
end
class WarHand < Hand
def play_card
@cards.pop
end
def allow_face_up?
@cards.length <= 3
end
end
class BeloteHand < Hand
def highest_of_suit(suit)
@cards.select { |card|
card.suit == suit
}.max_by { |card|
@allowed_ranks.find_index(card.rank)
}
end
def belote?
cards_exist_in_any_suite?(fetch_cards([:queen, :king]), 2)
end
def tierce?
rank_sequence?(3)
end
def quarte?
rank_sequence?(4)
end
def quint?
rank_sequence?(5)
end
def carre_of_jacks?
fetch_cards([:jack]).length == 4
end
def carre_of_nines?
fetch_cards([:"9"]).length == 4
end
def carre_of_aces?
fetch_cards([:ace]).length == 4
end
private
def rank_sequence?(length)
allowed_ranks.each_cons(length).any? { |sequence|
cards_exist_in_any_suite?(fetch_cards(sequence), length)
}
end
end
class SixtySixHand < Hand
def twenty?(trump_suit)
cards_exist_in_any_suite?(fetch_cards([:queen, :king], [trump_suit]), 2)
end
def forty?(trump_suit)
filter_cards_by_suit(fetch_cards([:queen, :king]), trump_suit).length == 2
end
end

Лог от изпълнението

..F.F...FF.......F...FF....F................F...FF.......

Failures:

  1) Card #== compares two cards by their rank and suit
     Failure/Error: expect(Card.new(4, :spades)).to eq Card.new(4, :spades)
       
       expected: #<Card:0x007fc28fe3a130 @rank=:"4", @suit=:spades>
            got: #<Card:0x007fc28fe3a270 @rank=:"4", @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc28fe3a130 @rank=:"4", @suit=:spades>
       +#<Card:0x007fc28fe3a270 @rank=:"4", @suit=:spades>
     # /tmp/d20151112-27349-1qgz60l/spec.rb:131:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) WarDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007fc290c85050 @rank=:"2", @suit=:clubs>, #<Card:0x007fc290c84fd8 @rank=:"3", @suit=:clubs>, #<Card:0x007fc290c84f60 @rank=:"4", @suit=:clubs>, #<Card:0x007fc290c84ee8 @rank=:"5", @suit=:clubs>, #<Card:0x007fc290c84e70 @rank=:"6", @suit=:clubs>, #<Card:0x007fc290c84df8 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290c84d80 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290c84d08 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290c84c90 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290c84c18 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290c84ba0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290c84b28 @rank=:king, @suit=:clubs>, #<Card:0x007fc290c84a88 @rank=:ace, @suit=:clubs>, #<Card:0x007fc290c84a10 @rank=:"2", @suit=:diamonds>, #<Card:0x007fc290c84998 @rank=:"3", @suit=:diamonds>, #<Card:0x007fc290c84920 @rank=:"4", @suit=:diamonds>, #<Card:0x007fc290c848a8 @rank=:"5", @suit=:diamonds>, #<Card:0x007fc290c84830 @rank=:"6", @suit=:diamonds>, #<Card:0x007fc290c84790 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290c84718 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290c846a0 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290c84628 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290c845b0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290c84510 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290c84498 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290c84420 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290c843a8 @rank=:"2", @suit=:hearts>, #<Card:0x007fc290c84330 @rank=:"3", @suit=:hearts>, #<Card:0x007fc290c842b8 @rank=:"4", @suit=:hearts>, #<Card:0x007fc290c84240 @rank=:"5", @suit=:hearts>, #<Card:0x007fc290c841c8 @rank=:"6", @suit=:hearts>, #<Card:0x007fc290c84150 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290c840d8 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290c84060 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290cebfa8 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290cebf30 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290cebeb8 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290cebe40 @rank=:king, @suit=:hearts>, #<Card:0x007fc290cebdc8 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290cebd50 @rank=:"2", @suit=:spades>, #<Card:0x007fc290cebcd8 @rank=:"3", @suit=:spades>, #<Card:0x007fc290cebc60 @rank=:"4", @suit=:spades>, #<Card:0x007fc290cebbe8 @rank=:"5", @suit=:spades>, #<Card:0x007fc290cebb70 @rank=:"6", @suit=:spades>, #<Card:0x007fc290cebaf8 @rank=:"7", @suit=:spades>, #<Card:0x007fc290ceba80 @rank=:"8", @suit=:spades>, #<Card:0x007fc290ceba08 @rank=:"9", @suit=:spades>, #<Card:0x007fc290ceb990 @rank=:"10", @suit=:spades>, #<Card:0x007fc290ceb8f0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290ceb850 @rank=:queen, @suit=:spades>, #<Card:0x007fc290ceb7d8 @rank=:king, @suit=:spades>, #<Card:0x007fc290ceb738 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fc290c87648 @rank=:"2", @suit=:spades>, #<Card:0x007fc290c875d0 @rank=:"2", @suit=:hearts>, #<Card:0x007fc290c87558 @rank=:"2", @suit=:diamonds>, #<Card:0x007fc290c87490 @rank=:"2", @suit=:clubs>, #<Card:0x007fc290c873f0 @rank=:"3", @suit=:spades>, #<Card:0x007fc290c87350 @rank=:"3", @suit=:hearts>, #<Card:0x007fc290c87260 @rank=:"3", @suit=:diamonds>, #<Card:0x007fc290c87170 @rank=:"3", @suit=:clubs>, #<Card:0x007fc290c870f8 @rank=:"4", @suit=:spades>, #<Card:0x007fc290c87058 @rank=:"4", @suit=:hearts>, #<Card:0x007fc290c86fe0 @rank=:"4", @suit=:diamonds>, #<Card:0x007fc290c86f68 @rank=:"4", @suit=:clubs>, #<Card:0x007fc290c86ef0 @rank=:"5", @suit=:spades>, #<Card:0x007fc290c86e78 @rank=:"5", @suit=:hearts>, #<Card:0x007fc290c86e00 @rank=:"5", @suit=:diamonds>, #<Card:0x007fc290c86d88 @rank=:"5", @suit=:clubs>, #<Card:0x007fc290c86d10 @rank=:"6", @suit=:spades>, #<Card:0x007fc290c86c70 @rank=:"6", @suit=:hearts>, #<Card:0x007fc290c86bf8 @rank=:"6", @suit=:diamonds>, #<Card:0x007fc290c86b80 @rank=:"6", @suit=:clubs>, #<Card:0x007fc290c86b08 @rank=:"7", @suit=:spades>, #<Card:0x007fc290c86a90 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290c86a18 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290c869a0 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290c86928 @rank=:"8", @suit=:spades>, #<Card:0x007fc290c868b0 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290c86838 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290c86798 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290c866f8 @rank=:"9", @suit=:spades>, #<Card:0x007fc290c86680 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290c86608 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290c86590 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290c86518 @rank=:"10", @suit=:spades>, #<Card:0x007fc290c86478 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290c86400 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290c86360 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290c862e8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290c86270 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290c861f8 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290c86180 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290c86108 @rank=:queen, @suit=:spades>, #<Card:0x007fc290c86090 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290c86018 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290c85fa0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290c85f00 @rank=:king, @suit=:spades>, #<Card:0x007fc290c85e88 @rank=:king, @suit=:hearts>, #<Card:0x007fc290c85de8 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290c85d48 @rank=:king, @suit=:clubs>, #<Card:0x007fc290c85ca8 @rank=:ace, @suit=:spades>, #<Card:0x007fc290c85c30 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290c85bb8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290c85b18 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fc290c85050 @rank=:"2", @suit=:clubs>, #<Card:0x007fc290c84fd8 @rank=:"3", @suit=:clubs>, #<Card:0x007fc290c84f60 @rank=:"4", @suit=:clubs>, #<Card:0x007fc290c84ee8 @rank=:"5", @suit=:clubs>, #<Card:0x007fc290c84e70 @rank=:"6", @suit=:clubs>, #<Card:0x007fc290c84df8 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290c84d80 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290c84d08 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290c84c90 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290c84c18 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290c84ba0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290c84b28 @rank=:king, @suit=:clubs>, #<Card:0x007fc290c84a88 @rank=:ace, @suit=:clubs>, #<Card:0x007fc290c84a10 @rank=:"2", @suit=:diamonds>, #<Card:0x007fc290c84998 @rank=:"3", @suit=:diamonds>, #<Card:0x007fc290c84920 @rank=:"4", @suit=:diamonds>, #<Card:0x007fc290c848a8 @rank=:"5", @suit=:diamonds>, #<Card:0x007fc290c84830 @rank=:"6", @suit=:diamonds>, #<Card:0x007fc290c84790 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290c84718 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290c846a0 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290c84628 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290c845b0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290c84510 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290c84498 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290c84420 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290c843a8 @rank=:"2", @suit=:hearts>, #<Card:0x007fc290c84330 @rank=:"3", @suit=:hearts>, #<Card:0x007fc290c842b8 @rank=:"4", @suit=:hearts>, #<Card:0x007fc290c84240 @rank=:"5", @suit=:hearts>, #<Card:0x007fc290c841c8 @rank=:"6", @suit=:hearts>, #<Card:0x007fc290c84150 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290c840d8 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290c84060 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290cebfa8 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290cebf30 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290cebeb8 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290cebe40 @rank=:king, @suit=:hearts>, #<Card:0x007fc290cebdc8 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290cebd50 @rank=:"2", @suit=:spades>, #<Card:0x007fc290cebcd8 @rank=:"3", @suit=:spades>, #<Card:0x007fc290cebc60 @rank=:"4", @suit=:spades>, #<Card:0x007fc290cebbe8 @rank=:"5", @suit=:spades>, #<Card:0x007fc290cebb70 @rank=:"6", @suit=:spades>, #<Card:0x007fc290cebaf8 @rank=:"7", @suit=:spades>, #<Card:0x007fc290ceba80 @rank=:"8", @suit=:spades>, #<Card:0x007fc290ceba08 @rank=:"9", @suit=:spades>, #<Card:0x007fc290ceb990 @rank=:"10", @suit=:spades>, #<Card:0x007fc290ceb8f0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290ceb850 @rank=:queen, @suit=:spades>, #<Card:0x007fc290ceb7d8 @rank=:king, @suit=:spades>, #<Card:0x007fc290ceb738 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fc290c87648 @rank=:"2", @suit=:spades>, #<Card:0x007fc290c875d0 @rank=:"2", @suit=:hearts>, #<Card:0x007fc290c87558 @rank=:"2", @suit=:diamonds>, #<Card:0x007fc290c87490 @rank=:"2", @suit=:clubs>, #<Card:0x007fc290c873f0 @rank=:"3", @suit=:spades>, #<Card:0x007fc290c87350 @rank=:"3", @suit=:hearts>, #<Card:0x007fc290c87260 @rank=:"3", @suit=:diamonds>, #<Card:0x007fc290c87170 @rank=:"3", @suit=:clubs>, #<Card:0x007fc290c870f8 @rank=:"4", @suit=:spades>, #<Card:0x007fc290c87058 @rank=:"4", @suit=:hearts>, #<Card:0x007fc290c86fe0 @rank=:"4", @suit=:diamonds>, #<Card:0x007fc290c86f68 @rank=:"4", @suit=:clubs>, #<Card:0x007fc290c86ef0 @rank=:"5", @suit=:spades>, #<Card:0x007fc290c86e78 @rank=:"5", @suit=:hearts>, #<Card:0x007fc290c86e00 @rank=:"5", @suit=:diamonds>, #<Card:0x007fc290c86d88 @rank=:"5", @suit=:clubs>, #<Card:0x007fc290c86d10 @rank=:"6", @suit=:spades>, #<Card:0x007fc290c86c70 @rank=:"6", @suit=:hearts>, #<Card:0x007fc290c86bf8 @rank=:"6", @suit=:diamonds>, #<Card:0x007fc290c86b80 @rank=:"6", @suit=:clubs>, #<Card:0x007fc290c86b08 @rank=:"7", @suit=:spades>, #<Card:0x007fc290c86a90 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290c86a18 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290c869a0 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290c86928 @rank=:"8", @suit=:spades>, #<Card:0x007fc290c868b0 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290c86838 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290c86798 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290c866f8 @rank=:"9", @suit=:spades>, #<Card:0x007fc290c86680 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290c86608 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290c86590 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290c86518 @rank=:"10", @suit=:spades>, #<Card:0x007fc290c86478 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290c86400 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290c86360 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290c862e8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290c86270 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290c861f8 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290c86180 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290c86108 @rank=:queen, @suit=:spades>, #<Card:0x007fc290c86090 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290c86018 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290c85fa0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290c85f00 @rank=:king, @suit=:spades>, #<Card:0x007fc290c85e88 @rank=:king, @suit=:hearts>, #<Card:0x007fc290c85de8 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290c85d48 @rank=:king, @suit=:clubs>, #<Card:0x007fc290c85ca8 @rank=:ace, @suit=:spades>, #<Card:0x007fc290c85c30 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290c85bb8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290c85b18 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:140
     # /tmp/d20151112-27349-1qgz60l/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) WarDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007fc290ccc0b8 @rank=:ace, @suit=:spades>
            got: #<Card:0x007fc290ccc040 @rank=:"9", @suit=:clubs>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290ccc0b8 @rank=:ace, @suit=:spades>
       +#<Card:0x007fc290ccc040 @rank=:"9", @suit=:clubs>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:140
     # /tmp/d20151112-27349-1qgz60l/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fc290cb4e18 @rank=:"9", @suit=:clubs>
            got: #<Card:0x007fc290cb4f30 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290cb4e18 @rank=:"9", @suit=:clubs>
       +#<Card:0x007fc290cb4f30 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:140
     # /tmp/d20151112-27349-1qgz60l/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007fc290b95e38 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290b95cf8 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290b95c30 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290b95b68 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290b95a78 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290b959d8 @rank=:king, @suit=:clubs>, #<Card:0x007fc290b95910 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290b95708 @rank=:ace, @suit=:clubs>, #<Card:0x007fc290b955a0 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290b954d8 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290b952a8 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290b94f60 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290b94ec0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290b94d08 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290b94b78 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290b94a10 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290b94858 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290b945b0 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290b94470 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290b94308 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290b94240 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290b94128 @rank=:king, @suit=:hearts>, #<Card:0x007fc290b96a68 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290b97198 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290b97f08 @rank=:"7", @suit=:spades>, #<Card:0x007fc290b7ff20 @rank=:"8", @suit=:spades>, #<Card:0x007fc290b7fe30 @rank=:"9", @suit=:spades>, #<Card:0x007fc290b7fca0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290b7fbd8 @rank=:queen, @suit=:spades>, #<Card:0x007fc290b7fa98 @rank=:king, @suit=:spades>, #<Card:0x007fc290b7f9d0 @rank=:"10", @suit=:spades>, #<Card:0x007fc290b7f908 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fc290ba8420 @rank=:"7", @suit=:spades>, #<Card:0x007fc290ba8380 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290ba82e0 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290ba8218 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290ba8150 @rank=:"8", @suit=:spades>, #<Card:0x007fc290ba8088 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290b97fa8 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290b97ee0 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290b97e68 @rank=:"9", @suit=:spades>, #<Card:0x007fc290b97df0 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290b97d00 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290b97c88 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290b97be8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290b97b48 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290b97a30 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290b97968 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290b977d8 @rank=:queen, @suit=:spades>, #<Card:0x007fc290b97710 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290b975d0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290b97558 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290b974b8 @rank=:king, @suit=:spades>, #<Card:0x007fc290b97440 @rank=:king, @suit=:hearts>, #<Card:0x007fc290b97300 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290b97170 @rank=:king, @suit=:clubs>, #<Card:0x007fc290b97058 @rank=:"10", @suit=:spades>, #<Card:0x007fc290b96f90 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290b96f18 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290b96e28 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290b96db0 @rank=:ace, @suit=:spades>, #<Card:0x007fc290b96cc0 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290b96bd0 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290b96a18 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fc290b95e38 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290b95cf8 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290b95c30 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290b95b68 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290b95a78 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290b959d8 @rank=:king, @suit=:clubs>, #<Card:0x007fc290b95910 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290b95708 @rank=:ace, @suit=:clubs>, #<Card:0x007fc290b955a0 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290b954d8 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290b952a8 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290b94f60 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290b94ec0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290b94d08 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290b94b78 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290b94a10 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290b94858 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290b945b0 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290b94470 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290b94308 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290b94240 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290b94128 @rank=:king, @suit=:hearts>, #<Card:0x007fc290b96a68 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290b97198 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290b97f08 @rank=:"7", @suit=:spades>, #<Card:0x007fc290b7ff20 @rank=:"8", @suit=:spades>, #<Card:0x007fc290b7fe30 @rank=:"9", @suit=:spades>, #<Card:0x007fc290b7fca0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290b7fbd8 @rank=:queen, @suit=:spades>, #<Card:0x007fc290b7fa98 @rank=:king, @suit=:spades>, #<Card:0x007fc290b7f9d0 @rank=:"10", @suit=:spades>, #<Card:0x007fc290b7f908 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fc290ba8420 @rank=:"7", @suit=:spades>, #<Card:0x007fc290ba8380 @rank=:"7", @suit=:hearts>, #<Card:0x007fc290ba82e0 @rank=:"7", @suit=:diamonds>, #<Card:0x007fc290ba8218 @rank=:"7", @suit=:clubs>, #<Card:0x007fc290ba8150 @rank=:"8", @suit=:spades>, #<Card:0x007fc290ba8088 @rank=:"8", @suit=:hearts>, #<Card:0x007fc290b97fa8 @rank=:"8", @suit=:diamonds>, #<Card:0x007fc290b97ee0 @rank=:"8", @suit=:clubs>, #<Card:0x007fc290b97e68 @rank=:"9", @suit=:spades>, #<Card:0x007fc290b97df0 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290b97d00 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290b97c88 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290b97be8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290b97b48 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290b97a30 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290b97968 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290b977d8 @rank=:queen, @suit=:spades>, #<Card:0x007fc290b97710 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290b975d0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290b97558 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290b974b8 @rank=:king, @suit=:spades>, #<Card:0x007fc290b97440 @rank=:king, @suit=:hearts>, #<Card:0x007fc290b97300 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290b97170 @rank=:king, @suit=:clubs>, #<Card:0x007fc290b97058 @rank=:"10", @suit=:spades>, #<Card:0x007fc290b96f90 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290b96f18 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290b96e28 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290b96db0 @rank=:ace, @suit=:spades>, #<Card:0x007fc290b96cc0 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290b96bd0 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290b96a18 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:191
     # /tmp/d20151112-27349-1qgz60l/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007fc290b30bf0 @rank=:ace, @suit=:spades>
            got: #<Card:0x007fc290b30b78 @rank=:"9", @suit=:clubs>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290b30bf0 @rank=:ace, @suit=:spades>
       +#<Card:0x007fc290b30b78 @rank=:"9", @suit=:clubs>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:191
     # /tmp/d20151112-27349-1qgz60l/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fc290b041b8 @rank=:"9", @suit=:clubs>
            got: #<Card:0x007fc290b042a8 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290b041b8 @rank=:"9", @suit=:clubs>
       +#<Card:0x007fc290b042a8 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:191
     # /tmp/d20151112-27349-1qgz60l/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: expect(hand.highest_of_suit(:clubs)).to eq Card.new(:ace, :clubs)
       
       expected: #<Card:0x007fc290a92dd8 @rank=:ace, @suit=:clubs>
            got: #<Card:0x007fc290a934e0 @rank=:ace, @suit=:clubs>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290a92dd8 @rank=:ace, @suit=:clubs>
       +#<Card:0x007fc290a934e0 @rank=:ace, @suit=:clubs>
     # /tmp/d20151112-27349-1qgz60l/spec.rb:232:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
       expected collection contained:  [#<Card:0x007fc290674c60 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290674be8 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290674b70 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290674af8 @rank=:king, @suit=:clubs>, #<Card:0x007fc290674a58 @rank=:"10", @suit=:clubs>, #<Card:0x007fc2906749b8 @rank=:ace, @suit=:clubs>, #<Card:0x007fc2906748f0 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290674800 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290674788 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290674710 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290674670 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc2906745f8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290674558 @rank=:"9", @suit=:hearts>, #<Card:0x007fc2906744b8 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290674418 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290674378 @rank=:king, @suit=:hearts>, #<Card:0x007fc2906742b0 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290674210 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290674198 @rank=:"9", @suit=:spades>, #<Card:0x007fc2906740f8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290674058 @rank=:queen, @suit=:spades>, #<Card:0x007fc2906763f8 @rank=:king, @suit=:spades>, #<Card:0x007fc290677d48 @rank=:"10", @suit=:spades>, #<Card:0x007fc290663e38 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fc2906762b8 @rank=:"9", @suit=:spades>, #<Card:0x007fc2906761f0 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290676150 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc2906760b0 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290675ed0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290675e30 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290675d68 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290675cf0 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290675c78 @rank=:queen, @suit=:spades>, #<Card:0x007fc290675c00 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290675b60 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290675ac0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc2906759f8 @rank=:king, @suit=:spades>, #<Card:0x007fc290675980 @rank=:king, @suit=:hearts>, #<Card:0x007fc2906758b8 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290675840 @rank=:king, @suit=:clubs>, #<Card:0x007fc290675778 @rank=:"10", @suit=:spades>, #<Card:0x007fc2906756d8 @rank=:"10", @suit=:hearts>, #<Card:0x007fc2906755e8 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290675548 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290675480 @rank=:ace, @suit=:spades>, #<Card:0x007fc2906753b8 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290675340 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290675278 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fc290674c60 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290674be8 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290674b70 @rank=:queen, @suit=:clubs>, #<Card:0x007fc290674af8 @rank=:king, @suit=:clubs>, #<Card:0x007fc290674a58 @rank=:"10", @suit=:clubs>, #<Card:0x007fc2906749b8 @rank=:ace, @suit=:clubs>, #<Card:0x007fc2906748f0 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc290674800 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290674788 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290674710 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290674670 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc2906745f8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290674558 @rank=:"9", @suit=:hearts>, #<Card:0x007fc2906744b8 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290674418 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290674378 @rank=:king, @suit=:hearts>, #<Card:0x007fc2906742b0 @rank=:"10", @suit=:hearts>, #<Card:0x007fc290674210 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290674198 @rank=:"9", @suit=:spades>, #<Card:0x007fc2906740f8 @rank=:jack, @suit=:spades>, #<Card:0x007fc290674058 @rank=:queen, @suit=:spades>, #<Card:0x007fc2906763f8 @rank=:king, @suit=:spades>, #<Card:0x007fc290677d48 @rank=:"10", @suit=:spades>, #<Card:0x007fc290663e38 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fc2906762b8 @rank=:"9", @suit=:spades>, #<Card:0x007fc2906761f0 @rank=:"9", @suit=:hearts>, #<Card:0x007fc290676150 @rank=:"9", @suit=:diamonds>, #<Card:0x007fc2906760b0 @rank=:"9", @suit=:clubs>, #<Card:0x007fc290675ed0 @rank=:jack, @suit=:spades>, #<Card:0x007fc290675e30 @rank=:jack, @suit=:hearts>, #<Card:0x007fc290675d68 @rank=:jack, @suit=:diamonds>, #<Card:0x007fc290675cf0 @rank=:jack, @suit=:clubs>, #<Card:0x007fc290675c78 @rank=:queen, @suit=:spades>, #<Card:0x007fc290675c00 @rank=:queen, @suit=:hearts>, #<Card:0x007fc290675b60 @rank=:queen, @suit=:diamonds>, #<Card:0x007fc290675ac0 @rank=:queen, @suit=:clubs>, #<Card:0x007fc2906759f8 @rank=:king, @suit=:spades>, #<Card:0x007fc290675980 @rank=:king, @suit=:hearts>, #<Card:0x007fc2906758b8 @rank=:king, @suit=:diamonds>, #<Card:0x007fc290675840 @rank=:king, @suit=:clubs>, #<Card:0x007fc290675778 @rank=:"10", @suit=:spades>, #<Card:0x007fc2906756d8 @rank=:"10", @suit=:hearts>, #<Card:0x007fc2906755e8 @rank=:"10", @suit=:diamonds>, #<Card:0x007fc290675548 @rank=:"10", @suit=:clubs>, #<Card:0x007fc290675480 @rank=:ace, @suit=:spades>, #<Card:0x007fc2906753b8 @rank=:ace, @suit=:hearts>, #<Card:0x007fc290675340 @rank=:ace, @suit=:diamonds>, #<Card:0x007fc290675278 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:400
     # /tmp/d20151112-27349-1qgz60l/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
       
       expected: #<Card:0x007fc290228ad0 @rank=:ace, @suit=:spades>
            got: #<Card:0x007fc2902280a8 @rank=:"9", @suit=:clubs>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc290228ad0 @rank=:ace, @suit=:spades>
       +#<Card:0x007fc2902280a8 @rank=:"9", @suit=:clubs>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:400
     # /tmp/d20151112-27349-1qgz60l/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fc29002e928 @rank=:"9", @suit=:clubs>
            got: #<Card:0x007fc29002ec20 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fc29002e928 @rank=:"9", @suit=:clubs>
       +#<Card:0x007fc29002ec20 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1qgz60l/spec.rb:400
     # /tmp/d20151112-27349-1qgz60l/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.05123 seconds
57 examples, 11 failures

Failed examples:

rspec /tmp/d20151112-27349-1qgz60l/spec.rb:130 # Card #== compares two cards by their rank and suit
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:42 # WarDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:49 # WarDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:42 # BeloteDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:49 # BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:220 # BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:42 # SixtySixDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1qgz60l/spec.rb:49 # SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card

История (1 версия и 1 коментар)

Никола обнови решението на 07.11.2015 00:44 (преди над 8 години)

+class Card
+ attr_reader :rank, :suit
+
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
+ RANKS = [*(2..10).collect{ | x | x.to_s.to_sym}, :jack, :queen, :king, :ace]
+
+
+ def initialize(rank, suit)
+ rank = rank.to_s.to_sym
+ suit = suit.to_s.to_sym
+ raise ArgumentError, 'Argument is not known rank' unless RANKS.include? rank
+ raise ArgumentError, 'Argument is not known suit' unless SUITS.include? suit
+
+ @rank = rank
+ @suit = suit
+ end
+
+ def to_s
+ "#{@rank.capitalize} of #{@suit.capitalize}"
+ end
+
+ def self.suits
+ SUITS
+ end
+
+ def self.ranks
+ RANKS
+ end
+
+end
+
+class BaseDeck
+
+ include Enumerable
+
+ ALLOWED_RANKS = Card.ranks
+ ALLOWED_SUITS = Card.suits
+
+ def initialize(deck = generate_default_deck)
+ @deck = deck
+ end
+
+ def generate_default_deck
+ deck = Array.new
+ self.class::ALLOWED_RANKS.product(self.class::ALLOWED_SUITS)
+ .each { |rank, suit| deck.push(Card.new(rank, suit)) }
+ deck
+ end
+
+ public
+ def each(&block)
+ @deck.each(&block)
+ end
+
+ def size
+ @deck.size
+ end
+
+ def draw_top_card
+ @deck.shift
+ end
+
+ def draw_bottom_card
+ @deck.pop
+ end
+
+ def top_card
+ @deck.last
+ end
+
+ def bottom_card
+ @deck.first
+ end
+
+ def shuffle
+ @deck.shuffle!
+ end
+
+ def sort
+ @deck.sort! { |x,y|
+ suits_comp = compare_suits(x,y)
+ suits_comp == 0 ? compare_ranks(y,x) : suits_comp
+ }
+ end
+
+ def deal
+ raise "NotImplementedError"
+ end
+
+ def to_s
+ @deck.map(&:to_s).join("\n")
+ end
+
+ private
+ def compare_suits(first, second)
+ ALLOWED_SUITS.find_index(first.suit) <=>
+ ALLOWED_SUITS.find_index(second.suit)
+ end
+
+ def compare_ranks(first, second)
+ self.class::ALLOWED_RANKS.find_index(first.rank) <=>
+ self.class::ALLOWED_RANKS.find_index(second.rank)
+ end
+end
+
+
+class WarDeck < BaseDeck
+ CARDS_IN_HAND = 26
+ def deal
+ WarHand.new(@deck.take(CARDS_IN_HAND),
+ self.class::ALLOWED_RANKS,
+ self.class::ALLOWED_SUITS)
+ end
+end
+
+
+class BeloteDeck < BaseDeck
+ ALLOWED_RANKS = [:"7", :"8", :"9", :jack, :queen, :king, :"10", :ace]
+ CARDS_IN_HAND = 8
+ def deal
+ BeloteHand.new(@deck.take(CARDS_IN_HAND),
+ self.class::ALLOWED_RANKS,
+ self.class::ALLOWED_SUITS)
+ end
+end
+
+
+class SixtySixDeck < BaseDeck
+ ALLOWED_RANKS = [:"9", :jack, :queen, :king, :"10", :ace]
+ CARDS_IN_HAND = 6
+ def deal
+ SixtySixHand.new(@deck.take(CARDS_IN_HAND),
+ self.class::ALLOWED_RANKS,
+ self.class::ALLOWED_SUITS)
+ end
+end
+
+class Hand
+ attr_reader :cards, :allowed_ranks, :allowed_suits
+
+ def initialize(cards, allowed_ranks, allowed_suits)
+ @cards = cards
+ @allowed_ranks = allowed_ranks
+ @allowed_suits = allowed_suits
+ end
+
+ def size
+ @cards.length
+ end
+
+ def fetch_cards(ranks, exclude_suits = [])
+ @cards.select{ |card| ranks.include? card.rank \
+ and not exclude_suits.include? card.suit }
+ end
+
+ def filter_cards_by_suit(cards, suit)
+ cards.select{ |card| card.suit == suit }
+ end
+
+ def cards_exist_in_any_suite?(cards, length)
+ cards.group_by { |card|
+ card.suit
+ }.select{ |suit, cards|
+ cards.length >= length }.length > 0
+ end
+end
+
+class WarHand < Hand
+ def play_card
+ @cards.pop
+ end
+
+ def allow_face_up?
+ @cards.length <= 3
+ end
+end
+
+class BeloteHand < Hand
+ def highest_of_suit(suit)
+ @cards.select { |card|
+ card.suit == suit
+ }.max_by { |card|
+ @allowed_ranks.find_index(card.rank)
+ }
+ end
+
+ def belote?
+ cards_exist_in_any_suite?(fetch_cards([:queen, :king]), 2)
+ end
+
+ def tierce?
+ rank_sequence?(3)
+ end
+
+ def quarte?
+ rank_sequence?(4)
+ end
+
+ def quint?
+ rank_sequence?(5)
+ end
+
+ def carre_of_jacks?
+ fetch_cards([:jack]).length == 4
+ end
+
+ def carre_of_nines?
+ fetch_cards([:"9"]).length == 4
+ end
+
+ def carre_of_aces?
+ fetch_cards([:ace]).length == 4
+ end
+
+ private
+ def rank_sequence?(length)
+ allowed_ranks.each_cons(length).any? { |sequence|
+ cards_exist_in_any_suite?(fetch_cards(sequence), length)
+ }
+ end
+end
+
+class SixtySixHand < Hand
+
+ def twenty?(trump_suit)
+ cards_exist_in_any_suite?(fetch_cards([:queen, :king], [trump_suit]), 2)
+ end
+
+ def forty?(trump_suit)
+ filter_cards_by_suit(fetch_cards([:queen, :king]), trump_suit).length == 2
+ end
+
+end

Имаш проблеми със спазването на конвенциите на места, направи справка с ръководството за стил.

Основно начина на задаване на блокове, на места има ненужни нови редове. На ръба си да ти се отнемат точки. Постарай се повече в следващите задачи.