Permalink
Browse files

Add straight flush, correct ordering of hands

  • Loading branch information...
camillebaldock committed Sep 3, 2014
1 parent b9bd531 commit 920268d50723eb48d17c4c87f72d56f028871f1d
Showing with 16 additions and 3 deletions.
  1. +9 −3 lib/hand.rb
  2. +7 −0 spec/hand_spec.rb
View
@@ -16,14 +16,16 @@ def better_than?(other_hand)
]
def rank
- if has_four
+ if straight_flush
+ { :type => :straight_flush }
+ elsif has_four
{ :type => :four_of_a_kind }
elsif full_house
{ :type => :full_house }
- elsif straight
- { :type => :straight }
elsif flush
{ :type => :flush }
+ elsif straight
+ { :type => :straight }
elsif has_three
{ :type => :three_of_a_kind }
elsif has_two_pairs
@@ -94,6 +96,10 @@ def straight
end
end
+ def straight_flush
+ straight && flush
+ end
+
#TODO: live in a helper, utility
def consecutive_cards?(card_values)
card_values.sort!
View
@@ -35,6 +35,9 @@
let(:straight_hand_high_ace) {
HandParser.new.parse(["10h", "jh", "qh", "kh", "ad"])
}
+ let(:straight_flush_hand) {
+ HandParser.new.parse(["5h", "6h", "7h", "8h", "9h"])
+ }
describe "#better_than" do
it "tells me if the hand is better" do
@@ -94,5 +97,9 @@
it "works with a two pair hand" do
expect(two_pair_hand.rank).to eq ({:type => :two_pair})
end
+
+ it "works with a straight flush hand" do
+ expect(straight_flush_hand.rank).to eq ({:type => :straight_flush})
+ end
end
end

0 comments on commit 920268d

Please sign in to comment.