Skip to content

Commit 447c97f

Browse files
committed
Updating tests for poker exercise
1 parent 109a4c2 commit 447c97f

File tree

3 files changed

+136
-10
lines changed

3 files changed

+136
-10
lines changed

exercises/practice/poker/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"aadityakulkarni",
77
"FridaTveit",
88
"hgvanpariya",
9+
"jagdish-15",
910
"jmrunkle",
1011
"katmpatz",
1112
"kytrinyx",

exercises/practice/poker/.meta/tests.toml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[161f485e-39c2-4012-84cf-bec0c755b66c]
613
description = "single hand always wins"
@@ -14,12 +21,18 @@ description = "a tie has multiple winners"
1421
[61ed83a9-cfaa-40a5-942a-51f52f0a8725]
1522
description = "multiple hands with the same high cards, tie compares next highest ranked, down to last card"
1623

24+
[da01becd-f5b0-4342-b7f3-1318191d0580]
25+
description = "winning high card hand also has the lowest card"
26+
1727
[f7175a89-34ff-44de-b3d7-f6fd97d1fca4]
1828
description = "one pair beats high card"
1929

2030
[e114fd41-a301-4111-a9e7-5a7f72a76561]
2131
description = "highest pair wins"
2232

33+
[b3acd3a7-f9fa-4647-85ab-e0a9e07d1365]
34+
description = "both hands have the same pair, high card wins"
35+
2336
[935bb4dc-a622-4400-97fa-86e7d06b1f76]
2437
description = "two pairs beats one pair"
2538

@@ -32,6 +45,12 @@ description = "both hands have two pairs, with the same highest ranked pair, tie
3245
[15a7a315-0577-47a3-9981-d6cf8e6f387b]
3346
description = "both hands have two identically ranked pairs, tie goes to remaining card (kicker)"
3447

48+
[f761e21b-2560-4774-a02a-b3e9366a51ce]
49+
description = "both hands have two pairs that add to the same value, win goes to highest pair"
50+
51+
[fc6277ac-94ac-4078-8d39-9d441bc7a79e]
52+
description = "two pairs first ranked by largest pair"
53+
3554
[21e9f1e6-2d72-49a1-a930-228e5e0195dc]
3655
description = "three of a kind beats two pair"
3756

@@ -40,6 +59,11 @@ description = "both hands have three of a kind, tie goes to highest ranked tripl
4059

4160
[eb856cc2-481c-4b0d-9835-4d75d07a5d9d]
4261
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"
62+
include = false
63+
64+
[26a4a7d4-34a2-4f18-90b4-4a8dd35d2bb1]
65+
description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards"
66+
reimplements = "eb856cc2-481c-4b0d-9835-4d75d07a5d9d"
4367

4468
[a858c5d9-2f28-48e7-9980-b7fa04060a60]
4569
description = "a straight beats three of a kind"
@@ -50,6 +74,9 @@ description = "aces can end a straight (10 J Q K A)"
5074
[76856b0d-35cd-49ce-a492-fe5db53abc02]
5175
description = "aces can start a straight (A 2 3 4 5)"
5276

77+
[e214b7df-dcba-45d3-a2e5-342d8c46c286]
78+
description = "aces cannot be in the middle of a straight (Q K A 2 3)"
79+
5380
[6980c612-bbff-4914-b17a-b044e4e69ea1]
5481
description = "both hands with a straight, tie goes to highest ranked card"
5582

@@ -61,6 +88,11 @@ description = "flush beats a straight"
6188

6289
[4d90261d-251c-49bd-a468-896bf10133de]
6390
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"
91+
include = false
92+
93+
[e04137c5-c19a-4dfc-97a1-9dfe9baaa2ff]
94+
description = "both hands have a flush, tie goes to high card, down to the last one if necessary"
95+
reimplements = "4d90261d-251c-49bd-a468-896bf10133de"
6496

6597
[3a19361d-8974-455c-82e5-f7152f5dba7c]
6698
description = "full house beats a flush"
@@ -83,5 +115,17 @@ description = "with multiple decks, both hands with identical four of a kind, ti
83115
[923bd910-dc7b-4f7d-a330-8b42ec10a3ac]
84116
description = "straight flush beats four of a kind"
85117

118+
[d9629e22-c943-460b-a951-2134d1b43346]
119+
description = "aces can end a straight flush (10 J Q K A)"
120+
121+
[05d5ede9-64a5-4678-b8ae-cf4c595dc824]
122+
description = "aces can start a straight flush (A 2 3 4 5)"
123+
124+
[ad655466-6d04-49e8-a50c-0043c3ac18ff]
125+
description = "aces cannot be in the middle of a straight flush (Q K A 2 3)"
126+
86127
[d0927f70-5aec-43db-aed8-1cbd1b6ee9ad]
87-
description = "both hands have straight flush, tie goes to highest-ranked card"
128+
description = "both hands have a straight flush, tie goes to highest-ranked card"
129+
130+
[be620e09-0397-497b-ac37-d1d7a4464cfc]
131+
description = "even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush"

exercises/practice/poker/src/test/java/PokerTest.java

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public void sameHighCards() {
4444
.containsExactly(nextHighest3);
4545
}
4646

47+
@Disabled("Remove to run test")
48+
@Test
49+
public void winningWithLowestCard() {
50+
String lowest2 = "2S 5H 6S 8D 7H";
51+
String lowest3 = "3S 4D 6D 8C 7S";
52+
assertThat(new Poker(Arrays.asList(lowest2, lowest3)).getBestHands())
53+
.containsExactly(lowest2);
54+
}
55+
4756
@Disabled("Remove to run test")
4857
@Test
4958
public void nothingVsOnePair() {
@@ -62,6 +71,15 @@ public void twoPairs() {
6271
.containsExactly(pairOf4);
6372
}
6473

74+
@Disabled("Remove to run test")
75+
@Test
76+
public void samePair() {
77+
String pairOf4Lower = "4H 4S AH JC 3D";
78+
String pairOf4Higher = "4C 4D AS 5D 6C";
79+
assertThat(new Poker(Arrays.asList(pairOf4Lower, pairOf4Higher)).getBestHands())
80+
.containsExactly(pairOf4Higher);
81+
}
82+
6583
@Disabled("Remove to run test")
6684
@Test
6785
public void onePairVsDoublePair() {
@@ -98,6 +116,24 @@ public void identicallyRankedPairs() {
98116
.containsExactly(kicker8);
99117
}
100118

119+
@Disabled("Remove to run test")
120+
@Test
121+
public void twoPairsAddingToSameValue() {
122+
String doublePair6And3 = "6S 6H 3S 3H AS";
123+
String doublePair7And2 = "7H 7S 2H 2S AC";
124+
assertThat(new Poker(Arrays.asList(doublePair6And3, doublePair7And2)).getBestHands())
125+
.containsExactly(doublePair7And2);
126+
}
127+
128+
@Disabled("Remove to run test")
129+
@Test
130+
public void rankedByLargestPair() {
131+
String doublePairs5And4 = "5C 2S 5S 4H 4C";
132+
String doublePairs6And2 = "6S 2S 6H 7C 2C";
133+
assertThat(new Poker(Arrays.asList(doublePairs5And4, doublePairs6And2)).getBestHands())
134+
.containsExactly(doublePairs6And2);
135+
}
136+
101137
@Disabled("Remove to run test")
102138
@Test
103139
public void doublePairVsThree() {
@@ -119,7 +155,7 @@ public void twoThrees() {
119155
@Disabled("Remove to run test")
120156
@Test
121157
public void sameThreesMultipleDecks() {
122-
String remainingCard7 = "4S AH AS 7C AD";
158+
String remainingCard7 = "5S AH AS 7C AD";
123159
String remainingCard8 = "4S AH AS 8C AD";
124160
assertThat(new Poker(Arrays.asList(remainingCard7, remainingCard8)).getBestHands())
125161
.containsExactly(remainingCard8);
@@ -152,6 +188,15 @@ public void acesCanStartAStraight() {
152188
.containsExactly(straightStartA);
153189
}
154190

191+
@Disabled("Remove to run test")
192+
@Test
193+
public void acesCannotBeInMiddleOfStraight() {
194+
String hand = "2C 3D 7H 5H 2S";
195+
String straightMiddleA = "QS KH AC 2D 3S";
196+
assertThat(new Poker(Arrays.asList(hand, straightMiddleA)).getBestHands())
197+
.containsExactly(hand);
198+
}
199+
155200
@Disabled("Remove to run test")
156201
@Test
157202
public void twoStraights() {
@@ -181,11 +226,11 @@ public void straightVsFlush() {
181226

182227
@Disabled("Remove to run test")
183228
@Test
184-
public void twoFlushes() {
185-
String flushTo8 = "4H 7H 8H 9H 6H";
186-
String flushTo7 = "2S 4S 5S 6S 7S";
187-
assertThat(new Poker(Arrays.asList(flushTo8, flushTo7)).getBestHands())
188-
.containsExactly(flushTo8);
229+
public void twoFlushs() {
230+
String flushTo9 = "2H 7H 8H 9H 6H";
231+
String flushTo7 = "3S 5S 6S 7S 8S";
232+
assertThat(new Poker(Arrays.asList(flushTo9, flushTo7)).getBestHands())
233+
.containsExactly(flushTo9);
189234
}
190235

191236
@Disabled("Remove to run test")
@@ -251,6 +296,33 @@ public void squareVsStraightFlush() {
251296
.containsExactly(straightFlushTo9);
252297
}
253298

299+
@Disabled("Remove to run test")
300+
@Test
301+
public void acesEndingStraightFlush() {
302+
String hand = "KC AH AS AD AC";
303+
String straightFlushEndingWithA = "10C JC QC KC AC";
304+
assertThat(new Poker(Arrays.asList(hand, straightFlushEndingWithA)).getBestHands())
305+
.containsExactly(straightFlushEndingWithA);
306+
}
307+
308+
@Disabled("Remove to run test")
309+
@Test
310+
public void acesStartingStraightFlush() {
311+
String straightFlushStartingWithA = "4H AH 3H 2H 5H";
312+
String hand = "KS AH AS AD AC";
313+
assertThat(new Poker(Arrays.asList(straightFlushStartingWithA, hand)).getBestHands())
314+
.containsExactly(straightFlushStartingWithA);
315+
}
316+
317+
@Disabled("Remove to run test")
318+
@Test
319+
public void acesCannotBeInMiddleOfStraightFlush() {
320+
String straightFlushWithAInMiddle = "QH KH AH 2H 3H";
321+
String hand = "2C AC QC 10C KC";
322+
assertThat(new Poker(Arrays.asList(straightFlushWithAInMiddle, hand)).getBestHands())
323+
.containsExactly(hand);
324+
}
325+
254326
@Disabled("Remove to run test")
255327
@Test
256328
public void twoStraightFlushes() {
@@ -259,4 +331,13 @@ public void twoStraightFlushes() {
259331
assertThat(new Poker(Arrays.asList(straightFlushTo8, straightFlushTo9)).getBestHands())
260332
.containsExactly(straightFlushTo9);
261333
}
334+
335+
@Disabled("Remove to run test")
336+
@Test
337+
public void straightFlushTo5IsTheLowestScoring() {
338+
String straightFlushTo6 = "2H 3H 4H 5H 6H";
339+
String straightFlushTo5 = "4D AD 3D 2D 5D";
340+
assertThat(new Poker(Arrays.asList(straightFlushTo6, straightFlushTo5)).getBestHands())
341+
.containsExactly(straightFlushTo6);
342+
}
262343
}

0 commit comments

Comments
 (0)