-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard_test.go
371 lines (303 loc) · 8.45 KB
/
card_test.go
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package poker
import (
"testing"
)
func TestNewCard(t *testing.T) {
want := ACES & SPADES
got := NewCard("As")
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestQuitCards(t *testing.T) {
c := NewCard
cards := c("As") | c("Kc") | c("Ks") | c("3d")
cardsToQuit := c("3d") | c("5d")
want := c("As") | c("Kc") | c("Ks")
got := cards.QuitCards(cardsToQuit)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestOnes(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Kh") | c("2c") | c("3s") | c("4d") | c("5d")
want := 6
got := cards.Count()
if want != got {
t.Errorf("\nWant %d\nGot %d", want, got)
}
}
func TestMergeSuits(t *testing.T) {
c := NewCard
cards := c("As") | c("Kc") | c("Ks") | c("Jd")
want := (ACES | KINGS | JACKS) & FIRST_SUIT
got := cards.mergeSuits()
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestMergeSuits2(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Kh") | c("2c") | c("3s") | c("4d") | c("5d")
want := (ACES | KINGS | FIVES | FOURS | THREES | TWOS) & FIRST_SUIT
got := cards.mergeSuits()
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestReduceRepeatedNumber(t *testing.T) {
c := NewCard
cards := c("Kc") | c("Kh") | c("Kd") | c("Ks")
want := 2
cards = cards.reduceRepeatedNumber(2)
got := cards.Count()
if want != got {
t.Errorf("\nWant %d\nGot %d", want, got)
}
}
func TestQuitStraightRepeatedNumbers(t *testing.T) {
c := NewCard
cards := c("Kc") | c("Kh") | c("Ad") | c("Qs") | c("Td") | c("Js")
want := 5
cards = cards.quitStraightRepeatedNumbers()
got := cards.Count()
if want != got {
t.Errorf("\nWant %d\nGot %d", want, got)
}
}
func TestGetJustOneFlush(t *testing.T) {
c := NewCard
cards := c("Ah") | c("Kh") | c("Qh") | c("Jh") | c("Th") | c("Ad")
want := c("Ah") | c("Kh") | c("Qh") | c("Jh") | c("Th")
got := cards.getJustOneFlush()
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestGetFlushHighestNumbers(t *testing.T) {
c := NewCard
cards := c("Kh") | c("Qh") | c("Jh") | c("Th") | c("9h") | c("8h") | c("7h") | c("6h") | c("5h") | c("4h")
want := c("Kh") | c("Qh") | c("Jh") | c("Th") | c("9h")
got := cards.getFlushHighestNumbers()
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestHighCardAce(t *testing.T) {
c := NewCard
cards := c("As") | c("Kc")
want := c("As")
got, _ := HighCard(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestHighCardSeven(t *testing.T) {
c := NewCard
cards := c("2s") | c("7c")
want := c("7c")
got, _ := HighCard(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoPair(t *testing.T) {
c := NewCard
cards := c("As") | c("Kd") | c("Qc") | c("Jc") | c("Tc") | c("9c") | c("8c")
_, found := Pair(cards)
if found {
t.Errorf("\nLooking for a pair in %s\nWant found=false\nGot found=true", cards)
}
}
func TestPairAce(t *testing.T) {
c := NewCard
cards := c("As") | c("Kc") | c("Ac")
want := c("As") | c("Ac")
got, _ := Pair(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestPairSeven(t *testing.T) {
c := NewCard
cards := c("7s") | c("Kc") | c("7c")
want := c("7s") | c("7c")
got, _ := Pair(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoTwoPair(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Qc") | c("Jc") | c("Tc")
_, found := TwoPair(cards)
if found {
t.Errorf("\nLooking for a two pair in %s\nWant found=false\nGot found=true", cards)
}
}
func TestTwoPairAceSeven(t *testing.T) {
c := NewCard
cards := c("7s") | c("Kc") | c("7c") | c("As") | c("Ad")
want := c("7s") | c("7c") | c("As") | c("Ad")
got, _ := TwoPair(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoThreeOfAKind(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Qc") | c("Jc") | c("Tc")
_, found := ThreeOfAKind(cards)
if found {
t.Errorf("\nLooking for a three of a kind in %s\nWant found=false\nGot found=true", cards)
}
}
func TestThreeOfAKindAce(t *testing.T) {
c := NewCard
cards := c("Ah") | c("Kc") | c("7c") | c("As") | c("Ad")
want := c("Ah") | c("As") | c("Ad")
got, _ := ThreeOfAKind(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoStraight(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Qc") | c("Jc") | c("Tc")
_, found := Straight(cards)
if found {
t.Errorf("\nLooking for a straight in %s\nWant found=false\nGot found=true", cards)
}
}
func TestStraightToFive(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Kh") | c("2c") | c("3s") | c("4d") | c("5d")
want := c("5d") | c("4d") | c("3s") | c("2c") | c("Ac")
got, _ := Straight(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestStraightToTen(t *testing.T) {
c := NewCard
cards := c("Qh") | c("Tc") | c("9c") | c("8s") | c("7d") | c("6d")
want := c("Tc") | c("9c") | c("8s") | c("7d") | c("6d")
got, _ := Straight(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestStraightWithRepeatedCard(t *testing.T) {
c := NewCard
cards := c("8h") | c("9c") | c("8s") | c("7d") | c("6d") | c("5d")
want := 5
winningCards, _ := Straight(cards)
got := winningCards.Count()
if want != got {
t.Errorf("\nWant %d\nGot %d", want, got)
}
}
func TestNoFlush(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Qc") | c("Jc") | c("Tc")
_, found := Flush(cards)
if found {
t.Errorf("\nLooking for a flush in %s\nWant found=false\nGot found=true", cards)
}
}
func TestFlushToTen(t *testing.T) {
c := NewCard
cards := c("2h") | c("Th") | c("9c") | c("8h") | c("7h") | c("6h")
want := c("2h") | c("Th") | c("8h") | c("7h") | c("6h")
got, _ := Flush(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestFlushWithSevenSameColorCards(t *testing.T) {
c := NewCard
cards := c("2h") | c("Th") | c("9h") | c("8h") | c("7h") | c("6h") | c("Ah")
want := c("Ah") | c("Th") | c("8h") | c("7h") | c("9h")
got, _ := Flush(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoFullHouse(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Ah") | c("Jc") | c("Tc")
_, found := FullHouse(cards)
if found {
t.Errorf("\nLooking for a full house in %s\nWant found=false\nGot found=true", cards)
}
}
func TestFullHouseToNine(t *testing.T) {
c := NewCard
cards := c("2h") | c("9h") | c("9c") | c("9d") | c("2d") | c("6h")
want := c("2h") | c("9h") | c("9c") | c("9d") | c("2d")
got, _ := FullHouse(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoFourOfAKind(t *testing.T) {
c := NewCard
cards := c("Ac") | c("Ad") | c("Qc") | c("Jc") | c("Tc")
_, found := FourOfAKind(cards)
if found {
t.Errorf("\nLooking for a four of a kind in %s\nWant found=false\nGot found=true", cards)
}
}
func TestFourOfAKindAce(t *testing.T) {
c := NewCard
cards := c("Ah") | c("Ac") | c("Kc") | c("7c") | c("As") | c("Ad")
want := c("Ah") | c("As") | c("Ad") | c("Ac")
got, _ := FourOfAKind(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoStraightFlush(t *testing.T) {
c := NewCard
cards := c("Ah") | c("Ad") | c("Qh") | c("3c") | c("Tc")
_, found := StraightFlush(cards)
if found {
t.Errorf("\nLooking for a straight flush in %s\nWant found=false\nGot found=true", cards)
}
}
func TestStraightFlushTen(t *testing.T) {
c := NewCard
cards := c("Th") | c("9h") | c("8h") | c("7h") | c("6h") | c("Ad")
want := c("Th") | c("9h") | c("8h") | c("7h") | c("6h")
got, _ := StraightFlush(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestStraightFlushFive(t *testing.T) {
c := NewCard
cards := c("5h") | c("4h") | c("3h") | c("2h") | c("Ah") | c("Ad")
want := c("5h") | c("4h") | c("3h") | c("2h") | c("Ah")
got, _ := StraightFlush(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}
func TestNoRoyalFlush(t *testing.T) {
c := NewCard
cards := c("Ah") | c("Ad") | c("Qh") | c("3c") | c("Tc")
_, found := RoyalFlush(cards)
if found {
t.Errorf("\nLooking for a straight flush in %s\nWant found=false\nGot found=true", cards)
}
}
func TestRoyalFlush(t *testing.T) {
c := NewCard
cards := c("Th") | c("Jh") | c("Qh") | c("Kh") | c("Ah") | c("Ad")
want := c("Th") | c("Jh") | c("Qh") | c("Kh") | c("Ah")
got, _ := RoyalFlush(cards)
if want != got {
t.Errorf("\nWant %s\nGot %s", want, got)
}
}