-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck_test.go
76 lines (63 loc) · 1.94 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
package main
import (
"testing"
)
func TestNewDeckIsReadyForPlay(t *testing.T) {
deck := NewDeck()
if !deck.Active() {
t.Fail()
}
return
}
func TestNumberOfCardsInDeck(t *testing.T) {
princess := Card{8, "Princess", "Discarding this card loses the game"}
countess := Card{7, "Countess", "Must discard this card when held with a King or Prince"}
var availableCards []Card
var burntCard Card
var discardedCards []Card
availableCards = append(availableCards, princess)
availableCards = append(availableCards, countess)
deck := Deck{availableCards, burntCard, discardedCards}
if !(deck.NumberInDeck() == 2) {
t.Error("After initialisation, Deck did not contain 2 cards.")
}
}
func TestDrawingLastCardFromDeck(t *testing.T) {
princess := Card{8, "Princess", "Discarding this card loses the game"}
var availableCards []Card
var burntCard Card
var discardedCards []Card
var drawnCard Card
var err error
availableCards = append(availableCards, princess)
deck := Deck{availableCards, burntCard, discardedCards}
if deck.NumberInDeck() != 1 {
t.Fatalf("Deck should contain 1 card, but contains %d cards", deck.NumberInDeck())
}
err, drawnCard = deck.Draw()
if err != nil {
t.Fatal(err)
}
if drawnCard.Name() != "Princess" {
t.Error("The wrong card was drawn from the deck")
}
if deck.NumberInDeck() != 0 {
t.Errorf("Deck should be empty, but contains %d cards", deck.NumberInDeck())
deck.Describe()
}
if deck.Active() != false {
t.Errorf("Expected deck.Active to be false but was %t", deck.Active())
}
}
func ExampleDescribeDeckF() {
princess := Card{8, "Princess", "Discarding this card loses the game"}
var availableCards []Card
var burntCard Card
var discardedCards []Card
availableCards = append(availableCards, princess)
deck := Deck{availableCards, burntCard, discardedCards}
deck.Describe()
// Output:
// Deck is active
// Card: Princess is worth 8 points, when played has "Discarding this card loses the game" effect
}