-
Notifications
You must be signed in to change notification settings - Fork 2
/
deck_test.go
60 lines (54 loc) · 1.33 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
package main
import "testing"
func TestNewDeck(t *testing.T) {
deck := newDeck()
got := len(deck.cards)
expected := 36
if got != expected {
t.Errorf("TestNewDeck expected: %v, got: %v", expected, got)
}
}
func TestShuffle(t *testing.T) {
deck := newDeck()
card1 := deck.cards[0]
card2 := deck.cards[1]
card3 := deck.cards[2]
deck.shuffle()
scard1 := deck.cards[0]
scard2 := deck.cards[1]
scard3 := deck.cards[2]
if card1.equals(scard1) && card2.equals(scard2) && card3.equals(scard3) {
t.Errorf("TestShuffle: it was expected that at least one of first 3 cards was moved somewhere")
t.Logf("Deck: %s", deck.asString())
}
}
func TestGetCard(t *testing.T) {
deck := newDeck()
card, err := deck.getCard()
if err != nil {
t.Fatalf("TestGetCard got error: %s", err)
}
if len(card.Value) == 0 {
t.Errorf("TestGetCard got empty value of card")
}
if len(card.Suit) == 0 {
t.Errorf("TestGetCard got empty suit of card")
}
}
func TestGetCardOnEmptyDeck(t *testing.T) {
deck := newDeck()
deck.cards = deck.cards[:0]
_, err := deck.getCard()
if err == nil {
t.Errorf("TestGetCard must be error")
}
}
func TestAsString(t *testing.T) {
deck := newDeck()
deck.cards = deck.cards[:4]
got := deck.asString()
expected := "6♣ 6♦ 6♥ 6♠"
if got != expected {
t.Errorf("TestAsString expected: %v, got: %v", expected, got)
}
}