This repository was archived by the owner on Jun 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.elm
More file actions
175 lines (137 loc) · 3.34 KB
/
Copy pathTests.elm
File metadata and controls
175 lines (137 loc) · 3.34 KB
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
module Tests exposing (..)
import Basics exposing (Order(..))
import Expect
import Test exposing (..)
type alias PokerHand =
( String, String, String, String, String )
type HandRank
= HighCard CardValue
type CardValue
= C2
| C3
| C4
| C5
| C6
| C7
| C8
| C9
| CT
| CJ
| CQ
| CK
| CA
cardValue : String -> CardValue
cardValue card =
case String.left 1 card of
"2" ->
C2
"3" ->
C3
"4" ->
C4
"5" ->
C5
"6" ->
C6
"7" ->
C7
"8" ->
C8
"9" ->
C9
"T" ->
CT
"J" ->
CJ
"Q" ->
CQ
"K" ->
CK
"A" ->
CA
_ ->
CQ
handRank : PokerHand -> HandRank
handRank hand =
case hand of
( _, _, _, q, _ ) ->
HighCard (cardValue q)
cardValueComparator c1 c2 =
if c1 == c2 then
EQ
else
case ( c1, c2 ) of
( C2, _ ) ->
LT
( C3, C2 ) ->
GT
( C3, _ ) ->
LT
( C4, C2 ) ->
GT
( C4, C3 ) ->
GT
( C4, _ ) ->
LT
_ ->
GT
all : Test
all =
describe "Poker"
[ describe "cardValueComparator" <|
List.map testCardValueCompare
[ ( C2, EQ, C2 )
, ( C2, LT, C3 )
, ( C3, GT, C2 )
, ( C3, EQ, C3 )
, ( C3, LT, C4 )
, ( C3, LT, C5 )
, ( C4, GT, C2 )
, ( C4, LT, C5 )
]
, describe "cardValue" <|
List.map testCardValue
[ ( "2S", C2 )
, ( "3S", C3 )
, ( "4S", C4 )
, ( "5S", C5 )
, ( "6S", C6 )
, ( "7S", C7 )
, ( "8C", C8 )
, ( "9S", C9 )
, ( "TS", CT )
, ( "JS", CJ )
, ( "QS", CQ )
, ( "KS", CK )
, ( "AS", CA )
]
, describe "HandRank"
[ test "HighCard 9" <|
\_ ->
Expect.equal (HighCard C9)
(handRank ( "2H", "3D", "5S", "9C", "8D" ))
, test "HighCard QC" <|
\_ ->
Expect.equal (HighCard CQ)
(handRank ( "2H", "3D", "5S", "QC", "8D" ))
, test "HighCard QH" <|
\_ ->
Expect.equal (HighCard CQ)
(handRank ( "2H", "3D", "5S", "QH", "8D" ))
, test "HighCard K" <|
\_ ->
Expect.equal (HighCard CK)
(handRank ( "2H", "3D", "QC", "KS", "8D" ))
]
]
testCardValue : ( String, CardValue ) -> Test
testCardValue ( card, value ) =
test card <|
\_ ->
Expect.equal value
(cardValue card)
testCardValueCompare ( c1, operator, c2 ) =
test (String.join " " [ toString c1, toString c2 ]) <|
\_ ->
Expect.equal operator
(cardValueComparator c1 c2)