|
@@ -2,6 +2,7 @@ import org.junit.Ignore;
|
2
|
2
|
import org.junit.Test;
|
3
|
3
|
|
4
|
4
|
import java.util.Arrays;
|
|
5
|
+import java.util.Collections;
|
5
|
6
|
|
6
|
7
|
import static org.junit.Assert.assertEquals;
|
7
|
8
|
|
|
@@ -9,99 +10,174 @@ public class PokerTest {
|
9
|
10
|
@Test
|
10
|
11
|
public void oneHand() {
|
11
|
12
|
String hand = "4S 5S 7H 8D JC";
|
12
|
|
- assertEquals(Arrays.asList(hand), new Poker(Arrays.asList(hand)).getBestHands());
|
|
13
|
+ assertEquals(Collections.singletonList(hand), new Poker(Collections.singletonList(hand)).getBestHands());
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ @Ignore("Remove to run test")
|
|
17
|
+ @Test
|
|
18
|
+ public void highestCardWins() {
|
|
19
|
+ String highest8 = "4D 5S 6S 8D 3C";
|
|
20
|
+ String highest10 = "2S 4C 7S 9H 10H";
|
|
21
|
+ String highestJ = "3S 4S 5D 6H JH";
|
|
22
|
+ assertEquals(Collections.singletonList(highestJ), new Poker(Arrays.asList(highest8, highest10, highestJ)).getBestHands());
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ @Ignore("Remove to run test")
|
|
26
|
+ @Test
|
|
27
|
+ public void tieHasMultipleWinners() {
|
|
28
|
+ String highest8 = "4D 5S 6S 8D 3C";
|
|
29
|
+ String highest10 = "2S 4C 7S 9H 10H";
|
|
30
|
+ String highestJh = "3S 4S 5D 6H JH";
|
|
31
|
+ String highestJd = "3H 4H 5C 6C JD";
|
|
32
|
+ assertEquals(Arrays.asList(highestJh, highestJd),
|
|
33
|
+ new Poker(Arrays.asList(highest8, highest10, highestJh, highestJd)).getBestHands());
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ @Ignore("Remove to run test")
|
|
37
|
+ @Test
|
|
38
|
+ public void sameHighCards() {
|
|
39
|
+ String nextHighest3 = "3S 5H 6S 8D 7H";
|
|
40
|
+ String nextHighest2 = "2S 5D 6D 8C 7S";
|
|
41
|
+ assertEquals(Collections.singletonList(nextHighest3), new Poker(Arrays.asList(nextHighest3, nextHighest2)).getBestHands());
|
13
|
42
|
}
|
14
|
43
|
|
15
|
44
|
@Ignore("Remove to run test")
|
16
|
45
|
@Test
|
17
|
46
|
public void nothingVsOnePair() {
|
18
|
|
- String nothing = "4S 5H 6S 8D JH";
|
|
47
|
+ String nothing = "4S 5H 6C 8D KH";
|
19
|
48
|
String pairOf4 = "2S 4H 6S 4D JH";
|
20
|
|
- assertEquals(Arrays.asList(pairOf4), new Poker(Arrays.asList(nothing, pairOf4)).getBestHands());
|
|
49
|
+ assertEquals(Collections.singletonList(pairOf4), new Poker(Arrays.asList(nothing, pairOf4)).getBestHands());
|
21
|
50
|
}
|
22
|
51
|
|
23
|
52
|
@Ignore("Remove to run test")
|
24
|
53
|
@Test
|
25
|
54
|
public void twoPairs() {
|
26
|
55
|
String pairOf2 = "4S 2H 6S 2D JH";
|
27
|
|
- String pairOf4 = "2S 4H 6S 4D JH";
|
28
|
|
- assertEquals(Arrays.asList(pairOf4), new Poker(Arrays.asList(pairOf2, pairOf4)).getBestHands());
|
|
56
|
+ String pairOf4 = "2S 4H 6C 4D JD";
|
|
57
|
+ assertEquals(Collections.singletonList(pairOf4), new Poker(Arrays.asList(pairOf2, pairOf4)).getBestHands());
|
29
|
58
|
}
|
30
|
59
|
|
31
|
60
|
@Ignore("Remove to run test")
|
32
|
61
|
@Test
|
33
|
62
|
public void onePairVsDoublePair() {
|
34
|
63
|
String pairOf8 = "2S 8H 6S 8D JH";
|
35
|
|
- String doublePair = "4S 5H 4S 8D 5H";
|
36
|
|
- assertEquals(Arrays.asList(doublePair), new Poker(Arrays.asList(pairOf8, doublePair)).getBestHands());
|
|
64
|
+ String doublePair = "4S 5H 4C 8C 5C";
|
|
65
|
+ assertEquals(Collections.singletonList(doublePair), new Poker(Arrays.asList(pairOf8, doublePair)).getBestHands());
|
37
|
66
|
}
|
38
|
67
|
|
39
|
68
|
@Ignore("Remove to run test")
|
40
|
69
|
@Test
|
41
|
70
|
public void twoDoublePairs() {
|
42
|
|
- String doublePair2And8 = "2S 8H 2S 8D JH";
|
43
|
|
- String doublePair4And5 = "4S 5H 4S 8D 5H";
|
44
|
|
- assertEquals(Arrays.asList(doublePair2And8), new Poker(Arrays.asList(doublePair2And8, doublePair4And5)).getBestHands());
|
|
71
|
+ String doublePair2And8 = "2S 8H 2D 8D 3H";
|
|
72
|
+ String doublePair4And5 = "4S 5H 4C 8S 5D";
|
|
73
|
+ assertEquals(Collections.singletonList(doublePair2And8),
|
|
74
|
+ new Poker(Arrays.asList(doublePair2And8, doublePair4And5)).getBestHands());
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ @Ignore("Remove to run test")
|
|
78
|
+ @Test
|
|
79
|
+ public void sameHighestPair() {
|
|
80
|
+ String doublePair2AndQ = "2S QS 2C QD JH";
|
|
81
|
+ String doublePairJAndQ = "JD QH JS 8D QC";
|
|
82
|
+ assertEquals(Collections.singletonList(doublePairJAndQ),
|
|
83
|
+ new Poker(Arrays.asList(doublePairJAndQ, doublePair2AndQ)).getBestHands());
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ @Ignore("Remove to run test")
|
|
87
|
+ @Test
|
|
88
|
+ public void identicallyRankedPairs() {
|
|
89
|
+ String kicker8 = "JD QH JS 8D QC";
|
|
90
|
+ String kicker2 = "JS QS JC 2D QD";
|
|
91
|
+ assertEquals(Collections.singletonList(kicker8), new Poker(Arrays.asList(kicker8, kicker2)).getBestHands());
|
45
|
92
|
}
|
46
|
93
|
|
47
|
94
|
@Ignore("Remove to run test")
|
48
|
95
|
@Test
|
49
|
96
|
public void doublePairVsThree() {
|
50
|
|
- String doublePair2And8 = "2S 8H 2S 8D JH";
|
51
|
|
- String threeOf4 = "4S 5H 4S 8D 4H";
|
52
|
|
- assertEquals(Arrays.asList(threeOf4), new Poker(Arrays.asList(doublePair2And8, threeOf4)).getBestHands());
|
|
97
|
+ String doublePair2And8 = "2S 8H 2H 8D JH";
|
|
98
|
+ String threeOf4 = "4S 5H 4C 8S 4H";
|
|
99
|
+ assertEquals(Collections.singletonList(threeOf4), new Poker(Arrays.asList(doublePair2And8, threeOf4)).getBestHands());
|
53
|
100
|
}
|
54
|
101
|
|
55
|
102
|
@Ignore("Remove to run test")
|
56
|
103
|
@Test
|
57
|
104
|
public void twoThrees() {
|
58
|
|
- String threeOf2 = "2S 2H 2S 8D JH";
|
59
|
|
- String threeOf1 = "4S AH AS 8D AH";
|
60
|
|
- assertEquals(Arrays.asList(threeOf1), new Poker(Arrays.asList(threeOf2, threeOf1)).getBestHands());
|
|
105
|
+ String threeOf2 = "2S 2H 2C 8D JH";
|
|
106
|
+ String threeOf1 = "4S AH AS 8C AD";
|
|
107
|
+ assertEquals(Collections.singletonList(threeOf1), new Poker(Arrays.asList(threeOf2, threeOf1)).getBestHands());
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Ignore("Remove to run test")
|
|
111
|
+ @Test
|
|
112
|
+ public void sameThreesMultipleDecks() {
|
|
113
|
+ String remainingCard7 = "4S AH AS 7C AD";
|
|
114
|
+ String remainingCard8 = "4S AH AS 8C AD";
|
|
115
|
+ assertEquals(Collections.singletonList(remainingCard8),
|
|
116
|
+ new Poker(Arrays.asList(remainingCard7, remainingCard8)).getBestHands());
|
61
|
117
|
}
|
62
|
118
|
|
63
|
119
|
@Ignore("Remove to run test")
|
64
|
120
|
@Test
|
65
|
121
|
public void threeVsStraight() {
|
66
|
|
- String threeOf4 = "4S 5H 4S 8D 4H";
|
67
|
|
- String straight = "3S 4H 2S 6D 5H";
|
68
|
|
- assertEquals(Arrays.asList(straight), new Poker(Arrays.asList(threeOf4, straight)).getBestHands());
|
|
122
|
+ String threeOf4 = "4S 5H 4C 8D 4H";
|
|
123
|
+ String straight = "3S 4D 2S 6D 5C";
|
|
124
|
+ assertEquals(Collections.singletonList(straight), new Poker(Arrays.asList(threeOf4, straight)).getBestHands());
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ @Ignore("Remove to run test")
|
|
128
|
+ @Test
|
|
129
|
+ public void AcesCanEndAStraight() {
|
|
130
|
+ String hand = "4S 5H 4C 8D 4H";
|
|
131
|
+ String straightEndsA = "10D JH QS KD AC";
|
|
132
|
+ assertEquals(Collections.singletonList(straightEndsA), new Poker(Arrays.asList(hand, straightEndsA)).getBestHands());
|
|
133
|
+ }
|
|
134
|
+
|
|
135
|
+ @Ignore("Remove to run test")
|
|
136
|
+ @Test
|
|
137
|
+ public void AcesCanStartAStraight() {
|
|
138
|
+ String hand = "4S 5H 4C 8D 4H";
|
|
139
|
+ String straightStartA = "4D AH 3S 2D 5C";
|
|
140
|
+ assertEquals(Collections.singletonList(straightStartA), new Poker(Arrays.asList(hand, straightStartA)).getBestHands());
|
69
|
141
|
}
|
70
|
142
|
|
71
|
143
|
@Ignore("Remove to run test")
|
72
|
144
|
@Test
|
73
|
145
|
public void twoStraights() {
|
74
|
|
- String straightTo8 = "4S 6H 7S 8D 5H";
|
|
146
|
+ String straightTo8 = "4S 6C 7S 8D 5H";
|
75
|
147
|
String straightTo9 = "5S 7H 8S 9D 6H";
|
76
|
|
- assertEquals(Arrays.asList(straightTo9), new Poker(Arrays.asList(straightTo8, straightTo9)).getBestHands());
|
|
148
|
+ assertEquals(Collections.singletonList(straightTo9), new Poker(Arrays.asList(straightTo8, straightTo9)).getBestHands());
|
|
149
|
+ }
|
77
|
150
|
|
78
|
|
- String straightTo1 = "AS QH KS TD JH";
|
79
|
|
- String straightTo5 = "4S AH 3S 2D 5H";
|
80
|
|
- assertEquals(Arrays.asList(straightTo1), new Poker(Arrays.asList(straightTo1, straightTo5)).getBestHands());
|
|
151
|
+ @Ignore("Remove to run test")
|
|
152
|
+ @Test
|
|
153
|
+ public void theLowestStraightStartsWithAce() {
|
|
154
|
+ String straight = "2H 3C 4D 5D 6H";
|
|
155
|
+ String straightStartA = "4S AH 3S 2D 5H";
|
|
156
|
+ assertEquals(Collections.singletonList(straight), new Poker(Arrays.asList(straight, straightStartA)).getBestHands());
|
81
|
157
|
}
|
82
|
158
|
|
83
|
159
|
@Ignore("Remove to run test")
|
84
|
160
|
@Test
|
85
|
161
|
public void straightVsFlush() {
|
86
|
|
- String straightTo8 = "4S 6H 7S 8D 5H";
|
|
162
|
+ String straightTo8 = "4C 6H 7D 8D 5H";
|
87
|
163
|
String flushTo7 = "2S 4S 5S 6S 7S";
|
88
|
|
- assertEquals(Arrays.asList(flushTo7), new Poker(Arrays.asList(straightTo8, flushTo7)).getBestHands());
|
|
164
|
+ assertEquals(Collections.singletonList(flushTo7), new Poker(Arrays.asList(straightTo8, flushTo7)).getBestHands());
|
89
|
165
|
}
|
90
|
166
|
|
91
|
167
|
@Ignore("Remove to run test")
|
92
|
168
|
@Test
|
93
|
169
|
public void twoFlushes() {
|
94
|
|
- String flushTo8 = "3H 6H 7H 8H 5H";
|
|
170
|
+ String flushTo8 = "4H 7H 8H 9H 6H";
|
95
|
171
|
String flushTo7 = "2S 4S 5S 6S 7S";
|
96
|
|
- assertEquals(Arrays.asList(flushTo8), new Poker(Arrays.asList(flushTo8, flushTo7)).getBestHands());
|
|
172
|
+ assertEquals(Collections.singletonList(flushTo8), new Poker(Arrays.asList(flushTo8, flushTo7)).getBestHands());
|
97
|
173
|
}
|
98
|
174
|
|
99
|
175
|
@Ignore("Remove to run test")
|
100
|
176
|
@Test
|
101
|
177
|
public void flushVsFull() {
|
102
|
178
|
String flushTo8 = "3H 6H 7H 8H 5H";
|
103
|
|
- String full = "4S 5H 4S 5D 4H";
|
104
|
|
- assertEquals(Arrays.asList(full), new Poker(Arrays.asList(full, flushTo8)).getBestHands());
|
|
179
|
+ String full = "4S 5H 4C 5D 4H";
|
|
180
|
+ assertEquals(Collections.singletonList(full), new Poker(Arrays.asList(full, flushTo8)).getBestHands());
|
105
|
181
|
}
|
106
|
182
|
|
107
|
183
|
@Ignore("Remove to run test")
|
|
@@ -109,55 +185,56 @@ public class PokerTest {
|
109
|
185
|
public void twoFulls() {
|
110
|
186
|
String fullOf4By9 = "4H 4S 4D 9S 9D";
|
111
|
187
|
String fullOf5By8 = "5H 5S 5D 8S 8D";
|
112
|
|
- assertEquals(Arrays.asList(fullOf5By8), new Poker(Arrays.asList(fullOf4By9, fullOf5By8)).getBestHands());
|
|
188
|
+ assertEquals(Collections.singletonList(fullOf5By8), new Poker(Arrays.asList(fullOf4By9, fullOf5By8)).getBestHands());
|
113
|
189
|
}
|
114
|
190
|
|
115
|
191
|
@Ignore("Remove to run test")
|
116
|
192
|
@Test
|
117
|
|
- public void fullVsSquare() {
|
118
|
|
- String full = "4S 5H 4S 5D 4H";
|
119
|
|
- String squareOf3 = "3S 3H 2S 3D 3H";
|
120
|
|
- assertEquals(Arrays.asList(squareOf3), new Poker(Arrays.asList(full, squareOf3)).getBestHands());
|
|
193
|
+ public void twoFullssameThripletMultipleDecks() {
|
|
194
|
+ String fullOf5By9 = "5H 5S 5D 9S 9D";
|
|
195
|
+ String fullOf5By8 = "5H 5S 5D 8S 8D";
|
|
196
|
+ assertEquals(Collections.singletonList(fullOf5By9), new Poker(Arrays.asList(fullOf5By9, fullOf5By8)).getBestHands());
|
121
|
197
|
}
|
122
|
198
|
|
123
|
199
|
@Ignore("Remove to run test")
|
124
|
200
|
@Test
|
125
|
|
- public void twoSquares() {
|
126
|
|
- String squareOf2 = "2S 2H 2S 8D 2H";
|
127
|
|
- String squareOf5 = "4S 5H 5S 5D 5H";
|
128
|
|
- assertEquals(Arrays.asList(squareOf5), new Poker(Arrays.asList(squareOf2, squareOf5)).getBestHands());
|
|
201
|
+ public void fullVsSquare() {
|
|
202
|
+ String full = "4S 5H 4D 5D 4H";
|
|
203
|
+ String squareOf3 = "3S 3H 2S 3D 3C";
|
|
204
|
+ assertEquals(Collections.singletonList(squareOf3), new Poker(Arrays.asList(full, squareOf3)).getBestHands());
|
129
|
205
|
}
|
130
|
206
|
|
131
|
207
|
@Ignore("Remove to run test")
|
132
|
208
|
@Test
|
133
|
|
- public void squareVsStraightFlush() {
|
134
|
|
- String squareOf5 = "4S 5H 5S 5D 5H";
|
135
|
|
- String straightFlushTo9 = "5S 7S 8S 9S 6S";
|
136
|
|
- assertEquals(Arrays.asList(straightFlushTo9), new Poker(Arrays.asList(squareOf5, straightFlushTo9)).getBestHands());
|
|
209
|
+ public void twoSquares() {
|
|
210
|
+ String squareOf2 = "2S 2H 2C 8D 2D";
|
|
211
|
+ String squareOf5 = "4S 5H 5S 5D 5C";
|
|
212
|
+ assertEquals(Collections.singletonList(squareOf5), new Poker(Arrays.asList(squareOf2, squareOf5)).getBestHands());
|
137
|
213
|
}
|
138
|
214
|
|
139
|
215
|
@Ignore("Remove to run test")
|
140
|
216
|
@Test
|
141
|
|
- public void twoStraightFlushes() {
|
142
|
|
- String straightFlushTo8 = "4H 6H 7H 8H 5H";
|
143
|
|
- String straightFlushTo9 = "5S 7S 8S 9S 6S";
|
144
|
|
- assertEquals(Arrays.asList(straightFlushTo9), new Poker(Arrays.asList(straightFlushTo8, straightFlushTo9)).getBestHands());
|
|
217
|
+ public void sameSquaresMultipleDecks() {
|
|
218
|
+ String kicker2 = "3S 3H 2S 3D 3C";
|
|
219
|
+ String kicker4 = "3S 3H 4S 3D 3C";
|
|
220
|
+ assertEquals(Collections.singletonList(kicker4), new Poker(Arrays.asList(kicker2, kicker4)).getBestHands());
|
145
|
221
|
}
|
146
|
222
|
|
147
|
223
|
@Ignore("Remove to run test")
|
148
|
224
|
@Test
|
149
|
|
- public void threeHandWithTie() {
|
150
|
|
- String spadeStraightTo9 = "9S 8S 7S 6S 5S";
|
151
|
|
- String diamondStraightTo9 = "9D 8D 7D 6D 5D";
|
152
|
|
- String threeOf4 = "4D 4S 4H QS KS";
|
153
|
|
- assertEquals(Arrays.asList(spadeStraightTo9, diamondStraightTo9), new Poker(Arrays.asList(spadeStraightTo9, diamondStraightTo9, threeOf4)).getBestHands());
|
|
225
|
+ public void squareVsStraightFlush() {
|
|
226
|
+ String squareOf5 = "4S 5H 5S 5D 5C";
|
|
227
|
+ String straightFlushTo9 = "7S 8S 9S 6S 10S";
|
|
228
|
+ assertEquals(Collections.singletonList(straightFlushTo9),
|
|
229
|
+ new Poker(Arrays.asList(squareOf5, straightFlushTo9)).getBestHands());
|
154
|
230
|
}
|
155
|
231
|
|
156
|
232
|
@Ignore("Remove to run test")
|
157
|
233
|
@Test
|
158
|
|
- public void straightTo5AgainstAPairOfJacks() {
|
159
|
|
- String straightTo5 = "2S 4D 5C 3S AS";
|
160
|
|
- String twoJacks = "JD 8D 7D JC 5D";
|
161
|
|
- assertEquals(Arrays.asList(straightTo5), new Poker(Arrays.asList(straightTo5, twoJacks)).getBestHands());
|
|
234
|
+ public void twoStraightFlushes() {
|
|
235
|
+ String straightFlushTo8 = "4H 6H 7H 8H 5H";
|
|
236
|
+ String straightFlushTo9 = "5S 7S 8S 9S 6S";
|
|
237
|
+ assertEquals(Collections.singletonList(straightFlushTo9),
|
|
238
|
+ new Poker(Arrays.asList(straightFlushTo8, straightFlushTo9)).getBestHands());
|
162
|
239
|
}
|
163
|
240
|
}
|