From 852213e9dda377c52cbaaa97a3d47284e6661a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Mon, 5 Jan 2026 17:45:57 -0800 Subject: [PATCH 1/2] Sync `poker` tests --- exercises/practice/poker/.meta/tests.toml | 33 +++++++++++++++- exercises/practice/poker/PokerTests.fs | 48 +++++++++++++++++++++-- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/exercises/practice/poker/.meta/tests.toml b/exercises/practice/poker/.meta/tests.toml index 27a1fad29..2e654ef63 100644 --- a/exercises/practice/poker/.meta/tests.toml +++ b/exercises/practice/poker/.meta/tests.toml @@ -21,12 +21,18 @@ description = "a tie has multiple winners" [61ed83a9-cfaa-40a5-942a-51f52f0a8725] description = "multiple hands with the same high cards, tie compares next highest ranked, down to last card" +[da01becd-f5b0-4342-b7f3-1318191d0580] +description = "winning high card hand also has the lowest card" + [f7175a89-34ff-44de-b3d7-f6fd97d1fca4] description = "one pair beats high card" [e114fd41-a301-4111-a9e7-5a7f72a76561] description = "highest pair wins" +[b3acd3a7-f9fa-4647-85ab-e0a9e07d1365] +description = "both hands have the same pair, high card wins" + [935bb4dc-a622-4400-97fa-86e7d06b1f76] description = "two pairs beats one pair" @@ -53,6 +59,11 @@ description = "both hands have three of a kind, tie goes to highest ranked tripl [eb856cc2-481c-4b0d-9835-4d75d07a5d9d] description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards" +include = false + +[26a4a7d4-34a2-4f18-90b4-4a8dd35d2bb1] +description = "with multiple decks, two players can have same three of a kind, ties go to highest remaining cards" +reimplements = "eb856cc2-481c-4b0d-9835-4d75d07a5d9d" [a858c5d9-2f28-48e7-9980-b7fa04060a60] description = "a straight beats three of a kind" @@ -63,6 +74,9 @@ description = "aces can end a straight (10 J Q K A)" [76856b0d-35cd-49ce-a492-fe5db53abc02] description = "aces can start a straight (A 2 3 4 5)" +[e214b7df-dcba-45d3-a2e5-342d8c46c286] +description = "aces cannot be in the middle of a straight (Q K A 2 3)" + [6980c612-bbff-4914-b17a-b044e4e69ea1] description = "both hands with a straight, tie goes to highest ranked card" @@ -74,6 +88,11 @@ description = "flush beats a straight" [4d90261d-251c-49bd-a468-896bf10133de] description = "both hands have a flush, tie goes to high card, down to the last one if necessary" +include = false + +[e04137c5-c19a-4dfc-97a1-9dfe9baaa2ff] +description = "both hands have a flush, tie goes to high card, down to the last one if necessary" +reimplements = "4d90261d-251c-49bd-a468-896bf10133de" [3a19361d-8974-455c-82e5-f7152f5dba7c] description = "full house beats a flush" @@ -96,5 +115,17 @@ description = "with multiple decks, both hands with identical four of a kind, ti [923bd910-dc7b-4f7d-a330-8b42ec10a3ac] description = "straight flush beats four of a kind" +[d9629e22-c943-460b-a951-2134d1b43346] +description = "aces can end a straight flush (10 J Q K A)" + +[05d5ede9-64a5-4678-b8ae-cf4c595dc824] +description = "aces can start a straight flush (A 2 3 4 5)" + +[ad655466-6d04-49e8-a50c-0043c3ac18ff] +description = "aces cannot be in the middle of a straight flush (Q K A 2 3)" + [d0927f70-5aec-43db-aed8-1cbd1b6ee9ad] -description = "both hands have straight flush, tie goes to highest-ranked card" +description = "both hands have a straight flush, tie goes to highest-ranked card" + +[be620e09-0397-497b-ac37-d1d7a4464cfc] +description = "even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush" diff --git a/exercises/practice/poker/PokerTests.fs b/exercises/practice/poker/PokerTests.fs index 3140520f2..070bc223f 100644 --- a/exercises/practice/poker/PokerTests.fs +++ b/exercises/practice/poker/PokerTests.fs @@ -29,6 +29,12 @@ let ``Multiple hands with the same high cards, tie compares next highest ranked, let expected = ["3S 5H 6S 8D 7H"] bestHands hands |> should equal expected +[] +let ``Winning high card hand also has the lowest card`` () = + let hands = ["2S 5H 6S 8D 7H"; "3S 4D 6D 8C 7S"] + let expected = ["2S 5H 6S 8D 7H"] + bestHands hands |> should equal expected + [] let ``One pair beats high card`` () = let hands = ["4S 5H 6C 8D KH"; "2S 4H 6S 4D JH"] @@ -41,6 +47,12 @@ let ``Highest pair wins`` () = let expected = ["2S 4H 6C 4D JD"] bestHands hands |> should equal expected +[] +let ``Both hands have the same pair, high card wins`` () = + let hands = ["4H 4S AH JC 3D"; "4C 4D AS 5D 6C"] + let expected = ["4H 4S AH JC 3D"] + bestHands hands |> should equal expected + [] let ``Two pairs beats one pair`` () = let hands = ["2S 8H 6S 8D JH"; "4S 5H 4C 8C 5C"] @@ -91,7 +103,7 @@ let ``Both hands have three of a kind, tie goes to highest ranked triplet`` () = [] let ``With multiple decks, two players can have same three of a kind, ties go to highest remaining cards`` () = - let hands = ["4S AH AS 7C AD"; "4S AH AS 8C AD"] + let hands = ["5S AH AS 7C AD"; "4S AH AS 8C AD"] let expected = ["4S AH AS 8C AD"] bestHands hands |> should equal expected @@ -113,6 +125,12 @@ let ``Aces can start a straight (A 2 3 4 5)`` () = let expected = ["4D AH 3S 2D 5C"] bestHands hands |> should equal expected +[] +let ``Aces cannot be in the middle of a straight (Q K A 2 3)`` () = + let hands = ["2C 3D 7H 5H 2S"; "QS KH AC 2D 3S"] + let expected = ["2C 3D 7H 5H 2S"] + bestHands hands |> should equal expected + [] let ``Both hands with a straight, tie goes to highest ranked card`` () = let hands = ["4S 6C 7S 8D 5H"; "5S 7H 8S 9D 6H"] @@ -133,8 +151,8 @@ let ``Flush beats a straight`` () = [] let ``Both hands have a flush, tie goes to high card, down to the last one if necessary`` () = - let hands = ["4H 7H 8H 9H 6H"; "2S 4S 5S 6S 7S"] - let expected = ["4H 7H 8H 9H 6H"] + let hands = ["2H 7H 8H 9H 6H"; "3S 5S 6S 7S 8S"] + let expected = ["2H 7H 8H 9H 6H"] bestHands hands |> should equal expected [] @@ -179,9 +197,33 @@ let ``Straight flush beats four of a kind`` () = let expected = ["7S 8S 9S 6S 10S"] bestHands hands |> should equal expected +[] +let ``Aces can end a straight flush (10 J Q K A)`` () = + let hands = ["KC AH AS AD AC"; "10C JC QC KC AC"] + let expected = ["10C JC QC KC AC"] + bestHands hands |> should equal expected + +[] +let ``Aces can start a straight flush (A 2 3 4 5)`` () = + let hands = ["KS AH AS AD AC"; "4H AH 3H 2H 5H"] + let expected = ["4H AH 3H 2H 5H"] + bestHands hands |> should equal expected + +[] +let ``Aces cannot be in the middle of a straight flush (Q K A 2 3)`` () = + let hands = ["2C AC QC 10C KC"; "QH KH AH 2H 3H"] + let expected = ["2C AC QC 10C KC"] + bestHands hands |> should equal expected + [] let ``Both hands have a straight flush, tie goes to highest-ranked card`` () = let hands = ["4H 6H 7H 8H 5H"; "5S 7S 8S 9S 6S"] let expected = ["5S 7S 8S 9S 6S"] bestHands hands |> should equal expected +[] +let ``Even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush`` () = + let hands = ["2H 3H 4H 5H 6H"; "4D AD 3D 2D 5D"] + let expected = ["2H 3H 4H 5H 6H"] + bestHands hands |> should equal expected + From c6790498f62b8c201a3057a4bd4372f0df5f02ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Mon, 19 Jan 2026 15:12:49 -0800 Subject: [PATCH 2/2] Update example solution --- exercises/practice/poker/.meta/Example.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/poker/.meta/Example.fs b/exercises/practice/poker/.meta/Example.fs index 511aa0e1d..5aeec9561 100644 --- a/exercises/practice/poker/.meta/Example.fs +++ b/exercises/practice/poker/.meta/Example.fs @@ -124,7 +124,7 @@ let (|Straight|_|) hand = let (|StraightFlush|_|) hand = match hand with - | Flush _ & Straight _ -> ranks hand |> List.head |> PokerHand.StraightFlush |> Some + | Flush _ & Straight (PokerHand.Straight rank) -> PokerHand.StraightFlush rank |> Some | _ -> None let (|FourOfAKind|_|) hand =