Permalink
Browse files

Implement value and cards for pair hand

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent dd9b8c2 commit 7124f2e92f866dec17a127be6a09c381209c7758
Showing with 15 additions and 3 deletions.
  1. +9 −3 lib/hand.rb
  2. +6 −0 spec/hand_spec.rb
View
@@ -46,7 +46,7 @@ def rank
elsif has_two_pairs
has_two_pairs
elsif has_two
{ :type => :pair }
has_two
else
{ :type => :highest }
end
@@ -87,11 +87,17 @@ def has_two_pairs
end
def has_two
pips_per_occurence[2]
if pips_per_occurence[2]
{
:type => :pair,
:value => pips_per_occurence[2].first,
:cards => pips_per_occurence[1].sort.reverse
}
end
end
def full_house
has_three && has_two
has_three && pips_per_occurence[2]
end
def flush
View
@@ -37,6 +37,12 @@
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :pair
end
it "returns the value correctly" do
expect(hand.rank.fetch(:value)).to eq 5
end
it "returns the other cards correctly" do
expect(hand.rank.fetch(:cards)).to eq [8,7,6]
end
end
context "high card" do

0 comments on commit 7124f2e

Please sign in to comment.