Skip to content

Commit

Permalink
Compare straight and straight flush hands
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebaldock committed Sep 8, 2014
1 parent c51045c commit 999d655
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/hand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 22 additions & 6 deletions spec/hand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 999d655

Please sign in to comment.