|
2 | 2 | require_relative 'poker'
|
3 | 3 |
|
4 | 4 | class PokerTest < Minitest::Test
|
5 |
| - def test_one_hand |
6 |
| - high_of_jack = %w[4S 5S 7H 8D JC] |
7 |
| - game = Poker.new([high_of_jack]) |
8 |
| - assert_equal [high_of_jack], game.best_hand |
| 5 | + def test_single_hand_always_wins |
| 6 | + # skip |
| 7 | + hands = [%w[4S 5S 7H 8D JC]] |
| 8 | + assert_equal [%w[4S 5S 7H 8D JC]], Poker.new(hands).best_hand |
9 | 9 | end
|
10 | 10 |
|
11 |
| - def test_highest_card |
| 11 | + def test_highest_card_out_of_all_hands_wins |
12 | 12 | skip
|
13 |
| - high_of_8 = %w[4S 5H 6S 8D 2H] |
14 |
| - high_of_queen = %w[2S 4H 6C 9D QH] |
15 |
| - game = Poker.new([high_of_8, high_of_queen]) |
16 |
| - assert_equal [high_of_queen], game.best_hand |
| 13 | + hands = [%w[4D 5S 6S 8D 3C], %w[2S 4C 7S 9H 10H], %w[3S 4S 5D 6H JH]] |
| 14 | + assert_equal [%w[3S 4S 5D 6H JH]], Poker.new(hands).best_hand |
17 | 15 | end
|
18 | 16 |
|
19 |
| - def test_highest_card_10 |
| 17 | + def test_a_tie_has_multiple_winners |
20 | 18 | skip
|
21 |
| - high_of_8 = %w[4D 5S 6S 8D 3C] |
22 |
| - high_of_10 = %w[2S 4C 7S 9H 10H] |
23 |
| - game = Poker.new([high_of_8, high_of_10]) |
24 |
| - assert_equal [high_of_10], game.best_hand |
| 19 | + hands = [%w[4D 5S 6S 8D 3C], %w[2S 4C 7S 9H 10H], %w[3S 4S 5D 6H JH], %w[3H 4H 5C 6C JD]] |
| 20 | + assert_equal [%w[3S 4S 5D 6H JH], %w[3H 4H 5C 6C JD]], Poker.new(hands).best_hand |
25 | 21 | end
|
26 | 22 |
|
27 |
| - def test_nothing_vs_one_pair |
| 23 | + def test_multiple_hands_with_the_same_high_cards_tie_compares_next_highest_ranked_down_to_last_card |
28 | 24 | skip
|
29 |
| - high_of_king = %w[4S 5H 6C 8D KH] |
30 |
| - pair_of_4 = %w[2S 4H 6S 4D JH] |
31 |
| - game = Poker.new([high_of_king, pair_of_4]) |
32 |
| - assert_equal [pair_of_4], game.best_hand |
| 25 | + hands = [%w[3S 5H 6S 8D 7H], %w[2S 5D 6D 8C 7S]] |
| 26 | + assert_equal [%w[3S 5H 6S 8D 7H]], Poker.new(hands).best_hand |
33 | 27 | end
|
34 | 28 |
|
35 |
| - def test_two_pair |
| 29 | + def test_one_pair_beats_high_card |
36 | 30 | skip
|
37 |
| - pair_of_2 = %w[4S 2H 6S 2D JH] |
38 |
| - pair_of_4 = %w[2S 4H 6C 4D JD] |
39 |
| - game = Poker.new([pair_of_2, pair_of_4]) |
40 |
| - assert_equal [pair_of_4], game.best_hand |
| 31 | + hands = [%w[4S 5H 6C 8D KH], %w[2S 4H 6S 4D JH]] |
| 32 | + assert_equal [%w[2S 4H 6S 4D JH]], Poker.new(hands).best_hand |
41 | 33 | end
|
42 | 34 |
|
43 |
| - def test_one_pair_vs_double_pair |
| 35 | + def test_highest_pair_wins |
44 | 36 | skip
|
45 |
| - pair_of_8 = %w[2S 8H 6S 8D JH] |
46 |
| - fives_and_fours = %w[4S 5H 4C 8C 5C] |
47 |
| - game = Poker.new([pair_of_8, fives_and_fours]) |
48 |
| - assert_equal [fives_and_fours], game.best_hand |
| 37 | + hands = [%w[4S 2H 6S 2D JH], %w[2S 4H 6C 4D JD]] |
| 38 | + assert_equal [%w[2S 4H 6C 4D JD]], Poker.new(hands).best_hand |
49 | 39 | end
|
50 | 40 |
|
51 |
| - def test_two_double_pair |
| 41 | + def test_two_pairs_beats_one_pair |
52 | 42 | skip
|
53 |
| - eights_and_twos = %w[2S 8H 2D 8D 3H] |
54 |
| - fives_and_fours = %w[4S 5H 4C 8S 5D] |
55 |
| - game = Poker.new([eights_and_twos, fives_and_fours]) |
56 |
| - assert_equal [eights_and_twos], game.best_hand |
| 43 | + hands = [%w[2S 8H 6S 8D JH], %w[4S 5H 4C 8C 5C]] |
| 44 | + assert_equal [%w[4S 5H 4C 8C 5C]], Poker.new(hands).best_hand |
57 | 45 | end
|
58 | 46 |
|
59 |
| - def test_another_two_double_pair |
| 47 | + def test_both_hands_have_two_pairs_highest_ranked_pair_wins |
60 | 48 | skip
|
61 |
| - aces_and_twos = %w[2S AH 2C AD JH] |
62 |
| - queens_and_jacks = %w[JD QH JS 8D QC] |
63 |
| - game = Poker.new([aces_and_twos, queens_and_jacks]) |
64 |
| - assert_equal [aces_and_twos], game.best_hand |
| 49 | + hands = [%w[2S 8H 2D 8D 3H], %w[4S 5H 4C 8S 5D]] |
| 50 | + assert_equal [%w[2S 8H 2D 8D 3H]], Poker.new(hands).best_hand |
65 | 51 | end
|
66 | 52 |
|
67 |
| - def test_double_pair_vs_three |
| 53 | + def test_both_hands_have_two_pairs_with_the_same_highest_ranked_pair_tie_goes_to_low_pair |
68 | 54 | skip
|
69 |
| - eights_and_twos = %w[2S 8H 2H 8D JH] |
70 |
| - three_of_4 = %w[4S 5H 4C 8S 4H] |
71 |
| - game = Poker.new([eights_and_twos, three_of_4]) |
72 |
| - assert_equal [three_of_4], game.best_hand |
| 55 | + hands = [%w[2S QS 2C QD JH], %w[JD QH JS 8D QC]] |
| 56 | + assert_equal [%w[JD QH JS 8D QC]], Poker.new(hands).best_hand |
73 | 57 | end
|
74 | 58 |
|
75 |
| - def test_two_three |
| 59 | + def test_both_hands_have_two_identically_ranked_pairs_tie_goes_to_remaining_card_kicker |
76 | 60 | skip
|
77 |
| - three_twos = %w[2S 2H 2C 8D JH] |
78 |
| - three_aces = %w[4S AH AS 8C AD] |
79 |
| - game = Poker.new([three_twos, three_aces]) |
80 |
| - assert_equal [three_aces], game.best_hand |
| 61 | + hands = [%w[JD QH JS 8D QC], %w[JS QS JC 2D QD]] |
| 62 | + assert_equal [%w[JD QH JS 8D QC]], Poker.new(hands).best_hand |
81 | 63 | end
|
82 | 64 |
|
83 |
| - def test_three_vs_straight |
| 65 | + def test_both_hands_have_two_pairs_that_add_to_the_same_value_win_goes_to_highest_pair |
84 | 66 | skip
|
85 |
| - three_of_4 = %w[4S 5H 4C 8D 4H] |
86 |
| - straight = %w[3S 4D 2S 6D 5C] |
87 |
| - game = Poker.new([three_of_4, straight]) |
88 |
| - assert_equal [straight], game.best_hand |
| 67 | + hands = [%w[6S 6H 3S 3H AS], %w[7H 7S 2H 2S AC]] |
| 68 | + assert_equal [%w[7H 7S 2H 2S AC]], Poker.new(hands).best_hand |
89 | 69 | end
|
90 | 70 |
|
91 |
| - def test_a_5_high_straight |
| 71 | + def test_two_pairs_first_ranked_by_largest_pair |
92 | 72 | skip
|
93 |
| - three_of_4 = %w[4S 5H 4C 8D 4H] |
94 |
| - straight_to_5 = %w[4D AH 3S 2D 5C] |
95 |
| - game = Poker.new([three_of_4, straight_to_5]) |
96 |
| - assert_equal [straight_to_5], game.best_hand |
| 73 | + hands = [%w[5C 2S 5S 4H 4C], %w[6S 2S 6H 7C 2C]] |
| 74 | + assert_equal [%w[6S 2S 6H 7C 2C]], Poker.new(hands).best_hand |
97 | 75 | end
|
98 | 76 |
|
99 |
| - def test_two_straights |
| 77 | + def test_three_of_a_kind_beats_two_pair |
100 | 78 | skip
|
101 |
| - straight_to_8 = %w[4S 6C 7S 8D 5H] |
102 |
| - straight_to_9 = %w[5S 7H 8S 9D 6H] |
103 |
| - game = Poker.new([straight_to_8, straight_to_9]) |
104 |
| - assert_equal [straight_to_9], game.best_hand |
| 79 | + hands = [%w[2S 8H 2H 8D JH], %w[4S 5H 4C 8S 4H]] |
| 80 | + assert_equal [%w[4S 5H 4C 8S 4H]], Poker.new(hands).best_hand |
105 | 81 | end
|
106 | 82 |
|
107 |
| - def test_5_high_straight_vs_other_straight |
| 83 | + def test_both_hands_have_three_of_a_kind_tie_goes_to_highest_ranked_triplet |
108 | 84 | skip
|
109 |
| - straight_to_jack = %w[8H 7C 10D 9D JH] |
110 |
| - straight_to_5 = %w[4S AH 3S 2D 5H] |
111 |
| - game = Poker.new([straight_to_jack, straight_to_5]) |
112 |
| - assert_equal [straight_to_jack], game.best_hand |
| 85 | + hands = [%w[2S 2H 2C 8D JH], %w[4S AH AS 8C AD]] |
| 86 | + assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand |
113 | 87 | end
|
114 | 88 |
|
115 |
| - def test_straight_vs_flush |
| 89 | + def test_with_multiple_decks_two_players_can_have_same_three_of_a_kind_ties_go_to_highest_remaining_cards |
116 | 90 | skip
|
117 |
| - straight_to_8 = %w[4C 6H 7D 8D 5H] |
118 |
| - flush_to_7 = %w[2S 4S 5S 6S 7S] |
119 |
| - game = Poker.new([straight_to_8, flush_to_7]) |
120 |
| - assert_equal [flush_to_7], game.best_hand |
| 91 | + hands = [%w[4S AH AS 7C AD], %w[4S AH AS 8C AD]] |
| 92 | + assert_equal [%w[4S AH AS 8C AD]], Poker.new(hands).best_hand |
121 | 93 | end
|
122 | 94 |
|
123 |
| - def test_two_flushes |
| 95 | + def test_a_straight_beats_three_of_a_kind |
124 | 96 | skip
|
125 |
| - flush_to_8 = %w[3H 6H 7H 8H 5H] |
126 |
| - flush_to_7 = %w[2S 4S 5S 6S 7S] |
127 |
| - game = Poker.new([flush_to_8, flush_to_7]) |
128 |
| - assert_equal [flush_to_8], game.best_hand |
| 97 | + hands = [%w[4S 5H 4C 8D 4H], %w[3S 4D 2S 6D 5C]] |
| 98 | + assert_equal [%w[3S 4D 2S 6D 5C]], Poker.new(hands).best_hand |
129 | 99 | end
|
130 | 100 |
|
131 |
| - def test_flush_vs_full |
| 101 | + def test_aces_can_end_a_straight_10_j_q_k_a |
132 | 102 | skip
|
133 |
| - flush_to_8 = %w[3H 6H 7H 8H 5C] |
134 |
| - full = %w[4S 5H 4C 5D 4H] |
135 |
| - game = Poker.new([flush_to_8, full]) |
136 |
| - assert_equal [full], game.best_hand |
| 103 | + hands = [%w[4S 5H 4C 8D 4H], %w[10D JH QS KD AC]] |
| 104 | + assert_equal [%w[10D JH QS KD AC]], Poker.new(hands).best_hand |
137 | 105 | end
|
138 | 106 |
|
139 |
| - def test_two_fulls |
| 107 | + def test_aces_can_start_a_straight_a_2_3_4_5 |
140 | 108 | skip
|
141 |
| - full_of_4_by_9 = %w[4H 4S 4D 9S 9D] |
142 |
| - full_of_5_by_8 = %w[5H 5S 5D 8S 8D] |
143 |
| - game = Poker.new([full_of_4_by_9, full_of_5_by_8]) |
144 |
| - assert_equal [full_of_5_by_8], game.best_hand |
| 109 | + hands = [%w[4S 5H 4C 8D 4H], %w[4D AH 3S 2D 5C]] |
| 110 | + assert_equal [%w[4D AH 3S 2D 5C]], Poker.new(hands).best_hand |
145 | 111 | end
|
146 | 112 |
|
147 |
| - def test_full_vs_square |
| 113 | + def test_aces_cannot_be_in_the_middle_of_a_straight_q_k_a_2_3 |
148 | 114 | skip
|
149 |
| - full = %w[4S 5H 4D 5D 4H] |
150 |
| - square_of_3 = %w[3S 3H 2S 3D 3C] |
151 |
| - game = Poker.new([square_of_3, full]) |
152 |
| - assert_equal [square_of_3], game.best_hand |
| 115 | + hands = [%w[2C 3D 7H 5H 2S], %w[QS KH AC 2D 3S]] |
| 116 | + assert_equal [%w[2C 3D 7H 5H 2S]], Poker.new(hands).best_hand |
153 | 117 | end
|
154 | 118 |
|
155 |
| - def test_two_square |
| 119 | + def test_both_hands_with_a_straight_tie_goes_to_highest_ranked_card |
156 | 120 | skip
|
157 |
| - square_of_2 = %w[2S 2H 2C 8D 2D] |
158 |
| - square_of_5 = %w[4S 5H 5S 5D 5C] |
159 |
| - game = Poker.new([square_of_2, square_of_5]) |
160 |
| - assert_equal [square_of_5], game.best_hand |
| 121 | + hands = [%w[4S 6C 7S 8D 5H], %w[5S 7H 8S 9D 6H]] |
| 122 | + assert_equal [%w[5S 7H 8S 9D 6H]], Poker.new(hands).best_hand |
161 | 123 | end
|
162 | 124 |
|
163 |
| - def test_square_vs_straight_flush |
| 125 | + def test_even_though_an_ace_is_usually_high_a_5_high_straight_is_the_lowest_scoring_straight |
164 | 126 | skip
|
165 |
| - square_of_5 = %w[4S 5H 5S 5D 5C] |
166 |
| - straight_flush_to_10 = %w[7S 8S 9S 6S 10S] |
167 |
| - game = Poker.new([square_of_5, straight_flush_to_10]) |
168 |
| - assert_equal [straight_flush_to_10], game.best_hand |
| 127 | + hands = [%w[2H 3C 4D 5D 6H], %w[4S AH 3S 2D 5H]] |
| 128 | + assert_equal [%w[2H 3C 4D 5D 6H]], Poker.new(hands).best_hand |
169 | 129 | end
|
170 | 130 |
|
171 |
| - def test_two_straight_flushes |
| 131 | + def test_flush_beats_a_straight |
172 | 132 | skip
|
173 |
| - straight_flush_to_8 = %w[4H 6H 7H 8H 5H] |
174 |
| - straight_flush_to_9 = %w[5S 7S 8S 9S 6S] |
175 |
| - game = Poker.new([straight_flush_to_8, straight_flush_to_9]) |
176 |
| - assert_equal [straight_flush_to_9], game.best_hand |
| 133 | + hands = [%w[4C 6H 7D 8D 5H], %w[2S 4S 5S 6S 7S]] |
| 134 | + assert_equal [%w[2S 4S 5S 6S 7S]], Poker.new(hands).best_hand |
177 | 135 | end
|
178 | 136 |
|
179 |
| - def test_highest_card_down_to_fifth_card |
| 137 | + def test_both_hands_have_a_flush_tie_goes_to_high_card_down_to_the_last_one_if_necessary |
180 | 138 | skip
|
181 |
| - high_of_8_low_of_3 = %w[3S 5H 6S 8D 7H] |
182 |
| - high_of_8_low_of_2 = %w[2S 5D 6D 8C 7S] |
183 |
| - game = Poker.new([high_of_8_low_of_3, high_of_8_low_of_2]) |
184 |
| - assert_equal [high_of_8_low_of_3], game.best_hand |
| 139 | + hands = [%w[4H 7H 8H 9H 6H], %w[2S 4S 5S 6S 7S]] |
| 140 | + assert_equal [%w[4H 7H 8H 9H 6H]], Poker.new(hands).best_hand |
185 | 141 | end
|
186 | 142 |
|
187 |
| - def test_three_hand_with_tie |
| 143 | + def test_full_house_beats_a_flush |
188 | 144 | skip
|
189 |
| - spade_straight_to_9 = %w[9S 8S 7S 6S 5S] |
190 |
| - diamond_straight_to_9 = %w[9D 8D 7D 6D 5D] |
191 |
| - three_of_4 = %w[4D 4S 4H QS KS] |
192 |
| - hands = [spade_straight_to_9, diamond_straight_to_9, three_of_4] |
193 |
| - game = Poker.new(hands) |
194 |
| - assert_equal [spade_straight_to_9, diamond_straight_to_9], game.best_hand |
| 145 | + hands = [%w[3H 6H 7H 8H 5H], %w[4S 5H 4C 5D 4H]] |
| 146 | + assert_equal [%w[4S 5H 4C 5D 4H]], Poker.new(hands).best_hand |
| 147 | + end |
| 148 | + |
| 149 | + def test_both_hands_have_a_full_house_tie_goes_to_highest_ranked_triplet |
| 150 | + skip |
| 151 | + hands = [%w[4H 4S 4D 9S 9D], %w[5H 5S 5D 8S 8D]] |
| 152 | + assert_equal [%w[5H 5S 5D 8S 8D]], Poker.new(hands).best_hand |
| 153 | + end |
| 154 | + |
| 155 | + def test_with_multiple_decks_both_hands_have_a_full_house_with_the_same_triplet_tie_goes_to_the_pair |
| 156 | + skip |
| 157 | + hands = [%w[5H 5S 5D 9S 9D], %w[5H 5S 5D 8S 8D]] |
| 158 | + assert_equal [%w[5H 5S 5D 9S 9D]], Poker.new(hands).best_hand |
| 159 | + end |
| 160 | + |
| 161 | + def test_four_of_a_kind_beats_a_full_house |
| 162 | + skip |
| 163 | + hands = [%w[4S 5H 4D 5D 4H], %w[3S 3H 2S 3D 3C]] |
| 164 | + assert_equal [%w[3S 3H 2S 3D 3C]], Poker.new(hands).best_hand |
| 165 | + end |
| 166 | + |
| 167 | + def test_both_hands_have_four_of_a_kind_tie_goes_to_high_quad |
| 168 | + skip |
| 169 | + hands = [%w[2S 2H 2C 8D 2D], %w[4S 5H 5S 5D 5C]] |
| 170 | + assert_equal [%w[4S 5H 5S 5D 5C]], Poker.new(hands).best_hand |
| 171 | + end |
| 172 | + |
| 173 | + def test_with_multiple_decks_both_hands_with_identical_four_of_a_kind_tie_determined_by_kicker |
| 174 | + skip |
| 175 | + hands = [%w[3S 3H 2S 3D 3C], %w[3S 3H 4S 3D 3C]] |
| 176 | + assert_equal [%w[3S 3H 4S 3D 3C]], Poker.new(hands).best_hand |
| 177 | + end |
| 178 | + |
| 179 | + def test_straight_flush_beats_four_of_a_kind |
| 180 | + skip |
| 181 | + hands = [%w[4S 5H 5S 5D 5C], %w[7S 8S 9S 6S 10S]] |
| 182 | + assert_equal [%w[7S 8S 9S 6S 10S]], Poker.new(hands).best_hand |
| 183 | + end |
| 184 | + |
| 185 | + def test_aces_can_end_a_straight_flush_10_j_q_k_a |
| 186 | + skip |
| 187 | + hands = [%w[KC AH AS AD AC], %w[10C JC QC KC AC]] |
| 188 | + assert_equal [%w[10C JC QC KC AC]], Poker.new(hands).best_hand |
| 189 | + end |
| 190 | + |
| 191 | + def test_aces_can_start_a_straight_flush_a_2_3_4_5 |
| 192 | + skip |
| 193 | + hands = [%w[KS AH AS AD AC], %w[4H AH 3H 2H 5H]] |
| 194 | + assert_equal [%w[4H AH 3H 2H 5H]], Poker.new(hands).best_hand |
| 195 | + end |
| 196 | + |
| 197 | + def test_aces_cannot_be_in_the_middle_of_a_straight_flush_q_k_a_2_3 |
| 198 | + skip |
| 199 | + hands = [%w[2C AC QC 10C KC], %w[QH KH AH 2H 3H]] |
| 200 | + assert_equal [%w[2C AC QC 10C KC]], Poker.new(hands).best_hand |
| 201 | + end |
| 202 | + |
| 203 | + def test_both_hands_have_a_straight_flush_tie_goes_to_highest_ranked_card |
| 204 | + skip |
| 205 | + hands = [%w[4H 6H 7H 8H 5H], %w[5S 7S 8S 9S 6S]] |
| 206 | + assert_equal [%w[5S 7S 8S 9S 6S]], Poker.new(hands).best_hand |
| 207 | + end |
| 208 | + |
| 209 | + def test_even_though_an_ace_is_usually_high_a_5_high_straight_flush_is_the_lowest_scoring_straight_flush |
| 210 | + skip |
| 211 | + hands = [%w[2H 3H 4H 5H 6H], %w[4D AD 3D 2D 5D]] |
| 212 | + assert_equal [%w[2H 3H 4H 5H 6H]], Poker.new(hands).best_hand |
195 | 213 | end
|
196 | 214 | end
|
0 commit comments