-
Notifications
You must be signed in to change notification settings - Fork 4
/
game_test.go
204 lines (157 loc) · 4.79 KB
/
game_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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func newTestGame() *Game {
return NewGameFromSeed(0xace)
}
func TestStack_Push(t *testing.T) {
stack := &Stack{}
card := NewCard(1, SuitSpades)
assert.Equal(t, 0, len(stack.Cards))
stack.Push(card)
assert.Equal(t, 1, len(stack.Cards))
}
func TestGame_Deal(t *testing.T) {
game := newTestGame()
assert.Equal(t, 1, len(game.Stack1.Cards))
assert.Equal(t, 2, len(game.Stack2.Cards))
assert.Equal(t, 7, len(game.Stack7.Cards))
assert.Equal(t, 24, len(game.Hand.Cards))
}
func TestGame_Deal_FaceUp(t *testing.T) {
game := newTestGame()
assert.Equal(t, true, game.Stack1.Cards[0].FaceUp)
assert.Equal(t, false, game.Stack2.Cards[0].FaceUp)
assert.Equal(t, true, game.Stack2.Cards[1].FaceUp)
}
func TestGame_Draw(t *testing.T) {
game := newTestGame()
assert.Equal(t, 24, len(game.Hand.Cards))
game.DrawThree()
assert.Equal(t, 21, len(game.Hand.Cards))
assert.NotNil(t, game.Draw1)
assert.True(t, game.Draw1.FaceUp)
assert.NotNil(t, game.Draw2)
assert.True(t, game.Draw2.FaceUp)
assert.NotNil(t, game.Draw3)
assert.True(t, game.Draw3.FaceUp)
}
func TestGameDrawEnd(t *testing.T) {
game := newTestGame()
assert.Equal(t, 24, len(game.Hand.Cards))
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
assert.Equal(t, 0, len(game.Hand.Cards))
}
func TestGame_DrawCycles(t *testing.T) {
game := newTestGame()
assert.Equal(t, 24, len(game.Hand.Cards))
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
game.DrawThree()
// This is the extra one...
game.DrawThree()
assert.Equal(t, 24, len(game.Hand.Cards))
}
func TestGame_ResetDraw(t *testing.T) {
game := newTestGame()
assert.Equal(t, 24, len(game.Hand.Cards))
game.DrawThree()
game.ResetDraw()
assert.Equal(t, 24, len(game.Hand.Cards))
}
func TestGame_DrawSymmetric(t *testing.T) {
game := newTestGame()
assert.Equal(t, 24, len(game.Hand.Cards))
game.DrawThree()
first := game.Draw1
game.ResetDraw()
// first draw again
game.DrawThree()
assert.Equal(t, first, game.Draw1)
}
func TestGame_MoveCardToBuildFromHand(t *testing.T) {
game := newTestGame()
game.DrawThree()
game.Draw3.Value = 1
game.MoveCardToBuild(game.Build1, game.Draw3)
assert.Equal(t, 1, len(game.Build1.Cards))
assert.Nil(t, game.Draw3)
}
func TestGame_MoveCardToBuildFromStack2(t *testing.T) {
game := newTestGame()
game.Stack2.Cards[1].Value = 1
assert.Equal(t, 2, len(game.Stack2.Cards))
assert.False(t, game.Stack2.Cards[0].FaceUp)
game.MoveCardToBuild(game.Build2, game.Stack2.Cards[1])
assert.Equal(t, 1, len(game.Build2.Cards))
assert.Equal(t, 1, len(game.Stack2.Cards))
assert.True(t, game.Stack2.Cards[0].FaceUp)
}
func TestGame_MoveCardToStack(t *testing.T) {
game := newTestGame()
game.Stack1.Cards[0].Value = 3
game.Stack1.Cards[0].Suit = SuitClubs
game.Stack2.Cards[1].Value = 2
game.Stack2.Cards[1].Suit = SuitDiamonds
assert.False(t, game.Stack2.Cards[0].FaceUp)
game.MoveCardToStack(game.Stack1, game.Stack2.Cards[1])
assert.Equal(t, 2, len(game.Stack1.Cards))
assert.Equal(t, 1, len(game.Stack2.Cards))
assert.True(t, game.Stack2.Cards[0].FaceUp)
}
func TestGame_MoveCardToStack_Empty(t *testing.T) {
game := newTestGame()
game.Stack1.Cards = []*Card{}
game.Stack2.Cards[1].Value = ValueKing
game.Stack2.Cards[1].Suit = SuitDiamonds
game.MoveCardToStack(game.Stack1, game.Stack2.Cards[1])
assert.Equal(t, 1, len(game.Stack1.Cards))
assert.Equal(t, 1, len(game.Stack2.Cards))
assert.True(t, game.Stack2.Cards[0].FaceUp)
}
func TestGame_MoveCardToStack_EmptyEmpty(t *testing.T) {
game := newTestGame()
game.Stack3.Cards = []*Card{}
king := NewCard(ValueKing, SuitDiamonds)
game.Stack2.Cards = []*Card{king}
game.MoveCardToStack(game.Stack3, game.Stack2.Cards[0])
assert.Equal(t, 1, len(game.Stack3.Cards))
assert.Equal(t, 0, len(game.Stack2.Cards))
}
func TestGame_MoveCardToStack_Stack(t *testing.T) {
game := newTestGame()
game.Stack1.Cards[0].Value = 7
game.Stack1.Cards[0].Suit = SuitClubs
game.Stack2.Cards[0].Value = 6
game.Stack2.Cards[0].Suit = SuitDiamonds
game.Stack2.Cards[1].Value = 5
game.Stack2.Cards[1].Suit = SuitSpades
game.MoveCardToStack(game.Stack1, game.Stack2.Cards[0])
assert.Equal(t, 3, len(game.Stack1.Cards))
assert.Equal(t, 0, len(game.Stack2.Cards))
}
func TestGame_MoveCardToStack_KingStack(t *testing.T) {
game := newTestGame()
game.Stack1.Cards = []*Card{}
game.Stack3.Cards[1].Value = ValueKing
game.Stack3.Cards[1].Suit = SuitDiamonds
game.Stack3.Cards[2].Value = ValueQueen
game.Stack3.Cards[2].Suit = SuitSpades
game.MoveCardToStack(game.Stack1, game.Stack3.Cards[1])
assert.Equal(t, 2, len(game.Stack1.Cards))
assert.Equal(t, 1, len(game.Stack3.Cards))
}