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

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

Към профила на Денислав Първанов

Резултати

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

Код

class Card
def initialize(suit, rank)
@suit = suit
@rank = rank
end
def rank
@rank
end
def suit
@suit
end
def to_s
rank.to_s.capitalize + " of " + suit.to_s.capitalize
end
def ==(card)
rank == card.rank && suit == card.suit
end
end
class Game
@@suits = %w{spades hearts clubs diamonds}
def initialize(cards = [])
@cards = cards
@ranks = %w{2 3 4 5 6 7 8 9 10 jack queen king ace}
end
def size
@cards.length
end
def draw_top_card
@cards.shift
end
def draw_bottom_car
@cards.pop
end
def top_card
@cards.first
end
def bottom_card
@card.last
end
def shuffle
@card.shuffle!
end
def sort
end
def to_s
@cards.each do |card|
card.to_s + "\n"
end
end
def generate_all_cards
@@suits.each { |suit| @ranks.each { |rank| @cards << Card.new(suit, rank) }}
end
end
class WarDeck < Game
def initialize(cards = [])
@cards = cards
@ranks = %w{2 3 4 5 6 7 8 9 10 jack queen king ace}
generate_all_cards if(cards.empty?)
end
end
class BeloteDeck < Game
def initialize(cards = [])
@cards = cards
@ranks = %w{7 8 9 10 jack queen king 10 ace}
generate_all_cards if(cards.empty?)
end
end
class SixtySixDeck < Game
def initialize(cards = [])
@cards = cards
@ranks = %w{9 jack queen king 10 ace}
generate_all_cards if(cards.empty?)
end
end

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

FF.FF.FFFFFFFFFFFF.FFFFFFFFFFFFFFFFFFFFFFFFFF.FFFFFFFFFFF

Failures:

  1) Card #to_s stringifies and capitalizes the rank and suit
     Failure/Error: expect(all_cards.map(&:to_s)).to eq all_card_names
       
       expected: ["2 of Clubs", "3 of Clubs", "4 of Clubs", "5 of Clubs", "6 of Clubs", "7 of Clubs", "8 of Clubs", "9 of Clubs", "10 of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs", "Ace of Clubs", "2 of Diamonds", "3 of Diamonds", "4 of Diamonds", "5 of Diamonds", "6 of Diamonds", "7 of Diamonds", "8 of Diamonds", "9 of Diamonds", "10 of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds", "Ace of Diamonds", "2 of Hearts", "3 of Hearts", "4 of Hearts", "5 of Hearts", "6 of Hearts", "7 of Hearts", "8 of Hearts", "9 of Hearts", "10 of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts", "Ace of Hearts", "2 of Spades", "3 of Spades", "4 of Spades", "5 of Spades", "6 of Spades", "7 of Spades", "8 of Spades", "9 of Spades", "10 of Spades", "Jack of Spades", "Queen of Spades", "King of Spades", "Ace of Spades"]
            got: ["Clubs of 2", "Clubs of 3", "Clubs of 4", "Clubs of 5", "Clubs of 6", "Clubs of 7", "Clubs of 8", "Clubs of 9", "Clubs of 10", "Clubs of Jack", "Clubs of Queen", "Clubs of King", "Clubs of Ace", "Diamonds of 2", "Diamonds of 3", "Diamonds of 4", "Diamonds of 5", "Diamonds of 6", "Diamonds of 7", "Diamonds of 8", "Diamonds of 9", "Diamonds of 10", "Diamonds of Jack", "Diamonds of Queen", "Diamonds of King", "Diamonds of Ace", "Hearts of 2", "Hearts of 3", "Hearts of 4", "Hearts of 5", "Hearts of 6", "Hearts of 7", "Hearts of 8", "Hearts of 9", "Hearts of 10", "Hearts of Jack", "Hearts of Queen", "Hearts of King", "Hearts of Ace", "Spades of 2", "Spades of 3", "Spades of 4", "Spades of 5", "Spades of 6", "Spades of 7", "Spades of 8", "Spades of 9", "Spades of 10", "Spades of Jack", "Spades of Queen", "Spades of King", "Spades of Ace"]
       
       (compared using ==)
     # /tmp/d20151112-27349-gcxxoc/spec.rb:116: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) Card readers has readers for rank and suit
     Failure/Error: expect(card.rank).to eq :jack
       
       expected: :jack
            got: :spades
       
       (compared using ==)
       
       Diff:
       @@ -1,2 +1,2 @@
       -:jack
       +:spades
     # /tmp/d20151112-27349-gcxxoc/spec.rb:124: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)>'

  3) WarDeck behaves like a deck implements Enumerable
     Failure/Error: expect(deck_class).to include(Enumerable)
       expected WarDeck to include Enumerable
       Diff:
       @@ -1,2 +1,2 @@
       -[Enumerable]
       +WarDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/spec.rb:9: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)>'

  4) 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
     NoMethodError:
       undefined method `to_a' for #<WarDeck:0x007f1942a65600>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/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)>'

  5) WarDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<WarDeck:0x007f194286a940>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/spec.rb:30: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 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
     NoMethodError:
       undefined method `draw_bottom_card' for #<WarDeck:0x007f19428653c8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/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)>'

  7) WarDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<WarDeck:0x007f194285ee10>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/spec.rb:44: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) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `last' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/solution.rb:48:in `bottom_card'
     # /tmp/d20151112-27349-gcxxoc/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)>'

  9) WarDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: deck.shuffle
     NoMethodError:
       undefined method `shuffle!' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/solution.rb:52:in `shuffle'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:60: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) 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:0x007f19436c7380>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:140
     # /tmp/d20151112-27349-gcxxoc/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) 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:0x007f19436c46f8 @suit=:jack, @rank=:spades>, #<Card:0x007f19436c46a8 @suit=10, @rank=:hearts>, #<Card:0x007f19436c4720 @suit=:ace, @rank=:clubs>, #<Card:0x007f19436c46d0 @suit=2, @rank=:clubs>]
            got: []
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,2 @@
       -[#<Card:0x007f19436c46f8 @rank=:spades, @suit=:jack>,
       - #<Card:0x007f19436c46a8 @rank=:hearts, @suit=10>,
       - #<Card:0x007f19436c4720 @rank=:clubs, @suit=:ace>,
       - #<Card:0x007f19436c46d0 @rank=:clubs, @suit=2>]
       +[]
     # /tmp/d20151112-27349-gcxxoc/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)>'

  12) WarDeck hand #deal deals 26 cards
     Failure/Error: hand = WarDeck.new.deal
     NoMethodError:
       undefined method `deal' for #<WarDeck:0x007f19436c82f8>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:162: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) WarDeck hand #allow_face_up? returns false if the cards are more than 3
     Failure/Error: let(:hand) { WarDeck.new.deal }
     NoMethodError:
       undefined method `deal' for #<WarDeck:0x007f19435f8f30>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:169:in `block (4 levels) in <top (required)>'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:172: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)>'

  14) WarDeck hand #allow_face_up? returns true if the cards are less than or equal to 3
     Failure/Error: let(:hand) { WarDeck.new.deal }
     NoMethodError:
       undefined method `deal' for #<WarDeck:0x007f1943731910>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:169:in `block (4 levels) in <top (required)>'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:176:in `block (5 levels) in <top (required)>'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:176:in `times'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:176: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)>'

  15) BeloteDeck behaves like a deck implements Enumerable
     Failure/Error: expect(deck_class).to include(Enumerable)
       expected BeloteDeck to include Enumerable
       Diff:
       @@ -1,2 +1,2 @@
       -[Enumerable]
       +BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/spec.rb:9: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)>'

  16) 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
     NoMethodError:
       undefined method `to_a' for #<BeloteDeck:0x007f1943714400>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/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)>'

  17) BeloteDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<BeloteDeck:0x007f19436fecb8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/spec.rb:30: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) 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
     NoMethodError:
       undefined method `draw_bottom_card' for #<BeloteDeck:0x007f19436fc940>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/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)>'

  19) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<BeloteDeck:0x007f19436d4fd0>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/spec.rb:44: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)>'

  20) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `last' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/solution.rb:48:in `bottom_card'
     # /tmp/d20151112-27349-gcxxoc/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)>'

  21) BeloteDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: deck.shuffle
     NoMethodError:
       undefined method `shuffle!' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/solution.rb:52:in `shuffle'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:60: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)>'

  22) 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:0x007f19436a82a0>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:191
     # /tmp/d20151112-27349-gcxxoc/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)>'

  23) 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:0x007f194369ca90 @suit=:jack, @rank=:spades>, #<Card:0x007f194369ca40 @suit=10, @rank=:hearts>, #<Card:0x007f194369cab8 @suit=:ace, @rank=:clubs>, #<Card:0x007f194369ca68 @suit=7, @rank=:clubs>]
            got: []
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,2 @@
       -[#<Card:0x007f194369ca90 @rank=:spades, @suit=:jack>,
       - #<Card:0x007f194369ca40 @rank=:hearts, @suit=10>,
       - #<Card:0x007f194369cab8 @rank=:clubs, @suit=:ace>,
       - #<Card:0x007f194369ca68 @rank=:clubs, @suit=7>]
       +[]
     # /tmp/d20151112-27349-gcxxoc/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)>'

  24) BeloteDeck hand #deal deals 8 cards
     Failure/Error: hand = BeloteDeck.new.deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943674478>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:213: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)>'

  25) BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f194366d1a0>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:230: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)>'

  26) BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f194361fce8>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:249: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)>'

  27) BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943617cc8>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:264: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)>'

  28) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f194360be50>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:282: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)>'

  29) BeloteDeck hand #tierce? with tierce returns true for cards with numbers
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943608c50>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:297: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)>'

  30) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f19435ee008>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:314: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)>'

  31) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f19435d9d10>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:332: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)>'

  32) BeloteDeck hand #quarte? does not return true if there is no quarte
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f19435c32e0>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:347: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)>'

  33) BeloteDeck hand #quint? detects five cards with increasing ranks
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f19435af998>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:364: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)>'

  34) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f19435ad058>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:379: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)>'

  35) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f194359e5f8>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:386
     # /tmp/d20151112-27349-gcxxoc/spec.rb:84: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)>'

  36) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943592b40>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:386
     # /tmp/d20151112-27349-gcxxoc/spec.rb:99: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)>'

  37) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943582fb0>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:390
     # /tmp/d20151112-27349-gcxxoc/spec.rb:84: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)>'

  38) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943573a10>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:390
     # /tmp/d20151112-27349-gcxxoc/spec.rb:99: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)>'

  39) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943570ae0>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:394
     # /tmp/d20151112-27349-gcxxoc/spec.rb:84: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)>'

  40) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<BeloteDeck:0x007f1943557658>
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-gcxxoc/spec.rb:394
     # /tmp/d20151112-27349-gcxxoc/spec.rb:99: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)>'

  41) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: expect(deck_class).to include(Enumerable)
       expected SixtySixDeck to include Enumerable
       Diff:
       @@ -1,2 +1,2 @@
       -[Enumerable]
       +SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/spec.rb:9: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)>'

  42) 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
     NoMethodError:
       undefined method `to_a' for #<SixtySixDeck:0x007f194352b760>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/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)>'

  43) SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<SixtySixDeck:0x007f194351c7d8>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/spec.rb:30: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)>'

  44) 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
     NoMethodError:
       undefined method `draw_bottom_card' for #<SixtySixDeck:0x007f194350d788>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/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)>'

  45) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
     NoMethodError:
       undefined method `to_a' for #<SixtySixDeck:0x007f19434fe698>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/spec.rb:44: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)>'

  46) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `last' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/solution.rb:48:in `bottom_card'
     # /tmp/d20151112-27349-gcxxoc/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)>'

  47) SixtySixDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: deck.shuffle
     NoMethodError:
       undefined method `shuffle!' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/solution.rb:52:in `shuffle'
     # /tmp/d20151112-27349-gcxxoc/spec.rb:60: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)>'

  48) 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:0x007f19434cee98>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-gcxxoc/spec.rb:400
     # /tmp/d20151112-27349-gcxxoc/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)>'

  49) 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:0x007f19434c34f8 @suit=:jack, @rank=:spades>, #<Card:0x007f19434c34a8 @suit=10, @rank=:hearts>, #<Card:0x007f19434c3520 @suit=:ace, @rank=:clubs>, #<Card:0x007f19434c34d0 @suit=9, @rank=:clubs>]
            got: []
       
       (compared using ==)
       
       Diff:
       @@ -1,5 +1,2 @@
       -[#<Card:0x007f19434c34f8 @rank=:spades, @suit=:jack>,
       - #<Card:0x007f19434c34a8 @rank=:hearts, @suit=10>,
       - #<Card:0x007f19434c3520 @rank=:clubs, @suit=:ace>,
       - #<Card:0x007f19434c34d0 @rank=:clubs, @suit=9>]
       +[]
     # /tmp/d20151112-27349-gcxxoc/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)>'

  50) SixtySixDeck hand #deal deals 6 cards
     Failure/Error: hand = SixtySixDeck.new.deal
     NoMethodError:
       undefined method `deal' for #<SixtySixDeck:0x007f1943490c88>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:422: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)>'

  51) SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<SixtySixDeck:0x007f194346c3d8>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:437: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)>'

  52) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<SixtySixDeck:0x007f1943455c50>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:450: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)>'

  53) SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit
     Failure/Error: ]).deal
     NoMethodError:
       undefined method `deal' for #<SixtySixDeck:0x007f194344f6c0>
     # /tmp/d20151112-27349-gcxxoc/spec.rb:463: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)>'

Finished in 0.04048 seconds
57 examples, 53 failures

Failed examples:

rspec /tmp/d20151112-27349-gcxxoc/spec.rb:110 # Card #to_s stringifies and capitalizes the rank and suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:121 # Card readers has readers for rank and suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:8 # WarDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:28 # WarDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:35 # WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:42 # WarDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:49 # WarDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:56 # WarDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-gcxxoc/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-gcxxoc/spec.rb:145 # WarDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:161 # WarDeck hand #deal deals 26 cards
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:171 # WarDeck hand #allow_face_up? returns false if the cards are more than 3
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:175 # WarDeck hand #allow_face_up? returns true if the cards are less than or equal to 3
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:8 # BeloteDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:28 # BeloteDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:35 # BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:42 # BeloteDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:49 # BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:56 # BeloteDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-gcxxoc/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-gcxxoc/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:212 # BeloteDeck hand #deal deals 8 cards
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:220 # BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:239 # BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:254 # BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:287 # BeloteDeck hand #tierce? with tierce returns true for cards with numbers
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:304 # BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:322 # BeloteDeck hand #quarte? detects four cards with increasing ranks
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:337 # BeloteDeck hand #quarte? does not return true if there is no quarte
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:354 # BeloteDeck hand #quint? detects five cards with increasing ranks
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:369 # BeloteDeck hand #quint? does not return true if there is no quint
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:74 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:89 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:74 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:89 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:74 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:89 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:8 # SixtySixDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:28 # SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:35 # SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:42 # SixtySixDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:49 # SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:56 # SixtySixDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-gcxxoc/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-gcxxoc/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:421 # SixtySixDeck hand #deal deals 6 cards
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:429 # SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:442 # SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
rspec /tmp/d20151112-27349-gcxxoc/spec.rb:455 # SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit

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

Денислав обнови решението на 11.11.2015 16:25 (преди над 8 години)

+class Card
+ def initialize(suit, rank)
+ @suit = suit
+ @rank = rank
+ end
+
+ def rank
+ @rank
+ end
+
+ def suit
+ @suit
+ end
+
+ def to_s
+ rank.to_s.capitalize + " of " + suit.to_s.capitalize
+ end
+
+ def ==(card)
+ rank == card.rank && suit == card.suit
+ end
+
+end
+
+class Game
+ def initialize(cards = [])
+ @cards = cards
+ end
+
+ def size
+ @cards.length
+ end
+
+ def draw_top_card
+ @cards.shift
+ end
+
+ def draw_bottom_car
+ @cards.pop
+ end
+
+ def top_card
+ @cards.first
+ end
+
+ def bottom_card
+ @card.last
+ end
+
+ def shuffle
+ @card.shuffle!
+ end
+
+ def sort
+
+ end
+
+ def to_s
+ @cards.each do |card|
+ card.to_s + "\n"
+ end
+ end
+end

Денислав обнови решението на 11.11.2015 16:31 (преди над 8 години)

class Card
- def initialize(suit, rank)
+ def initialize(suit, rank)
@suit = suit
@rank = rank
end
def rank
- @rank
+ @rank
end
def suit
- @suit
+ @suit
end
def to_s
- rank.to_s.capitalize + " of " + suit.to_s.capitalize
+ rank.to_s.capitalize + " of " + suit.to_s.capitalize
end
- def ==(card)
- rank == card.rank && suit == card.suit
- end
+ def ==(card)
+ rank == card.rank && suit == card.suit
+ end
end
class Game
- def initialize(cards = [])
- @cards = cards
- end
+ def initialize(cards = [])
+ @cards = cards
+ end
- def size
- @cards.length
- end
+ def size
+ @cards.length
+ end
- def draw_top_card
- @cards.shift
- end
+ def draw_top_card
+ @cards.shift
+ end
- def draw_bottom_car
- @cards.pop
- end
+ def draw_bottom_car
+ @cards.pop
+ end
- def top_card
- @cards.first
- end
+ def top_card
+ @cards.first
+ end
- def bottom_card
- @card.last
- end
+ def bottom_card
+ @card.last
+ end
- def shuffle
- @card.shuffle!
- end
+ def shuffle
+ @card.shuffle!
+ end
- def sort
+ def sort
- end
+ end
- def to_s
- @cards.each do |card|
+ def to_s
- card.to_s + "\n"
+ @cards.each do |card|
- end
+ card.to_s + "\n"
- end
+ end
-end
+ end
+end
+
+class WarDeck < Game
+
+end

Денислав обнови решението на 11.11.2015 17:19 (преди над 8 години)

class Card
def initialize(suit, rank)
@suit = suit
@rank = rank
end
def rank
@rank
end
def suit
@suit
end
def to_s
rank.to_s.capitalize + " of " + suit.to_s.capitalize
end
def ==(card)
rank == card.rank && suit == card.suit
end
-
end
class Game
+ @@suits = %w{spades hearts clubs diamonds}
def initialize(cards = [])
@cards = cards
+ @ranks = %w{2 3 4 5 6 7 8 9 10 jack queen king ace}
end
def size
@cards.length
end
def draw_top_card
@cards.shift
end
def draw_bottom_car
@cards.pop
end
def top_card
@cards.first
end
def bottom_card
@card.last
end
def shuffle
@card.shuffle!
end
def sort
end
def to_s
@cards.each do |card|
card.to_s + "\n"
end
end
+
+ def generate_all_cards
+ @@suits.each { |suit| @ranks.each { |rank| @cards << Card.new(suit, rank) }}
+ end
end
class WarDeck < Game
+ def initialize(cards = [])
+ @cards = cards
+ @ranks = %w{2 3 4 5 6 7 8 9 10 jack queen king ace}
+ generate_all_cards if(cards.empty?)
+ end
+end
+class BeloteDeck < Game
+ def initialize(cards = [])
+ @cards = cards
+ @ranks = %w{7 8 9 10 jack queen king 10 ace}
+ generate_all_cards if(cards.empty?)
+ end
end
+
+class SixtySixDeck < Game
+ def initialize(cards = [])
+ @cards = cards
+ @ranks = %w{9 jack queen king 10 ace}
+ generate_all_cards if(cards.empty?)
+ end
+end