-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck_test.go
61 lines (46 loc) · 1.14 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
package standarddeck
import (
"reflect"
"testing"
)
func Test_New(t *testing.T) {
deck := New()
if len(deck.Cards) != 52 {
t.Error("Should have 52 cards in the deck")
}
}
func Test_Shuffle(t *testing.T) {
deck := New().Shuffle()
if reflect.DeepEqual(deck.Cards, New().Cards) {
t.Error("Should have shuffled the deck")
}
}
func Test_ShuffleInPlace(t *testing.T) {
deck := New()
deck.Shuffle()
if reflect.DeepEqual(deck.Cards, New().Cards) {
t.Error("Should have shuffled the deck in place")
}
}
func Test_Draw_TooManyReturnsError(t *testing.T) {
deck := New()
if _, err := deck.Draw(53); err == nil {
t.Error("Should have thrown not enough cards in the deck error")
}
}
func Test_Draw_LessThanOne(t *testing.T) {
deck := New()
if _, err := deck.Draw(0); err == nil {
t.Error("Should have thrown too cannot draw less than 1 card")
}
}
func Test_Draw_RemovesFromDeck(t *testing.T) {
deck := New()
cards, _ := deck.Draw(7)
if len(cards) != 7 {
t.Errorf("Expected to draw 7 cards, actually drew %d", len(cards))
}
if len(deck.Cards) != 45 {
t.Errorf("Expected deck to have 45 cards, actually had %d", len(deck.Cards))
}
}