Skip to content

Commit ccb6fdf

Browse files
authored
Poker: Make high card tests more robust (#2336)
Ensure that high cards are checked in the correct order (high ranking cards down to low ranking cards). Tests previously succeeded even when comparing lowest ranking spare cards first (e.g. "3H JS" beats "2C 5H" even when comparing "3H" vs. "2C"). Two tests added to ensure hands with pairs and triplets of the same rank are checked for high cards down to the last card.
1 parent 9fcb1f1 commit ccb6fdf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

exercises/poker/canonical-data.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
},
4343
"expected": ["3S 5H 6S 8D 7H"]
4444
},
45+
{
46+
"uuid": "da01becd-f5b0-4342-b7f3-1318191d0580",
47+
"description": "winning high card hand also has the lowest card",
48+
"property": "bestHands",
49+
"input": {
50+
"hands": ["2S 5H 6S 8D 7H", "3S 4D 6D 8C 7S"]
51+
},
52+
"expected": ["2S 5H 6S 8D 7H"]
53+
},
4554
{
4655
"uuid": "f7175a89-34ff-44de-b3d7-f6fd97d1fca4",
4756
"description": "one pair beats high card",
@@ -60,6 +69,15 @@
6069
},
6170
"expected": ["2S 4H 6C 4D JD"]
6271
},
72+
{
73+
"uuid": "b3acd3a7-f9fa-4647-85ab-e0a9e07d1365",
74+
"description": "both hands have the same pair, high card wins",
75+
"property": "bestHands",
76+
"input": {
77+
"hands": ["4H 4S AH JC 3D", "4C 4D AS 5D 6C"]
78+
},
79+
"expected": ["4H 4S AH JC 3D"]
80+
},
6381
{
6482
"uuid": "935bb4dc-a622-4400-97fa-86e7d06b1f76",
6583
"description": "two pairs beats one pair",
@@ -141,6 +159,19 @@
141159
},
142160
"expected": ["4S AH AS 8C AD"]
143161
},
162+
{
163+
"uuid": "26a4a7d4-34a2-4f18-90b4-4a8dd35d2bb1",
164+
"reimplements": "eb856cc2-481c-4b0d-9835-4d75d07a5d9d",
165+
"description": "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards",
166+
"comments": [
167+
"Ensure that high cards are checked in the correct order (high to low)."
168+
],
169+
"property": "bestHands",
170+
"input": {
171+
"hands": ["5S AH AS 7C AD", "4S AH AS 8C AD"]
172+
},
173+
"expected": ["4S AH AS 8C AD"]
174+
},
144175
{
145176
"uuid": "a858c5d9-2f28-48e7-9980-b7fa04060a60",
146177
"description": "a straight beats three of a kind",
@@ -213,6 +244,19 @@
213244
},
214245
"expected": ["4H 7H 8H 9H 6H"]
215246
},
247+
{
248+
"uuid": "e04137c5-c19a-4dfc-97a1-9dfe9baaa2ff",
249+
"reimplements": "4d90261d-251c-49bd-a468-896bf10133de",
250+
"description": "both hands have a flush, tie goes to high card, down to the last one if necessary",
251+
"comments": [
252+
"Ensure that high cards are checked in the correct order (high to low)."
253+
],
254+
"property": "bestHands",
255+
"input": {
256+
"hands": ["2H 7H 8H 9H 6H", "3S 5S 6S 7S 8S"]
257+
},
258+
"expected": ["2H 7H 8H 9H 6H"]
259+
},
216260
{
217261
"uuid": "3a19361d-8974-455c-82e5-f7152f5dba7c",
218262
"description": "full house beats a flush",

0 commit comments

Comments
 (0)