-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdeck_test.go
78 lines (56 loc) · 1.84 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
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func assertNotEqualCard(t *testing.T, value int, suit Suit, card *Card) {
if value != card.Value || suit != card.Suit {
return
}
t.Fail()
}
func TestNewDeck(t *testing.T) {
deck := NewSortedDeck()
assert.Equal(t, 52, len(deck.Cards))
}
func TestNewSortedDeck(t *testing.T) {
deck := NewSortedDeck()
assert.Equal(t, 1, deck.Cards[0].Value)
assert.Equal(t, SuitClubs, deck.Cards[0].Suit)
assert.Equal(t, 13, deck.Cards[12].Value)
assert.Equal(t, SuitClubs, deck.Cards[0].Suit)
assert.Equal(t, 1, deck.Cards[13].Value)
assert.Equal(t, SuitDiamonds, deck.Cards[13].Suit)
assert.Equal(t, 5, deck.Cards[30].Value)
assert.Equal(t, SuitHearts, deck.Cards[30].Suit)
assert.Equal(t, 11, deck.Cards[49].Value)
assert.Equal(t, SuitSpades, deck.Cards[49].Suit)
}
func TestNewShuffledDeck(t *testing.T) {
deck := NewShuffledDeckFromSeed(1337)
assertNotEqualCard(t, 1, SuitClubs, deck.Cards[0])
assertNotEqualCard(t, 13, SuitClubs, deck.Cards[12])
assertNotEqualCard(t, 1, SuitDiamonds, deck.Cards[13])
}
func TestNewShuffledDeckFromSeed(t *testing.T) {
deck1 := NewShuffledDeckFromSeed(1337)
deck2 := NewShuffledDeckFromSeed(0xcafe)
assertNotEqualCard(t, deck1.Cards[0].Value, deck1.Cards[0].Suit, deck2.Cards[0])
assertNotEqualCard(t, deck1.Cards[1].Value, deck1.Cards[1].Suit, deck2.Cards[1])
assertNotEqualCard(t, deck1.Cards[2].Value, deck1.Cards[2].Suit, deck2.Cards[2])
}
func TestDeck_Push(t *testing.T) {
deck := Deck{}
assert.Equal(t, 0, len(deck.Cards))
card := NewCard(1, SuitDiamonds)
deck.Push(card)
assert.Equal(t, 1, len(deck.Cards))
assert.Equal(t, card, deck.Pop())
}
func TestDeck_Pop(t *testing.T) {
deck := NewSortedDeck()
assert.Equal(t, 52, len(deck.Cards))
card := deck.Pop()
assert.NotNil(t, card)
assert.Equal(t, 51, len(deck.Cards))
}