Skip to content

Commit

Permalink
Move hand definitions in test for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
camillebaldock committed Sep 8, 2014
1 parent c90f446 commit f7f1b76
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions spec/hand_spec.rb
Expand Up @@ -9,24 +9,13 @@
let(:card_parser) { CardParser.new }
let(:hand_parser) { HandArrayParser.new(card_parser) }
let(:pair_hand_string_array) { ["5h", "5d", "6d", "7d", "8d"] }
let(:highest_hand_string_array) { ["4h", "5d", "6d", "7d", "9d"] }
let(:two_pair_hand_string_array) { ["4h", "4d", "6d", "6h", "9s"] }
let(:two_pair_low_kicker_hand_string_array) { ["4h", "4d", "6d", "6h", "2s"] }
let(:three_of_a_kind_hand_string_array) { ["5h", "5d", "5s", "7d", "8d"] }
let(:four_of_a_kind_hand_string_array) { ["5h", "5d", "5s", "5c", "8d"] }
let(:full_house_hand_string_array) { ["5h", "5d", "5s", "6c", "6h"] }
let(:flush_hand_string_array) { ["5h", "6h", "7h", "8h", "10h"] }
let(:straight_hand_string_array) { ["5h", "6h", "7h", "8h", "9d"] }
let(:straight_hand_low_ace_string_array) { ["2h", "3h", "4h", "5h", "ad"] }
let(:straight_hand_high_ace_string_array) { ["10h", "jh", "qh", "kh", "ad"] }
let(:straight_flush_hand_string_array) { ["5h", "6h", "7h", "8h", "9h"] }
let(:hand_string_array) { pair_hand_string_array }
let(:hand) { described_class.new(hand_string_array, hand_parser) }

describe "hand comparisons" do
it "tells me if the hand is better" do
four_of_a_kind_hand = described_class.new(four_of_a_kind_hand_string_array, hand_parser)
full_house_hand = described_class.new(full_house_hand_string_array, hand_parser)
four_of_a_kind_hand = described_class.new(["5h", "5d", "5s", "5c", "8d"] , hand_parser)
full_house_hand = described_class.new(["5h", "5d", "5s", "6c", "6h"], hand_parser)

expect(four_of_a_kind_hand).to be > full_house_hand
end
Expand All @@ -46,7 +35,7 @@
end

context "high card" do
let(:hand_string_array) { highest_hand_string_array }
let(:hand_string_array) { ["4h", "5d", "6d", "7d", "9d"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :highest
end
Expand All @@ -56,14 +45,14 @@
end

context "three of a kind" do
let(:hand_string_array) { three_of_a_kind_hand_string_array }
let(:hand_string_array) { ["5h", "5d", "5s", "7d", "8d"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :three_of_a_kind
end
end

context "four of a kind" do
let(:hand_string_array) { four_of_a_kind_hand_string_array }
let(:hand_string_array) { ["5h", "5d", "5s", "5c", "8d"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :four_of_a_kind
end
Expand All @@ -76,21 +65,21 @@
end

context "full house" do
let(:hand_string_array) { full_house_hand_string_array }
let(:hand_string_array) { ["5h", "5d", "5s", "6c", "6h"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :full_house
end
end

context "flush hand" do
let(:hand_string_array) { flush_hand_string_array }
let(:hand_string_array) { ["5h", "6h", "7h", "8h", "10h"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :flush
end
end

context "straight hand" do
let(:hand_string_array) { straight_hand_string_array }
let(:hand_string_array) { ["5h", "6h", "7h", "8h", "9d"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :straight
end
Expand All @@ -100,7 +89,7 @@
end

context "straight with low ace hand" do
let(:hand_string_array) { straight_hand_low_ace_string_array }
let(:hand_string_array) { ["2h", "3h", "4h", "5h", "ad"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :straight
end
Expand All @@ -110,7 +99,7 @@
end

context "straight with high ace hand" do
let(:hand_string_array) { straight_hand_high_ace_string_array }
let(:hand_string_array) { ["10h", "jh", "qh", "kh", "ad"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :straight
end
Expand All @@ -120,7 +109,7 @@
end

context "two pairs" do
let(:hand_string_array) { two_pair_hand_string_array }
let(:hand_string_array) { ["4h", "4d", "6d", "6h", "9s"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :two_pair
end
Expand All @@ -133,14 +122,14 @@
end

context "two pairs with low kicker" do
let(:hand_string_array) { two_pair_low_kicker_hand_string_array }
let(:hand_string_array) { ["4h", "4d", "6d", "6h", "2s"] }
it "sets the kicker correctly" do
expect(hand.rank.fetch(:kicker)).to eq 2
end
end

context "straight flush" do
let(:hand_string_array) { straight_flush_hand_string_array }
let(:hand_string_array) { ["5h", "6h", "7h", "8h", "9h"] }
it "ranks the hand correctly" do
expect(hand.rank.fetch(:type)).to eq :straight_flush
end
Expand Down

0 comments on commit f7f1b76

Please sign in to comment.