forked from chehsunliu/poker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck_test.go
66 lines (53 loc) · 1.16 KB
/
deck_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
package cards
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDeck(t *testing.T) {
deck1 := NewDeck()
deck2 := NewDeck()
assert.Len(t, deck1.cards, 52)
assert.Len(t, deck2.cards, 52)
same := true
for i := range deck1.cards {
same = same && (deck1.cards[i] == deck2.cards[i])
}
assert.False(t, same)
}
func TestCopy(t *testing.T) {
deck := NewDeck()
deck2 := deck.Copy()
assert.NotSame(t, deck, deck2)
assert.EqualValues(t, deck, deck2)
}
func TestRemove(t *testing.T) {
deck := NewDeck()
c := NewCard("As")
assert.Contains(t, deck.cards, c)
deck.Remove(c)
assert.NotContains(t, deck.cards, c)
}
func TestDraw(t *testing.T) {
deck := NewDeck()
cards := deck.Draw(5)
assert.Len(t, cards, 5)
assert.False(t, deck.Empty())
deck.Draw(52 - 5)
assert.True(t, deck.Empty())
}
func TestEmpty(t *testing.T) {
deck := NewDeck()
assert.False(t, deck.Empty())
deck.Draw(51)
assert.False(t, deck.Empty())
deck.Draw(1)
assert.True(t, deck.Empty())
}
func TestScanAndValue(t *testing.T) {
deck := NewDeck()
v, err := deck.Value()
assert.Nil(t, err)
deck2 := &Deck{}
assert.Nil(t, deck2.Scan(v))
assert.EqualValues(t, deck, deck2)
}