Решение на Четвърта задача от Милена Дренска

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

Към профила на Милена Дренска

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 39 успешни тест(а)
  • 18 неуспешни тест(а)

Код

module HandFactory
def get_hand(deck_name, *args)
return WarHand.new(*args) if deck_name == 'WarDeck'
return BeloteHand.new(*args) if deck_name == 'BeloteDeck'
return SixtySixHand.new(*args) if deck_name == 'SixtySixDeck'
end
end
class Card
attr_reader :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def to_s
return "#{@rank.to_s.capitalize} of #{@suit.to_s.capitalize}"
end
end
class Deck
include Enumerable
include HandFactory
RANKS = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace]
SUITS = [:spades, :hearts, :diamonds, :clubs]
def initialize(cards = nil)
@cards = cards || self.class::RANKS.product(SUITS)
.map { |card_parameters| Card.new(card_parameters[0],card_parameters[1]) }
end
def each(&block)
@cards.each { |rank| block.call(rank) }
end
def size
size = self.class::RANKS.length * SUITS.length
end
def draw_top_card
top_card = @cards.shift
end
def draw_bottom_card
bottom_card = @cards.shift
end
def top_card
top_card = @cards[0]
end
def bottom_card
bottom_card = @cards[-1]
end
def shuffle
@cards.shuffle!
end
def sort
@cards.sort! do |a, b|
rank_sort = RANKS.index(b.rank) <=> RANKS.index(a.rank)
rank_sort.zero? ? SUITS.index(a.suit) <=> SUITS.index(b.suit) : rank_sort
end
end
def deal
cards = @cards.shift(@cards_to_deal)
hand = get_hand(self.class.name, cards)
end
def to_s
@cards.each(&:to_s)
end
end
class WarDeck < Deck
attr_reader :cards_to_deal
def initialize(cards = nil)
super
@cards_to_deal = 26
end
end
class BeloteDeck < Deck
RANKS = [7, 8, 9, :jack, :queen, :king, 10, :ace]
def initialize(cards = nil)
super
@cards_to_deal = 8
end
end
class SixtySixDeck < Deck
RANKS = [ 9, :jack, :queen, :king, 10, :ace]
def initialize(cards = nil)
super
@cards_to_deal = 6
end
end
class Hand
def initialize(cards)
@cards = cards
end
def size
@cards.length
end
end
class WarHand < Hand
FACE_UP_LIMIT = 3
def play_card
@cards.shift
end
def allow_face_up?
@cards.length <= FACE_UP_LIMIT
end
end
class BeloteHand < Hand
def highest_of_suit(suit)
@cards.select { |card| card.suit == suit}
.sort { |a, b| b.rank <=> a.rank }
.first
end
def belote?
res = @cards.select { |card| card.rank == :queen or card.rank == :king }
.group_by { |card| card.suit }
.any? { |group| group[1].length == 2}
end
def tierce?
has_consecutive(3)
end
def quarte?
has_consecutive(4)
end
def quint?
has_consecutive(5)
end
def carre_of_jacks?
has_carre_of(:jack)
end
def carre_of_nines?
has_carre_of(9)
end
def carre_of_aces?
has_carre_of(:ace)
end
private
def sort_by_rank(cards)
sorted_cards = cards.sort_by do |card|
[ BeloteDeck::SUITS.index(card.suit), BeloteDeck::RANKS.index(card.rank)]
end
end
def has_consecutive(n)
ranks, sorted_cards = BeloteDeck::RANKS, sort_by_rank(@cards)
sorted_cards.slice_when do |current, next_card|
ranks.index(current.rank) + 1 != ranks.index(next_card.rank)
end.any? { |sequence| sequence.length == n }
end
def has_carre_of(rank)
cards_of_rank = @cards.select do |card|
card.rank == rank
end
has_carre = cards_of_rank.length == 4
end
end
class SixtySixHand < Hand
def initialize(cards)
@cards = cards
end
def twenty?(trump_suit)
get_couples_by_suit.any? do |group|
group[1].length == 2 and group[0] != trump_suit
end
end
def forty?(trump_suit)
get_couples_by_suit.any? do |group|
group[1].length == 2 and group[0] == trump_suit
end
end
private
def get_couples_by_suit
couples = @cards.select { |card| card.rank == :queen or card.rank == :king }
.group_by { |card| card.suit }
end
end

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

..F.FF.F...FF....FF.F...FF.F..F.............FF.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:0x007fee2ebfa800 @rank=4, @suit=:spades>
            got: #<Card:0x007fee2ebfa968 @rank=4, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fee2ebfa800 @rank=4, @suit=:spades>
       +#<Card:0x007fee2ebfa968 @rank=4, @suit=:spades>
     # /tmp/d20151112-27349-pedzkr/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:0x007fee2fa43cb8 @rank=2, @suit=:clubs>, #<Card:0x007fee2fa43c90 @rank=3, @suit=:clubs>, #<Card:0x007fee2fa43c68 @rank=4, @suit=:clubs>, #<Card:0x007fee2fa43c40 @rank=5, @suit=:clubs>, #<Card:0x007fee2fa43c18 @rank=6, @suit=:clubs>, #<Card:0x007fee2fa43bf0 @rank=7, @suit=:clubs>, #<Card:0x007fee2fa43bc8 @rank=8, @suit=:clubs>, #<Card:0x007fee2fa43b78 @rank=9, @suit=:clubs>, #<Card:0x007fee2fa43b50 @rank=10, @suit=:clubs>, #<Card:0x007fee2fa43b28 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2fa43b00 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2fa43ad8 @rank=:king, @suit=:clubs>, #<Card:0x007fee2fa43ab0 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2fa43a88 @rank=2, @suit=:diamonds>, #<Card:0x007fee2fa43a60 @rank=3, @suit=:diamonds>, #<Card:0x007fee2fa43a38 @rank=4, @suit=:diamonds>, #<Card:0x007fee2fa43a10 @rank=5, @suit=:diamonds>, #<Card:0x007fee2fa439e8 @rank=6, @suit=:diamonds>, #<Card:0x007fee2fa439c0 @rank=7, @suit=:diamonds>, #<Card:0x007fee2fa43998 @rank=8, @suit=:diamonds>, #<Card:0x007fee2fa43970 @rank=9, @suit=:diamonds>, #<Card:0x007fee2fa43948 @rank=10, @suit=:diamonds>, #<Card:0x007fee2fa43920 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2fa438f8 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2fa438d0 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2fa438a8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2fa43880 @rank=2, @suit=:hearts>, #<Card:0x007fee2fa43858 @rank=3, @suit=:hearts>, #<Card:0x007fee2fa43830 @rank=4, @suit=:hearts>, #<Card:0x007fee2fa43808 @rank=5, @suit=:hearts>, #<Card:0x007fee2fa437e0 @rank=6, @suit=:hearts>, #<Card:0x007fee2fa437b8 @rank=7, @suit=:hearts>, #<Card:0x007fee2fa43790 @rank=8, @suit=:hearts>, #<Card:0x007fee2fa43768 @rank=9, @suit=:hearts>, #<Card:0x007fee2fa43740 @rank=10, @suit=:hearts>, #<Card:0x007fee2fa43718 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2fa436f0 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2fa436c8 @rank=:king, @suit=:hearts>, #<Card:0x007fee2fa436a0 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2fa43678 @rank=2, @suit=:spades>, #<Card:0x007fee2fa43650 @rank=3, @suit=:spades>, #<Card:0x007fee2fa43628 @rank=4, @suit=:spades>, #<Card:0x007fee2fa43600 @rank=5, @suit=:spades>, #<Card:0x007fee2fa435d8 @rank=6, @suit=:spades>, #<Card:0x007fee2fa435b0 @rank=7, @suit=:spades>, #<Card:0x007fee2fa43588 @rank=8, @suit=:spades>, #<Card:0x007fee2fa43560 @rank=9, @suit=:spades>, #<Card:0x007fee2fa43538 @rank=10, @suit=:spades>, #<Card:0x007fee2fa43510 @rank=:jack, @suit=:spades>, #<Card:0x007fee2fa434e8 @rank=:queen, @suit=:spades>, #<Card:0x007fee2fa434c0 @rank=:king, @suit=:spades>, #<Card:0x007fee2fa43498 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fee2f9dd008 @rank=2, @suit=:spades>, #<Card:0x007fee2f9dcfe0 @rank=2, @suit=:hearts>, #<Card:0x007fee2f9dcfb8 @rank=2, @suit=:diamonds>, #<Card:0x007fee2f9dcf90 @rank=2, @suit=:clubs>, #<Card:0x007fee2f9dcf68 @rank=3, @suit=:spades>, #<Card:0x007fee2f9dcf18 @rank=3, @suit=:hearts>, #<Card:0x007fee2f9dcef0 @rank=3, @suit=:diamonds>, #<Card:0x007fee2f9dcec8 @rank=3, @suit=:clubs>, #<Card:0x007fee2f9dcea0 @rank=4, @suit=:spades>, #<Card:0x007fee2f9dce78 @rank=4, @suit=:hearts>, #<Card:0x007fee2f9dce50 @rank=4, @suit=:diamonds>, #<Card:0x007fee2f9dcdd8 @rank=4, @suit=:clubs>, #<Card:0x007fee2f9dcdb0 @rank=5, @suit=:spades>, #<Card:0x007fee2f9dcd88 @rank=5, @suit=:hearts>, #<Card:0x007fee2f9dcd38 @rank=5, @suit=:diamonds>, #<Card:0x007fee2f9dcce8 @rank=5, @suit=:clubs>, #<Card:0x007fee2f9dccc0 @rank=6, @suit=:spades>, #<Card:0x007fee2f9dcc98 @rank=6, @suit=:hearts>, #<Card:0x007fee2f9dcc70 @rank=6, @suit=:diamonds>, #<Card:0x007fee2f9dcc48 @rank=6, @suit=:clubs>, #<Card:0x007fee2f9dcc20 @rank=7, @suit=:spades>, #<Card:0x007fee2f9dcbd0 @rank=7, @suit=:hearts>, #<Card:0x007fee2f9dcba8 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f9dcb80 @rank=7, @suit=:clubs>, #<Card:0x007fee2f9dcb58 @rank=8, @suit=:spades>, #<Card:0x007fee2f9dcb30 @rank=8, @suit=:hearts>, #<Card:0x007fee2f9dcb08 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f9dcae0 @rank=8, @suit=:clubs>, #<Card:0x007fee2f9dca90 @rank=9, @suit=:spades>, #<Card:0x007fee2f9dca68 @rank=9, @suit=:hearts>, #<Card:0x007fee2f9dca40 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f9dca18 @rank=9, @suit=:clubs>, #<Card:0x007fee2f9dc9f0 @rank=10, @suit=:spades>, #<Card:0x007fee2f9dc9c8 @rank=10, @suit=:hearts>, #<Card:0x007fee2f9dc978 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f9dc950 @rank=10, @suit=:clubs>, #<Card:0x007fee2f9dc928 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f9dc900 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f9dc8d8 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f9dc8b0 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f9dc860 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f9dc838 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f9dc810 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f9dc7e8 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f9dc7c0 @rank=:king, @suit=:spades>, #<Card:0x007fee2f9dc798 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f9dc770 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f9dc720 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f9dc6f8 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f9dc6a8 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f9dc680 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f9dc658 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fee2fa43cb8 @rank=2, @suit=:clubs>, #<Card:0x007fee2fa43c90 @rank=3, @suit=:clubs>, #<Card:0x007fee2fa43c68 @rank=4, @suit=:clubs>, #<Card:0x007fee2fa43c40 @rank=5, @suit=:clubs>, #<Card:0x007fee2fa43c18 @rank=6, @suit=:clubs>, #<Card:0x007fee2fa43bf0 @rank=7, @suit=:clubs>, #<Card:0x007fee2fa43bc8 @rank=8, @suit=:clubs>, #<Card:0x007fee2fa43b78 @rank=9, @suit=:clubs>, #<Card:0x007fee2fa43b50 @rank=10, @suit=:clubs>, #<Card:0x007fee2fa43b28 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2fa43b00 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2fa43ad8 @rank=:king, @suit=:clubs>, #<Card:0x007fee2fa43ab0 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2fa43a88 @rank=2, @suit=:diamonds>, #<Card:0x007fee2fa43a60 @rank=3, @suit=:diamonds>, #<Card:0x007fee2fa43a38 @rank=4, @suit=:diamonds>, #<Card:0x007fee2fa43a10 @rank=5, @suit=:diamonds>, #<Card:0x007fee2fa439e8 @rank=6, @suit=:diamonds>, #<Card:0x007fee2fa439c0 @rank=7, @suit=:diamonds>, #<Card:0x007fee2fa43998 @rank=8, @suit=:diamonds>, #<Card:0x007fee2fa43970 @rank=9, @suit=:diamonds>, #<Card:0x007fee2fa43948 @rank=10, @suit=:diamonds>, #<Card:0x007fee2fa43920 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2fa438f8 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2fa438d0 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2fa438a8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2fa43880 @rank=2, @suit=:hearts>, #<Card:0x007fee2fa43858 @rank=3, @suit=:hearts>, #<Card:0x007fee2fa43830 @rank=4, @suit=:hearts>, #<Card:0x007fee2fa43808 @rank=5, @suit=:hearts>, #<Card:0x007fee2fa437e0 @rank=6, @suit=:hearts>, #<Card:0x007fee2fa437b8 @rank=7, @suit=:hearts>, #<Card:0x007fee2fa43790 @rank=8, @suit=:hearts>, #<Card:0x007fee2fa43768 @rank=9, @suit=:hearts>, #<Card:0x007fee2fa43740 @rank=10, @suit=:hearts>, #<Card:0x007fee2fa43718 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2fa436f0 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2fa436c8 @rank=:king, @suit=:hearts>, #<Card:0x007fee2fa436a0 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2fa43678 @rank=2, @suit=:spades>, #<Card:0x007fee2fa43650 @rank=3, @suit=:spades>, #<Card:0x007fee2fa43628 @rank=4, @suit=:spades>, #<Card:0x007fee2fa43600 @rank=5, @suit=:spades>, #<Card:0x007fee2fa435d8 @rank=6, @suit=:spades>, #<Card:0x007fee2fa435b0 @rank=7, @suit=:spades>, #<Card:0x007fee2fa43588 @rank=8, @suit=:spades>, #<Card:0x007fee2fa43560 @rank=9, @suit=:spades>, #<Card:0x007fee2fa43538 @rank=10, @suit=:spades>, #<Card:0x007fee2fa43510 @rank=:jack, @suit=:spades>, #<Card:0x007fee2fa434e8 @rank=:queen, @suit=:spades>, #<Card:0x007fee2fa434c0 @rank=:king, @suit=:spades>, #<Card:0x007fee2fa43498 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fee2f9dd008 @rank=2, @suit=:spades>, #<Card:0x007fee2f9dcfe0 @rank=2, @suit=:hearts>, #<Card:0x007fee2f9dcfb8 @rank=2, @suit=:diamonds>, #<Card:0x007fee2f9dcf90 @rank=2, @suit=:clubs>, #<Card:0x007fee2f9dcf68 @rank=3, @suit=:spades>, #<Card:0x007fee2f9dcf18 @rank=3, @suit=:hearts>, #<Card:0x007fee2f9dcef0 @rank=3, @suit=:diamonds>, #<Card:0x007fee2f9dcec8 @rank=3, @suit=:clubs>, #<Card:0x007fee2f9dcea0 @rank=4, @suit=:spades>, #<Card:0x007fee2f9dce78 @rank=4, @suit=:hearts>, #<Card:0x007fee2f9dce50 @rank=4, @suit=:diamonds>, #<Card:0x007fee2f9dcdd8 @rank=4, @suit=:clubs>, #<Card:0x007fee2f9dcdb0 @rank=5, @suit=:spades>, #<Card:0x007fee2f9dcd88 @rank=5, @suit=:hearts>, #<Card:0x007fee2f9dcd38 @rank=5, @suit=:diamonds>, #<Card:0x007fee2f9dcce8 @rank=5, @suit=:clubs>, #<Card:0x007fee2f9dccc0 @rank=6, @suit=:spades>, #<Card:0x007fee2f9dcc98 @rank=6, @suit=:hearts>, #<Card:0x007fee2f9dcc70 @rank=6, @suit=:diamonds>, #<Card:0x007fee2f9dcc48 @rank=6, @suit=:clubs>, #<Card:0x007fee2f9dcc20 @rank=7, @suit=:spades>, #<Card:0x007fee2f9dcbd0 @rank=7, @suit=:hearts>, #<Card:0x007fee2f9dcba8 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f9dcb80 @rank=7, @suit=:clubs>, #<Card:0x007fee2f9dcb58 @rank=8, @suit=:spades>, #<Card:0x007fee2f9dcb30 @rank=8, @suit=:hearts>, #<Card:0x007fee2f9dcb08 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f9dcae0 @rank=8, @suit=:clubs>, #<Card:0x007fee2f9dca90 @rank=9, @suit=:spades>, #<Card:0x007fee2f9dca68 @rank=9, @suit=:hearts>, #<Card:0x007fee2f9dca40 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f9dca18 @rank=9, @suit=:clubs>, #<Card:0x007fee2f9dc9f0 @rank=10, @suit=:spades>, #<Card:0x007fee2f9dc9c8 @rank=10, @suit=:hearts>, #<Card:0x007fee2f9dc978 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f9dc950 @rank=10, @suit=:clubs>, #<Card:0x007fee2f9dc928 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f9dc900 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f9dc8d8 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f9dc8b0 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f9dc860 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f9dc838 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f9dc810 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f9dc7e8 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f9dc7c0 @rank=:king, @suit=:spades>, #<Card:0x007fee2f9dc798 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f9dc770 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f9dc720 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f9dc6f8 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f9dc6a8 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f9dc680 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f9dc658 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:140
     # /tmp/d20151112-27349-pedzkr/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 #size returns the size of the deck
     Failure/Error: expect(small_deck.size).to eq 2
       
       expected: 2
            got: 52
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:140
     # /tmp/d20151112-27349-pedzkr/spec.rb:23: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 #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fee2f97e170 @rank=9, @suit=:clubs>
            got: #<Card:0x007fee2f97e198 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fee2f97e170 @rank=9, @suit=:clubs>
       +#<Card:0x007fee2f97e198 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:140
     # /tmp/d20151112-27349-pedzkr/spec.rb:36: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) WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: expect(small_deck.to_s.strip).to eq "Ace of Spades\n9 of Clubs"
     NoMethodError:
       undefined method `strip' for #<Array:0x007fee2fa3fe88>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:140
     # /tmp/d20151112-27349-pedzkr/spec.rb:68: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)>'

  6) WarDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, two_of_clubs]
       
       expected: [#<Card:0x007fee2fa3d7c8 @rank=:jack, @suit=:spades>, #<Card:0x007fee2fa3d778 @rank=10, @suit=:hearts>, #<Card:0x007fee2fa3d7f0 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2fa3d7a0 @rank=2, @suit=:clubs>]
            got: [#<Card:0x007fee2fa3d7f0 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2fa3d7c8 @rank=:jack, @suit=:spades>, #<Card:0x007fee2fa3d778 @rank=10, @suit=:hearts>, #<Card:0x007fee2fa3d7a0 @rank=2, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,5 +1,5 @@
       -[#<Card:0x007fee2fa3d7c8 @rank=:jack, @suit=:spades>,
       +[#<Card:0x007fee2fa3d7f0 @rank=:ace, @suit=:clubs>,
       + #<Card:0x007fee2fa3d7c8 @rank=:jack, @suit=:spades>,
         #<Card:0x007fee2fa3d778 @rank=10, @suit=:hearts>,
       - #<Card:0x007fee2fa3d7f0 @rank=:ace, @suit=:clubs>,
         #<Card:0x007fee2fa3d7a0 @rank=2, @suit=:clubs>]
     # /tmp/d20151112-27349-pedzkr/spec.rb:155: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 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:0x007fee2f988058 @rank=7, @suit=:clubs>, #<Card:0x007fee2f98bac8 @rank=8, @suit=:clubs>, #<Card:0x007fee2f96acd8 @rank=9, @suit=:clubs>, #<Card:0x007fee2f96acb0 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f96ac10 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f96abe8 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f96ab98 @rank=10, @suit=:clubs>, #<Card:0x007fee2f96ab70 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f96aaf8 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f96aad0 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f96aa80 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f96aa58 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f96aa30 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f96aa08 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f96a9b8 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f96a990 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f96a8f0 @rank=7, @suit=:hearts>, #<Card:0x007fee2f96a8a0 @rank=8, @suit=:hearts>, #<Card:0x007fee2f96a878 @rank=9, @suit=:hearts>, #<Card:0x007fee2f96a800 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f96a7d8 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f96a788 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f96a6e8 @rank=10, @suit=:hearts>, #<Card:0x007fee2f96a6c0 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f96a698 @rank=7, @suit=:spades>, #<Card:0x007fee2f96a648 @rank=8, @suit=:spades>, #<Card:0x007fee2f96a620 @rank=9, @suit=:spades>, #<Card:0x007fee2f96a5a8 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f96a580 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f96a530 @rank=:king, @suit=:spades>, #<Card:0x007fee2f96a508 @rank=10, @suit=:spades>, #<Card:0x007fee2f96a4e0 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fee2f98afb0 @rank=7, @suit=:spades>, #<Card:0x007fee2f98af88 @rank=7, @suit=:hearts>, #<Card:0x007fee2f98af60 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f98af38 @rank=7, @suit=:clubs>, #<Card:0x007fee2f98af10 @rank=8, @suit=:spades>, #<Card:0x007fee2f98aee8 @rank=8, @suit=:hearts>, #<Card:0x007fee2f98aec0 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f98ae98 @rank=8, @suit=:clubs>, #<Card:0x007fee2f98ae70 @rank=9, @suit=:spades>, #<Card:0x007fee2f98ae48 @rank=9, @suit=:hearts>, #<Card:0x007fee2f98ae20 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f98adf8 @rank=9, @suit=:clubs>, #<Card:0x007fee2f98add0 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f98ada8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f98ad80 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f98a970 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f98a790 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f989390 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f989318 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f9892c8 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f989250 @rank=:king, @suit=:spades>, #<Card:0x007fee2f989228 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f9891b0 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f989188 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f989160 @rank=10, @suit=:spades>, #<Card:0x007fee2f989110 @rank=10, @suit=:hearts>, #<Card:0x007fee2f989048 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f988fd0 @rank=10, @suit=:clubs>, #<Card:0x007fee2f988fa8 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f988f30 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f988eb8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f988e90 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fee2f988058 @rank=7, @suit=:clubs>, #<Card:0x007fee2f98bac8 @rank=8, @suit=:clubs>, #<Card:0x007fee2f96acd8 @rank=9, @suit=:clubs>, #<Card:0x007fee2f96acb0 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f96ac10 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f96abe8 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f96ab98 @rank=10, @suit=:clubs>, #<Card:0x007fee2f96ab70 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f96aaf8 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f96aad0 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f96aa80 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f96aa58 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f96aa30 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f96aa08 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f96a9b8 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f96a990 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f96a8f0 @rank=7, @suit=:hearts>, #<Card:0x007fee2f96a8a0 @rank=8, @suit=:hearts>, #<Card:0x007fee2f96a878 @rank=9, @suit=:hearts>, #<Card:0x007fee2f96a800 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f96a7d8 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f96a788 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f96a6e8 @rank=10, @suit=:hearts>, #<Card:0x007fee2f96a6c0 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f96a698 @rank=7, @suit=:spades>, #<Card:0x007fee2f96a648 @rank=8, @suit=:spades>, #<Card:0x007fee2f96a620 @rank=9, @suit=:spades>, #<Card:0x007fee2f96a5a8 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f96a580 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f96a530 @rank=:king, @suit=:spades>, #<Card:0x007fee2f96a508 @rank=10, @suit=:spades>, #<Card:0x007fee2f96a4e0 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fee2f98afb0 @rank=7, @suit=:spades>, #<Card:0x007fee2f98af88 @rank=7, @suit=:hearts>, #<Card:0x007fee2f98af60 @rank=7, @suit=:diamonds>, #<Card:0x007fee2f98af38 @rank=7, @suit=:clubs>, #<Card:0x007fee2f98af10 @rank=8, @suit=:spades>, #<Card:0x007fee2f98aee8 @rank=8, @suit=:hearts>, #<Card:0x007fee2f98aec0 @rank=8, @suit=:diamonds>, #<Card:0x007fee2f98ae98 @rank=8, @suit=:clubs>, #<Card:0x007fee2f98ae70 @rank=9, @suit=:spades>, #<Card:0x007fee2f98ae48 @rank=9, @suit=:hearts>, #<Card:0x007fee2f98ae20 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f98adf8 @rank=9, @suit=:clubs>, #<Card:0x007fee2f98add0 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f98ada8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f98ad80 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f98a970 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f98a790 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f989390 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f989318 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f9892c8 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f989250 @rank=:king, @suit=:spades>, #<Card:0x007fee2f989228 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f9891b0 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f989188 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f989160 @rank=10, @suit=:spades>, #<Card:0x007fee2f989110 @rank=10, @suit=:hearts>, #<Card:0x007fee2f989048 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f988fd0 @rank=10, @suit=:clubs>, #<Card:0x007fee2f988fa8 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f988f30 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f988eb8 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f988e90 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:191
     # /tmp/d20151112-27349-pedzkr/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)>'

  8) BeloteDeck behaves like a deck #size returns the size of the deck
     Failure/Error: expect(small_deck.size).to eq 2
       
       expected: 2
            got: 32
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:191
     # /tmp/d20151112-27349-pedzkr/spec.rb:23: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)>'

  9) BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fee2f90d808 @rank=9, @suit=:clubs>
            got: #<Card:0x007fee2f90d830 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fee2f90d808 @rank=9, @suit=:clubs>
       +#<Card:0x007fee2f90d830 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:191
     # /tmp/d20151112-27349-pedzkr/spec.rb:36: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)>'

  10) BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: expect(small_deck.to_s.strip).to eq "Ace of Spades\n9 of Clubs"
     NoMethodError:
       undefined method `strip' for #<Array:0x007fee2f8b9cd0>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:191
     # /tmp/d20151112-27349-pedzkr/spec.rb:68: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) BeloteDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, seven_of_clubs]
       
       expected: [#<Card:0x007fee2f8a9b78 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f8a9b28 @rank=10, @suit=:hearts>, #<Card:0x007fee2f8a9c18 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f8a9b50 @rank=7, @suit=:clubs>]
            got: [#<Card:0x007fee2f8a9c18 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f8a9b78 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f8a9b28 @rank=10, @suit=:hearts>, #<Card:0x007fee2f8a9b50 @rank=7, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,5 +1,5 @@
       -[#<Card:0x007fee2f8a9b78 @rank=:jack, @suit=:spades>,
       +[#<Card:0x007fee2f8a9c18 @rank=:ace, @suit=:clubs>,
       + #<Card:0x007fee2f8a9b78 @rank=:jack, @suit=:spades>,
         #<Card:0x007fee2f8a9b28 @rank=10, @suit=:hearts>,
       - #<Card:0x007fee2f8a9c18 @rank=:ace, @suit=:clubs>,
         #<Card:0x007fee2f8a9b50 @rank=7, @suit=:clubs>]
     # /tmp/d20151112-27349-pedzkr/spec.rb:206: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)>'

  12) 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)
     ArgumentError:
       comparison of Card with Card failed
     # /tmp/d20151112-27349-pedzkr/solution.rb:129:in `sort'
     # /tmp/d20151112-27349-pedzkr/solution.rb:129:in `highest_of_suit'
     # /tmp/d20151112-27349-pedzkr/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)>'

  13) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: expect(hand.tierce?).to be true
       
       expected #<TrueClass:20> => true
            got #<FalseClass:0> => false
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       `expect(actual).to eq(expected)` if you don't care about
       object identity in this example.
     # /tmp/d20151112-27349-pedzkr/spec.rb:284:in `block (5 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)>'

  14) 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:0x007fee2f43d3a0 @rank=9, @suit=:clubs>, #<Card:0x007fee2f43d378 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f43d328 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f43d2b0 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f43d238 @rank=10, @suit=:clubs>, #<Card:0x007fee2f43d210 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f43d170 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f43d0d0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f43d0a8 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f43d080 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f43d030 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f43d008 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f43cfe0 @rank=9, @suit=:hearts>, #<Card:0x007fee2f43cfb8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f43ce50 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f43cdd8 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f43cd88 @rank=10, @suit=:hearts>, #<Card:0x007fee2f43cd10 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f43cce8 @rank=9, @suit=:spades>, #<Card:0x007fee2f43cc48 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f43cbd0 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f43cb80 @rank=:king, @suit=:spades>, #<Card:0x007fee2f43cae0 @rank=10, @suit=:spades>, #<Card:0x007fee2f43ca90 @rank=:ace, @suit=:spades>]
       actual collection contained:    [#<Card:0x007fee2f43e430 @rank=9, @suit=:spades>, #<Card:0x007fee2f43e408 @rank=9, @suit=:hearts>, #<Card:0x007fee2f43e368 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f43e340 @rank=9, @suit=:clubs>, #<Card:0x007fee2f43e318 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f43e2c8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f43e2a0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f43e278 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f43e250 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f43e200 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f43e1b0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f43e188 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f43e160 @rank=:king, @suit=:spades>, #<Card:0x007fee2f43e138 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f43e0e8 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f43e0c0 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f43e098 @rank=10, @suit=:spades>, #<Card:0x007fee2f43e020 @rank=10, @suit=:hearts>, #<Card:0x007fee2f43dff8 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f43dfd0 @rank=10, @suit=:clubs>, #<Card:0x007fee2f43df58 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f43df30 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f43df08 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f43de90 @rank=:ace, @suit=:clubs>]
       the missing elements were:      [#<Card:0x007fee2f43d3a0 @rank=9, @suit=:clubs>, #<Card:0x007fee2f43d378 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f43d328 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f43d2b0 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f43d238 @rank=10, @suit=:clubs>, #<Card:0x007fee2f43d210 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2f43d170 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f43d0d0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f43d0a8 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f43d080 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f43d030 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f43d008 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f43cfe0 @rank=9, @suit=:hearts>, #<Card:0x007fee2f43cfb8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f43ce50 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f43cdd8 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f43cd88 @rank=10, @suit=:hearts>, #<Card:0x007fee2f43cd10 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f43cce8 @rank=9, @suit=:spades>, #<Card:0x007fee2f43cc48 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f43cbd0 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f43cb80 @rank=:king, @suit=:spades>, #<Card:0x007fee2f43cae0 @rank=10, @suit=:spades>, #<Card:0x007fee2f43ca90 @rank=:ace, @suit=:spades>]
       the extra elements were:        [#<Card:0x007fee2f43e430 @rank=9, @suit=:spades>, #<Card:0x007fee2f43e408 @rank=9, @suit=:hearts>, #<Card:0x007fee2f43e368 @rank=9, @suit=:diamonds>, #<Card:0x007fee2f43e340 @rank=9, @suit=:clubs>, #<Card:0x007fee2f43e318 @rank=:jack, @suit=:spades>, #<Card:0x007fee2f43e2c8 @rank=:jack, @suit=:hearts>, #<Card:0x007fee2f43e2a0 @rank=:jack, @suit=:diamonds>, #<Card:0x007fee2f43e278 @rank=:jack, @suit=:clubs>, #<Card:0x007fee2f43e250 @rank=:queen, @suit=:spades>, #<Card:0x007fee2f43e200 @rank=:queen, @suit=:hearts>, #<Card:0x007fee2f43e1b0 @rank=:queen, @suit=:diamonds>, #<Card:0x007fee2f43e188 @rank=:queen, @suit=:clubs>, #<Card:0x007fee2f43e160 @rank=:king, @suit=:spades>, #<Card:0x007fee2f43e138 @rank=:king, @suit=:hearts>, #<Card:0x007fee2f43e0e8 @rank=:king, @suit=:diamonds>, #<Card:0x007fee2f43e0c0 @rank=:king, @suit=:clubs>, #<Card:0x007fee2f43e098 @rank=10, @suit=:spades>, #<Card:0x007fee2f43e020 @rank=10, @suit=:hearts>, #<Card:0x007fee2f43dff8 @rank=10, @suit=:diamonds>, #<Card:0x007fee2f43dfd0 @rank=10, @suit=:clubs>, #<Card:0x007fee2f43df58 @rank=:ace, @suit=:spades>, #<Card:0x007fee2f43df30 @rank=:ace, @suit=:hearts>, #<Card:0x007fee2f43df08 @rank=:ace, @suit=:diamonds>, #<Card:0x007fee2f43de90 @rank=:ace, @suit=:clubs>]
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:400
     # /tmp/d20151112-27349-pedzkr/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)>'

  15) SixtySixDeck behaves like a deck #size returns the size of the deck
     Failure/Error: expect(small_deck.size).to eq 2
       
       expected: 2
            got: 24
       
       (compared using ==)
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:400
     # /tmp/d20151112-27349-pedzkr/spec.rb:23: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)>'

  16) SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
       
       expected: #<Card:0x007fee2f3a95d8 @rank=9, @suit=:clubs>
            got: #<Card:0x007fee2f3a9600 @rank=:ace, @suit=:spades>
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Card:0x007fee2f3a95d8 @rank=9, @suit=:clubs>
       +#<Card:0x007fee2f3a9600 @rank=:ace, @suit=:spades>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:400
     # /tmp/d20151112-27349-pedzkr/spec.rb:36: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)>'

  17) SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: expect(small_deck.to_s.strip).to eq "Ace of Spades\n9 of Clubs"
     NoMethodError:
       undefined method `strip' for #<Array:0x007fee2edeaf70>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-pedzkr/spec.rb:400
     # /tmp/d20151112-27349-pedzkr/spec.rb:68: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)>'

  18) SixtySixDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, two_of_clubs]
       
       expected: [#<Card:0x007fee2edc04f0 @rank=:jack, @suit=:spades>, #<Card:0x007fee2edc04a0 @rank=10, @suit=:hearts>, #<Card:0x007fee2edc0518 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2edc04c8 @rank=9, @suit=:clubs>]
            got: [#<Card:0x007fee2edc0518 @rank=:ace, @suit=:clubs>, #<Card:0x007fee2edc04f0 @rank=:jack, @suit=:spades>, #<Card:0x007fee2edc04a0 @rank=10, @suit=:hearts>, #<Card:0x007fee2edc04c8 @rank=9, @suit=:clubs>]
       
       (compared using ==)
       
       Diff:
       
       @@ -1,5 +1,5 @@
       -[#<Card:0x007fee2edc04f0 @rank=:jack, @suit=:spades>,
       +[#<Card:0x007fee2edc0518 @rank=:ace, @suit=:clubs>,
       + #<Card:0x007fee2edc04f0 @rank=:jack, @suit=:spades>,
         #<Card:0x007fee2edc04a0 @rank=10, @suit=:hearts>,
       - #<Card:0x007fee2edc0518 @rank=:ace, @suit=:clubs>,
         #<Card:0x007fee2edc04c8 @rank=9, @suit=:clubs>]
     # /tmp/d20151112-27349-pedzkr/spec.rb:415: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.05248 seconds
57 examples, 18 failures

Failed examples:

rspec /tmp/d20151112-27349-pedzkr/spec.rb:130 # Card #== compares two cards by their rank and suit
rspec /tmp/d20151112-27349-pedzkr/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-pedzkr/spec.rb:22 # WarDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-pedzkr/spec.rb:35 # WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-pedzkr/spec.rb:67 # WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-pedzkr/spec.rb:145 # WarDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-pedzkr/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-pedzkr/spec.rb:22 # BeloteDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-pedzkr/spec.rb:35 # BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-pedzkr/spec.rb:67 # BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-pedzkr/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-pedzkr/spec.rb:220 # BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
rspec /tmp/d20151112-27349-pedzkr/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-pedzkr/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-pedzkr/spec.rb:22 # SixtySixDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-pedzkr/spec.rb:35 # SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-pedzkr/spec.rb:67 # SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-pedzkr/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order

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

Милена обнови решението на 10.11.2015 22:32 (преди около 9 години)

+module HandFactory
+ def get_hand(deck_name, *args)
+ return WarHand.new(*args) if deck_name == 'WarDeck'
+ return BeloteHand.new(*args) if deck_name == 'BeloteDeck'
+ return SixtySixHand.new(*args) if deck_name == 'SixtySixDeck'
+ end
+end
+
+class Card
+ attr_reader :rank, :suit
+
+ def initialize(rank, suit)
+ @rank = rank
+ @suit = suit
+ end
+
+ def to_s
+ return "#{@rank.to_s.capitalize} of #{@suit.to_s.capitalize}"
+ end
+end
+
+class Deck
+ include Enumerable
+ include HandFactory
+
+ RANKS = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace]
+ SUITS = [:spades, :hearts, :diamonds, :clubs]
+
+ def initialize(cards = nil)
+ @cards = cards || self.class::RANKS.product(SUITS)
+ .map { |card_parameters| Card.new(card_parameters[0],card_parameters[1]) }
+ end
+
+ def each(&block)
+ @cards.each { |rank| block.call(rank) }
+ end
+
+ def size
+ size = self.class::RANKS.length * SUITS.length
+ end
+
+ def draw_top_card
+ top_card = @cards.shift
+ end
+
+ def draw_bottom_card
+ bottom_card = @cards.shift
+ end
+
+ def top_card
+ top_card = @cards[0]
+ end
+
+ def bottom_card
+ bottom_card = @cards[-1]
+ end
+
+ def shuffle
+ @cards.shuffle!
+ end
+
+ def sort
+ @cards.sort! do |a, b|
+ rank_sort = RANKS.index(b.rank) <=> RANKS.index(a.rank)
+ rank_sort.zero? ? SUITS.index(a.suit) <=> SUITS.index(b.suit) : rank_sort
+ end
+ end
+
+ def deal
+ cards = @cards.shift(@cards_to_deal)
+ hand = get_hand(self.class.name, cards)
+ end
+
+ def to_s
+ @cards.each(&:to_s)
+ end
+end
+
+class WarDeck < Deck
+ attr_reader :cards_to_deal
+
+ def initialize(cards = nil)
+ super
+ @cards_to_deal = 26
+ end
+end
+
+class BeloteDeck < Deck
+ RANKS = [7, 8, 9, :jack, :queen, :king, 10, :ace]
+ def initialize(cards = nil)
+ super
+ @cards_to_deal = 8
+ end
+end
+
+class Hand
+ def initialize(cards)
+ @cards = cards
+ end
+
+ def size
+ @cards.length
+ end
+end
+
+class WarHand < Hand
+ FACE_UP_LIMIT = 3
+
+ def play_card
+ @cards.shift
+ end
+
+ def allow_face_up?
+ @cards.length <= FACE_UP_LIMIT
+ end
+end
+
+class BeloteHand < Hand
+ def highest_of_suit(suit)
+ @cards.select { |card| card.suit == suit}
+ .sort { |a, b| b.rank <=> a.rank }
+ .first
+ end
+
+ def belote?
+ res = @cards.select { |card| card.rank == :queen or card.rank == :king }
+ .group_by { |card| card.suit }
+ .any? { |group| group[1].length == 2}
+ end
+
+ def tierce?
+ has_consecutive(3)
+ end
+
+ def quarte?
+ has_consecutive(4)
+ end
+
+ def quint?
+ has_consecutive(5)
+ end
+
+ def carre_of_jacks?
+ has_carre_of(:jack)
+ end
+
+ def carre_of_nines?
+ has_carre_of(9)
+ end
+
+ def carre_of_aces?
+ has_carre_of(:ace)
+ end
+
+ private
+
+ def sort_by_rank(cards)
+ sorted_cards = cards.sort_by do |card|
+ [ BeloteDeck::SUITS.index(card.suit), BeloteDeck::RANKS.index(card.rank)]
+ end
+ end
+
+ def has_consecutive(n)
+ ranks, sorted_cards = BeloteDeck::RANKS, sort_by_rank(@cards)
+
+ sorted_cards.slice_when do |current, next_card|
+ ranks.index(current.rank) + 1 != ranks.index(next_card.rank)
+ end.any? { |sequence| sequence.length == n }
+ end
+
+ def has_carre_of(rank)
+ cards_of_rank = @cards.select do |card|
+ card.rank == rank
+ end
+
+ has_carre = cards_of_rank.length == 4
+ end
+end

Милена обнови решението на 10.11.2015 23:06 (преди около 9 години)

module HandFactory
def get_hand(deck_name, *args)
return WarHand.new(*args) if deck_name == 'WarDeck'
return BeloteHand.new(*args) if deck_name == 'BeloteDeck'
return SixtySixHand.new(*args) if deck_name == 'SixtySixDeck'
end
end
class Card
attr_reader :rank, :suit
def initialize(rank, suit)
@rank = rank
@suit = suit
end
def to_s
return "#{@rank.to_s.capitalize} of #{@suit.to_s.capitalize}"
end
end
class Deck
include Enumerable
include HandFactory
RANKS = [2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king, :ace]
SUITS = [:spades, :hearts, :diamonds, :clubs]
def initialize(cards = nil)
@cards = cards || self.class::RANKS.product(SUITS)
.map { |card_parameters| Card.new(card_parameters[0],card_parameters[1]) }
end
def each(&block)
@cards.each { |rank| block.call(rank) }
end
def size
size = self.class::RANKS.length * SUITS.length
end
def draw_top_card
top_card = @cards.shift
end
def draw_bottom_card
bottom_card = @cards.shift
end
def top_card
top_card = @cards[0]
end
def bottom_card
bottom_card = @cards[-1]
end
def shuffle
@cards.shuffle!
end
def sort
@cards.sort! do |a, b|
rank_sort = RANKS.index(b.rank) <=> RANKS.index(a.rank)
rank_sort.zero? ? SUITS.index(a.suit) <=> SUITS.index(b.suit) : rank_sort
end
end
def deal
cards = @cards.shift(@cards_to_deal)
hand = get_hand(self.class.name, cards)
end
def to_s
@cards.each(&:to_s)
end
end
class WarDeck < Deck
attr_reader :cards_to_deal
def initialize(cards = nil)
super
@cards_to_deal = 26
end
end
class BeloteDeck < Deck
RANKS = [7, 8, 9, :jack, :queen, :king, 10, :ace]
- def initialize(cards = nil)
- super
- @cards_to_deal = 8
+ def initialize(cards = nil)
+ super
+ @cards_to_deal = 8
end
end
+class SixtySixDeck < Deck
+ RANKS = [ 9, :jack, :queen, :king, 10, :ace]
+ def initialize(cards = nil)
+ super
+ @cards_to_deal = 6
+ end
+end
+
class Hand
def initialize(cards)
@cards = cards
end
def size
@cards.length
end
end
class WarHand < Hand
FACE_UP_LIMIT = 3
def play_card
@cards.shift
end
def allow_face_up?
@cards.length <= FACE_UP_LIMIT
end
end
class BeloteHand < Hand
def highest_of_suit(suit)
@cards.select { |card| card.suit == suit}
.sort { |a, b| b.rank <=> a.rank }
.first
end
def belote?
res = @cards.select { |card| card.rank == :queen or card.rank == :king }
.group_by { |card| card.suit }
.any? { |group| group[1].length == 2}
end
def tierce?
has_consecutive(3)
end
def quarte?
has_consecutive(4)
end
def quint?
has_consecutive(5)
end
def carre_of_jacks?
has_carre_of(:jack)
end
def carre_of_nines?
has_carre_of(9)
end
def carre_of_aces?
has_carre_of(:ace)
end
private
def sort_by_rank(cards)
sorted_cards = cards.sort_by do |card|
[ BeloteDeck::SUITS.index(card.suit), BeloteDeck::RANKS.index(card.rank)]
end
end
def has_consecutive(n)
ranks, sorted_cards = BeloteDeck::RANKS, sort_by_rank(@cards)
sorted_cards.slice_when do |current, next_card|
ranks.index(current.rank) + 1 != ranks.index(next_card.rank)
end.any? { |sequence| sequence.length == n }
end
def has_carre_of(rank)
cards_of_rank = @cards.select do |card|
card.rank == rank
end
has_carre = cards_of_rank.length == 4
+ end
+end
+
+class SixtySixHand < Hand
+ def initialize(cards)
+ @cards = cards
+ end
+
+ def twenty?(trump_suit)
+ get_couples_by_suit.any? do |group|
+ group[1].length == 2 and group[0] != trump_suit
+ end
+ end
+
+ def forty?(trump_suit)
+ get_couples_by_suit.any? do |group|
+ group[1].length == 2 and group[0] == trump_suit
+ end
+ end
+
+ private
+
+ def get_couples_by_suit
+ couples = @cards.select { |card| card.rank == :queen or card.rank == :king }
+ .group_by { |card| card.suit }
end
end

Милена,

  • от локалните променливи и присвояванията на ред 43 (и сродни) няма смисъл
  • на места форматирането на кода ти е малко странно

Прегледай решенията на колеги и нашето примерно решение за алтернативни идеи.