Skip to content

Commit 724cafd

Browse files
authored
Update tests poker (#2763)
1 parent 702e805 commit 724cafd

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"lpizzinidev"
44
],
5+
"contributors": [
6+
"jagdish-15"
7+
],
58
"files": {
69
"solution": [
710
"poker.js"

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/poker.spec.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ describe('Poker', () => {
3131
expect(bestHands(hands)).toEqual(expected);
3232
});
3333

34+
xtest('winning high card hand also has the lowest card', () => {
35+
const hands = ['2S 5H 6S 8D 7H', '3S 4D 6D 8C 7S'];
36+
const expected = ['2S 5H 6S 8D 7H'];
37+
expect(bestHands(hands)).toEqual(expected);
38+
});
39+
3440
xtest('one pair beats high card', () => {
3541
const hands = ['4S 5H 6C 8D KH', '2S 4H 6S 4D JH'];
3642
const expected = ['2S 4H 6S 4D JH'];
@@ -43,6 +49,12 @@ describe('Poker', () => {
4349
expect(bestHands(hands)).toEqual(expected);
4450
});
4551

52+
xtest('both hands have the same pair, high card wins', () => {
53+
const hands = ['4H 4S AH JC 3D', '4C 4D AS 5D 6C'];
54+
const expected = ['4H 4S AH JC 3D'];
55+
expect(bestHands(hands)).toEqual(expected);
56+
});
57+
4658
xtest('two pairs beats one pair', () => {
4759
const hands = ['2S 8H 6S 8D JH', '4S 5H 4C 8C 5C'];
4860
const expected = ['4S 5H 4C 8C 5C'];
@@ -67,6 +79,18 @@ describe('Poker', () => {
6779
expect(bestHands(hands)).toEqual(expected);
6880
});
6981

82+
xtest('both hands have two pairs that add to the same value, win goes to highest pair', () => {
83+
const hands = ['6S 6H 3S 3H AS', '7H 7S 2H 2S AC'];
84+
const expected = ['7H 7S 2H 2S AC'];
85+
expect(bestHands(hands)).toEqual(expected);
86+
});
87+
88+
xtest('two pairs first ranked by largest pair', () => {
89+
const hands = ['5C 2S 5S 4H 4C', '6S 2S 6H 7C 2C'];
90+
const expected = ['6S 2S 6H 7C 2C'];
91+
expect(bestHands(hands)).toEqual(expected);
92+
});
93+
7094
xtest('three of a kind beats two pair', () => {
7195
const hands = ['2S 8H 2H 8D JH', '4S 5H 4C 8S 4H'];
7296
const expected = ['4S 5H 4C 8S 4H'];
@@ -80,7 +104,7 @@ describe('Poker', () => {
80104
});
81105

82106
xtest('with multiple decks, two players can have same three of a kind, ties go to highest remaining cards', () => {
83-
const hands = ['4S AH AS 7C AD', '4S AH AS 8C AD'];
107+
const hands = ['5S AH AS 7C AD', '4S AH AS 8C AD'];
84108
const expected = ['4S AH AS 8C AD'];
85109
expect(bestHands(hands)).toEqual(expected);
86110
});
@@ -103,6 +127,12 @@ describe('Poker', () => {
103127
expect(bestHands(hands)).toEqual(expected);
104128
});
105129

130+
xtest('aces cannot be in the middle of a straight (Q K A 2 3)', () => {
131+
const hands = ['2C 3D 7H 5H 2S', 'QS KH AC 2D 3S'];
132+
const expected = ['2C 3D 7H 5H 2S'];
133+
expect(bestHands(hands)).toEqual(expected);
134+
});
135+
106136
xtest('both hands with a straight, tie goes to highest ranked card', () => {
107137
const hands = ['4S 6C 7S 8D 5H', '5S 7H 8S 9D 6H'];
108138
const expected = ['5S 7H 8S 9D 6H'];
@@ -122,8 +152,8 @@ describe('Poker', () => {
122152
});
123153

124154
xtest('both hands have a flush, tie goes to high card, down to the last one if necessary', () => {
125-
const hands = ['4H 7H 8H 9H 6H', '2S 4S 5S 6S 7S'];
126-
const expected = ['4H 7H 8H 9H 6H'];
155+
const hands = ['2H 7H 8H 9H 6H', '3S 5S 6S 7S 8S'];
156+
const expected = ['2H 7H 8H 9H 6H'];
127157
expect(bestHands(hands)).toEqual(expected);
128158
});
129159

@@ -169,9 +199,33 @@ describe('Poker', () => {
169199
expect(bestHands(hands)).toEqual(expected);
170200
});
171201

202+
xtest('aces can end a straight flush (10 J Q K A)', () => {
203+
const hands = ['KC AH AS AD AC', '10C JC QC KC AC'];
204+
const expected = ['10C JC QC KC AC'];
205+
expect(bestHands(hands)).toEqual(expected);
206+
});
207+
208+
xtest('aces can start a straight flush (A 2 3 4 5)', () => {
209+
const hands = ['KS AH AS AD AC', '4H AH 3H 2H 5H'];
210+
const expected = ['4H AH 3H 2H 5H'];
211+
expect(bestHands(hands)).toEqual(expected);
212+
});
213+
214+
xtest('aces cannot be in the middle of a straight flush (Q K A 2 3)', () => {
215+
const hands = ['2C AC QC 10C KC', 'QH KH AH 2H 3H'];
216+
const expected = ['2C AC QC 10C KC'];
217+
expect(bestHands(hands)).toEqual(expected);
218+
});
219+
172220
xtest('both hands have straight flush, tie goes to highest-ranked card', () => {
173221
const hands = ['4H 6H 7H 8H 5H', '5S 7S 8S 9S 6S'];
174222
const expected = ['5S 7S 8S 9S 6S'];
175223
expect(bestHands(hands)).toEqual(expected);
176224
});
225+
226+
xtest('even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush', () => {
227+
const hands = ['2H 3H 4H 5H 6H', '4D AD 3D 2D 5D'];
228+
const expected = ['2H 3H 4H 5H 6H'];
229+
expect(bestHands(hands)).toEqual(expected);
230+
});
177231
});

0 commit comments

Comments
 (0)