Permalink
Browse files

Compare four of a kind hands

  • Loading branch information...
camillebaldock committed Sep 8, 2014
1 parent 7bad3d1 commit eedd1a1fc5435ab348b12a31931d4c6d23210f51
Showing with 30 additions and 2 deletions.
  1. +1 −1 lib/hand.rb
  2. +29 −1 spec/hand_spec.rb
View
@@ -80,7 +80,7 @@ def has_four
{
:type => :four_of_a_kind,
:value => pips_per_occurence[4].first,
- :kicker => pips_per_occurence[1].first
+ :cards => pips_per_occurence[1]
}
end
end
View
@@ -85,6 +85,20 @@
it "returns the other cards correctly" do
expect(hand.rank.fetch(:cards)).to eq [8,7]
end
+ context "comparison" do
+ context "with a hand with the same three of a kind but lower cards" do
+ let(:other_hand_string_array) { ["5h", "5d", "5s", "7s", "6s"] }
+ it "is better" do
+ expect(hand).to be > other_hand
+ end
+ end
+ context "with a hand with the same three of a kind and same pips for other cards" do
+ let(:other_hand_string_array) { ["5h", "5d", "5s", "7s", "8s"] }
+ it "is a tie" do
+ expect(hand).to be == other_hand
+ end
+ end
+ end
end
context "four of a kind" do
@@ -96,7 +110,21 @@
expect(hand.rank.fetch(:value)).to eq 5
end
it "sets the kicker correctly" do
- expect(hand.rank.fetch(:kicker)).to eq 8
+ expect(hand.rank.fetch(:cards).first).to eq 8
+ end
+ context "comparison" do
+ context "with a hand with the same four of a kind but lower cards" do
+ let(:other_hand_string_array) { ["5h", "5d", "5s", "5c", "6s"] }
+ it "is better" do
+ expect(hand).to be > other_hand
+ end
+ end
+ context "with a hand with the same four of a kind and same pips for other cards" do
+ let(:other_hand_string_array) { ["5h", "5d", "5s", "5c", "8h"] }
+ it "is a tie" do
+ expect(hand).to be == other_hand
+ end
+ end
end
end

0 comments on commit eedd1a1

Please sign in to comment.