-
Notifications
You must be signed in to change notification settings - Fork 0
/
suit_test.go
168 lines (161 loc) · 3.42 KB
/
suit_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package card
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSuit_Card(t *testing.T) {
tcs := []struct {
description string
suit Suit
rank Rank
expectedResult Card
}{
{
description: "assert Clubs+Ace equals 'Ace of Clubs'",
suit: Clubs,
rank: Ace,
expectedResult: CA,
},
{
description: "assert Spades+King equals 'King of Spades'",
suit: Spades,
rank: King,
expectedResult: SK,
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedResult, tc.suit.Card(tc.rank))
})
}
}
func TestSuit_Symbol(t *testing.T) {
tcs := []struct {
description string
suit Suit
expectedResult rune
}{
{
description: "assert Clubs.Symbol equals '♣'",
suit: Clubs,
expectedResult: '♣',
},
{
description: "assert Diamonds.Symbol equals '♦'",
suit: Diamonds,
expectedResult: '♦',
},
{
description: "assert Hearts.Symbol equals '♥'",
suit: Hearts,
expectedResult: '♥',
},
{
description: "assert Spades.Symbol equals '♠'",
suit: Spades,
expectedResult: '♠',
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedResult, tc.suit.Symbol())
})
}
}
func TestSuit_Name(t *testing.T) {
tcs := []struct {
description string
suit Suit
expectedResult string
}{
{
description: `assert Clubs.Name equals "Clubs"`,
suit: Clubs,
expectedResult: "Clubs",
},
{
description: `assert Diamonds.Name equals "Diamonds"`,
suit: Diamonds,
expectedResult: "Diamonds",
},
{
description: `assert Hearts.Name equals "Hearts"`,
suit: Hearts,
expectedResult: "Hearts",
},
{
description: `assert Spades.Name equals "Spades"`,
suit: Spades,
expectedResult: "Spades",
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedResult, tc.suit.Name())
})
}
}
func TestSuit_String(t *testing.T) {
tcs := []struct {
description string
suit Suit
expectedResult string
}{
{
description: `assert Clubs.String equals "♣"`,
suit: Clubs,
expectedResult: "♣",
},
{
description: `assert Diamonds.String equals "♦"`,
suit: Diamonds,
expectedResult: "♦",
},
{
description: `assert Hearts.String equals "♥"`,
suit: Hearts,
expectedResult: "♥",
},
{
description: `assert Spades.String equals "♠"`,
suit: Spades,
expectedResult: "♠",
},
}
for _, tc := range tcs {
t.Run(tc.description, func(t *testing.T) {
assert.Equal(t, tc.expectedResult, tc.suit.String())
})
}
}
func TestParseSuit(t *testing.T) {
tcs := []struct {
input string
expectedResult Suit
}{
{
input: "♣",
expectedResult: Clubs,
},
{
input: "♦",
expectedResult: Diamonds,
},
{
input: "♥",
expectedResult: Hearts,
},
{
input: "♠",
expectedResult: Spades,
},
}
for _, tc := range tcs {
t.Run("Parse suit: "+tc.input, func(t *testing.T) {
suit, err := ParseSuit(tc.input)
require.NoError(t, err)
assert.Equal(t, tc.expectedResult, suit)
})
}
}