Permalink
Browse files

Compare straight and straight flush hands

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent c51045c commit 999d655c3263f0b3bc541f1b8e45aaf8846513f5
Showing with 24 additions and 8 deletions.
  1. +2 −2 lib/hand.rb
  2. +22 −6 spec/hand_spec.rb
View
@@ -174,9 +174,9 @@ def straight
card_values = cards.map(&:pips)
aces_as_ones = aces_as_ones(card_values)
if aces_as_ones != card_values && consecutive_cards?(aces_as_ones)
{ :type => :straight, :highest => 5 }
{ :type => :straight, :value => 5 }
elsif consecutive_cards?(card_values)
{ :type => :straight, :highest => high_card }
{ :type => :straight, :value => high_card }
end
end
View
@@ -185,7 +185,15 @@
expect(hand.rank.fetch(:type)).to eq :straight
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 9
expect(hand.rank.fetch(:value)).to eq 9
end
context "comparison" do
context "with a hand with a lower higher card" do
let(:other_hand_string_array) { ["5h", "6h", "7h", "8h", "4d"] }
it "is better" do
expect(hand).to be > other_hand
end
end
end
end
@@ -195,7 +203,7 @@
expect(hand.rank.fetch(:type)).to eq :straight
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 5
expect(hand.rank.fetch(:value)).to eq 5
end
end
@@ -205,7 +213,7 @@
expect(hand.rank.fetch(:type)).to eq :straight
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 14
expect(hand.rank.fetch(:value)).to eq 14
end
end
@@ -261,7 +269,15 @@
expect(hand.rank.fetch(:type)).to eq :straight_flush
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 9
expect(hand.rank.fetch(:value)).to eq 9
end
context "comparison" do
context "with a hand with a lower higher card" do
let(:other_hand_string_array) { ["5h", "6h", "7h", "8h", "4h"] }
it "is better" do
expect(hand).to be > other_hand
end
end
end
end
@@ -271,7 +287,7 @@
expect(hand.rank.fetch(:type)).to eq :straight_flush
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 5
expect(hand.rank.fetch(:value)).to eq 5
end
end
@@ -281,7 +297,7 @@
expect(hand.rank.fetch(:type)).to eq :straight_flush
end
it "sets the highest hand correctly" do
expect(hand.rank.fetch(:highest)).to eq 14
expect(hand.rank.fetch(:value)).to eq 14
end
end
end

0 comments on commit 999d655

Please sign in to comment.