-
Notifications
You must be signed in to change notification settings - Fork 0
/
card_test.go
88 lines (67 loc) · 1.53 KB
/
card_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
79
80
81
82
83
84
85
86
87
88
package shuffle
import (
"fmt"
"testing"
)
func ExampleCard() {
fmt.Println(Card{Rank: Ace, Suit: Heart})
fmt.Println(Card{Rank: Two, Suit: Spade})
fmt.Println(Card{Rank: Seven, Suit: Diamond})
fmt.Println(Card{Rank: Three, Suit: Club})
fmt.Println(Card{Suit: Joker})
//Output:
// Ace of Hearts
// Two of Spades
// Seven of Diamonds
// Three of Clubs
// Joker
}
func TestNew(t *testing.T) {
cards := New()
if len(cards) != 52 {
t.Error("Wrong number of cards in a new Deck")
}
}
func TestDefaultSort(t *testing.T) {
cards := New(DefaultSort)
exp := Card{Rank: Ace, Suit: Spade}
if cards[0] != exp {
t.Error("Expected Ave of Spades as first card. recieved:", cards[0])
}
}
func TestSort(t *testing.T) {
cards := New(Sort(Less))
exp := Card{Rank: Ace, Suit: Spade}
if cards[0] != exp {
t.Error("Expected Ave of Spades as first card. recieved:", cards[0])
}
}
func TestJokers(t *testing.T) {
cards := New(Jokers(3))
count := 0
for _, card := range cards {
if card.Suit == Joker {
count++
}
}
if count != 3 {
t.Error("Expected 3 Jokers, recieved:", count)
}
}
func TestFilter(t *testing.T) {
filter := func(card Card) bool {
return card.Rank == Two || card.Rank == Three
}
cards := New(Filter(filter))
for _, c := range cards {
if c.Rank == Two || c.Rank == Three {
t.Error("Expeceted all twos and threes to be filtered out.")
}
}
}
func TestDeck(t *testing.T) {
cards := New(Deck(3))
if len(cards) != 13*4*3 {
t.Errorf("Expeceted %d cards, recieved %d cards", 13*4*3, len(cards))
}
}