-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_test.go
69 lines (56 loc) · 1.31 KB
/
player_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
package poker_test
import (
"testing"
"github.com/arturo-source/poker-engine"
)
func TestAddOneCard(t *testing.T) {
p := poker.NewPlayer("")
card := poker.NewCard("As")
want := card
got := &p.Hand
err := p.AddCard(card)
if err != nil {
t.Errorf("Got error adding a card to a player hand: %s", err)
}
if want != *got {
t.Errorf("\nWant %s\nGot %s", want, *got)
}
}
func TestAddTwoCards(t *testing.T) {
p := poker.NewPlayer("")
card1 := poker.NewCard("As")
card2 := poker.NewCard("Kd")
want := card1 | card2
got := &p.Hand
var err error
err = p.AddCard(card1)
if err != nil {
t.Errorf("Got error adding a card to a player hand: %s", err)
}
err = p.AddCard(card2)
if err != nil {
t.Errorf("Got error adding a card to a player hand: %s", err)
}
if want != *got {
t.Errorf("\nWant %s\nGot %s", want, *got)
}
}
func TestErrorAddingMoreThanMaxCards(t *testing.T) {
p := poker.NewPlayer("")
card1 := poker.NewCard("As")
card2 := poker.NewCard("Kd")
card3 := poker.NewCard("3c")
var err error
err = p.AddCard(card1)
if err != nil {
t.Errorf("Got error adding a card to a player hand: %s", err)
}
err = p.AddCard(card2)
if err != nil {
t.Errorf("Got error adding a card to a player hand: %s", err)
}
err = p.AddCard(card3)
if err == nil {
t.Errorf("Wanted an error. Got nil.")
}
}