-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHand_test.go
More file actions
78 lines (67 loc) · 1.91 KB
/
Hand_test.go
File metadata and controls
78 lines (67 loc) · 1.91 KB
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 (
"reflect"
"testing"
)
func TestMaxHandSizeIsEqualToEleven(t *testing.T) {
deck := InitializeDeck()
hand := &Hand{}
for i := 0; i < 11; i++ {
hand.DrawCard(&deck)
}
if len(*hand) != 11 {
t.Error("Hand size is not 11.")
}
_, err := hand.DrawCard(&deck)
if err == nil {
t.Error("Did not throw error when hand size became more than 11.")
}
return
}
func TestPrettyPrintHand(t *testing.T) {
hand := Hand{
{13, "Clubs", "K"}, {2, "Diamonds", "2"}, {1, "Clubs", "A"},
{4, "Hearts", "4"}, {6, "Diamonds", "6"}, {12, "Spades", "Q"},
{3, "Spades", "3"}, {5, "Clubs", "5"}, {7, "Hearts", "7"},
{11, "Clubs", "J"},
}
prettyHand := hand.PrettyPrintHand()
if prettyHand != "AC 2D 3S 4H 5C 6D 7H JC QS KC" {
t.Error("Pretty print did not prettify input.")
}
return
}
func TestDiscardCard(t *testing.T) {
hand := Hand{
{13, "Clubs", "K"}, {2, "Diamonds", "2"}, {1, "Clubs", "A"},
{4, "Hearts", "4"}, {6, "Diamonds", "6"}, {12, "Spades", "Q"},
{3, "Spades", "3"}, {5, "Clubs", "5"}, {7, "Hearts", "7"},
{11, "Clubs", "J"},
}
stack := &Stack{}
hand.DiscardCard(Card{4, "Hearts", "4"}, stack)
if reflect.DeepEqual(hand, []Hand{{
{13, "Clubs", "K"}, {2, "Diamonds", "2"}, {1, "Clubs", "A"},
{6, "Diamonds", "6"}, {12, "Spades", "Q"}, {3, "Spades", "3"},
{5, "Clubs", "5"}, {7, "Hearts", "7"}, {11, "Clubs", "J"}},
}) {
t.Error("Hand did not discard card 4 of Hearts.")
}
if reflect.DeepEqual(stack, Stack{Card{4, "Hearts", "4"}}) {
t.Error("Stack did not put card on top of pile.")
}
return
}
func TestCheckTotal(t *testing.T) {
hand := Hand{
{2, "Clubs", "2"}, {2, "Diamonds", "2"}, {1, "Clubs", "A"},
{4, "Hearts", "4"}, {3, "Diamonds", "3"}, {12, "Spades", "Q"},
{3, "Spades", "3"}, {4, "Diamonds", "4"}, {7, "Hearts", "7"},
{3, "Clubs", "3"},
}
total := hand.CheckTotal()
if total != 26 {
t.Errorf("The total should be 26. Instead, we got: %d", total)
}
return
}