From f7f1b7676251359a0677f461ffe53049f5e5f488 Mon Sep 17 00:00:00 2001 From: Camille Baldock Date: Sun, 7 Sep 2014 20:39:15 -0700 Subject: [PATCH] Move hand definitions in test for readability --- spec/hand_spec.rb | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/spec/hand_spec.rb b/spec/hand_spec.rb index f250b24..cc2a971 100644 --- a/spec/hand_spec.rb +++ b/spec/hand_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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