1
exercism fetch fsharp poker

PokerTest.fs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// This file was auto-generated based on version 1.0.0 of the canonical data.

module PokerTest

open FsUnit.Xunit
open Xunit

open Poker

[<Fact>]
let ``Single hand always wins`` () =
    let input = ["4S 5S 7H 8D JC"]
    let expected = ["4S 5S 7H 8D JC"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Highest card out of all hands wins`` () =
    let input = ["4D 5S 6S 8D 3C"; "2S 4C 7S 9H 10H"; "3S 4S 5D 6H JH"]
    let expected = ["3S 4S 5D 6H JH"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``A tie has multiple winners`` () =
    let input = ["4D 5S 6S 8D 3C"; "2S 4C 7S 9H 10H"; "3S 4S 5D 6H JH"; "3H 4H 5C 6C JD"]
    let expected = ["3S 4S 5D 6H JH"; "3H 4H 5C 6C JD"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Multiple hands with the same high cards, tie compares next highest ranked, down to last card`` () =
    let input = ["3S 5H 6S 8D 7H"; "2S 5D 6D 8C 7S"]
    let expected = ["3S 5H 6S 8D 7H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``One pair beats high card`` () =
    let input = ["4S 5H 6C 8D KH"; "2S 4H 6S 4D JH"]
    let expected = ["2S 4H 6S 4D JH"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Highest pair wins`` () =
    let input = ["4S 2H 6S 2D JH"; "2S 4H 6C 4D JD"]
    let expected = ["2S 4H 6C 4D JD"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Two pairs beats one pair`` () =
    let input = ["2S 8H 6S 8D JH"; "4S 5H 4C 8C 5C"]
    let expected = ["4S 5H 4C 8C 5C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have two pairs, highest ranked pair wins`` () =
    let input = ["2S 8H 2D 8D 3H"; "4S 5H 4C 8S 5D"]
    let expected = ["2S 8H 2D 8D 3H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have two pairs, with the same highest ranked pair, tie goes to low pair`` () =
    let input = ["2S QS 2C QD JH"; "JD QH JS 8D QC"]
    let expected = ["JD QH JS 8D QC"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have two identically ranked pairs, tie goes to remaining card (kicker)`` () =
    let input = ["JD QH JS 8D QC"; "JS QS JC 2D QD"]
    let expected = ["JD QH JS 8D QC"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Three of a kind beats two pair`` () =
    let input = ["2S 8H 2H 8D JH"; "4S 5H 4C 8S 4H"]
    let expected = ["4S 5H 4C 8S 4H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have three of a kind, tie goes to highest ranked triplet`` () =
    let input = ["2S 2H 2C 8D JH"; "4S AH AS 8C AD"]
    let expected = ["4S AH AS 8C AD"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``With multiple decks, two players can have same three of a kind, ties go to highest remaining cards`` () =
    let input = ["4S AH AS 7C AD"; "4S AH AS 8C AD"]
    let expected = ["4S AH AS 8C AD"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``A straight beats three of a kind`` () =
    let input = ["4S 5H 4C 8D 4H"; "3S 4D 2S 6D 5C"]
    let expected = ["3S 4D 2S 6D 5C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Aces can end a straight (10 J Q K A)`` () =
    let input = ["4S 5H 4C 8D 4H"; "10D JH QS KD AC"]
    let expected = ["10D JH QS KD AC"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Aces can start a straight (A 2 3 4 5)`` () =
    let input = ["4S 5H 4C 8D 4H"; "4D AH 3S 2D 5C"]
    let expected = ["4D AH 3S 2D 5C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands with a straight, tie goes to highest ranked card`` () =
    let input = ["4S 6C 7S 8D 5H"; "5S 7H 8S 9D 6H"]
    let expected = ["5S 7H 8S 9D 6H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Even though an ace is usually high, a 5-high straight is the lowest-scoring straight`` () =
    let input = ["2H 3C 4D 5D 6H"; "4S AH 3S 2D 5H"]
    let expected = ["2H 3C 4D 5D 6H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Flush beats a straight`` () =
    let input = ["4C 6H 7D 8D 5H"; "2S 4S 5S 6S 7S"]
    let expected = ["2S 4S 5S 6S 7S"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have a flush, tie goes to high card, down to the last one if necessary`` () =
    let input = ["4H 7H 8H 9H 6H"; "2S 4S 5S 6S 7S"]
    let expected = ["4H 7H 8H 9H 6H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Full house beats a flush`` () =
    let input = ["3H 6H 7H 8H 5H"; "4S 5H 4C 5D 4H"]
    let expected = ["4S 5H 4C 5D 4H"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have a full house, tie goes to highest-ranked triplet`` () =
    let input = ["4H 4S 4D 9S 9D"; "5H 5S 5D 8S 8D"]
    let expected = ["5H 5S 5D 8S 8D"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``With multiple decks, both hands have a full house with the same triplet, tie goes to the pair`` () =
    let input = ["5H 5S 5D 9S 9D"; "5H 5S 5D 8S 8D"]
    let expected = ["5H 5S 5D 9S 9D"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Four of a kind beats a full house`` () =
    let input = ["4S 5H 4D 5D 4H"; "3S 3H 2S 3D 3C"]
    let expected = ["3S 3H 2S 3D 3C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have four of a kind, tie goes to high quad`` () =
    let input = ["2S 2H 2C 8D 2D"; "4S 5H 5S 5D 5C"]
    let expected = ["4S 5H 5S 5D 5C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``With multiple decks, both hands with identical four of a kind, tie determined by kicker`` () =
    let input = ["3S 3H 2S 3D 3C"; "3S 3H 4S 3D 3C"]
    let expected = ["3S 3H 4S 3D 3C"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Straight flush beats four of a kind`` () =
    let input = ["4S 5H 5S 5D 5C"; "7S 8S 9S 6S 10S"]
    let expected = ["7S 8S 9S 6S 10S"]
    bestHands input |> should equal expected

[<Fact(Skip = "Remove to run test")>]
let ``Both hands have straight flush, tie goes to highest-ranked card`` () =
    let input = ["4H 6H 7H 8H 5H"; "5S 7S 8S 9S 6S"]
    let expected = ["5S 7S 8S 9S 6S"]
    bestHands input |> should equal expected