Skip to content

Commit 8aa7070

Browse files
committed
Added more tests for empty deck scenario on draw
1 parent d0076cb commit 8aa7070

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

deck.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ func (z *Deck) Draw(amount int) (draw *Draw) {
165165
Cards: make([]*Card, 0),
166166
Remaining: 0,
167167
Success: false,
168-
DeckID: "",
168+
DeckID: z.DeckID,
169169
}
170+
170171
if z.Remaining == 0 {
171172
return
172173
}
@@ -194,7 +195,6 @@ func (z *Deck) Draw(amount int) (draw *Draw) {
194195
}
195196
draw.Cards = cards
196197
draw.Success = true
197-
draw.DeckID = z.DeckID
198198
draw.Remaining = z.Remaining
199199
return
200200
}

deck_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,33 @@ func TestDrawWithMoreThanRemainingNumberOfCards(t *testing.T) {
255255
}
256256
}
257257

258+
func TestDrawWithNoMoreCardsRemaining(t *testing.T) {
259+
deck := NewDeckWithJockers(1)
260+
deck.Remaining = 0
261+
remaining := deck.Remaining
262+
drawAmount := remaining + 2
263+
draw := deck.Draw(drawAmount)
264+
if deck.Remaining != 0 {
265+
t.Logf("Draw reduced the number of remaining cards by more than possible.\n")
266+
t.FailNow()
267+
}
268+
if len(draw.Cards) != remaining {
269+
t.Logf("The length of the drawn cards is not the same as the amount of remaining cards.\n")
270+
t.FailNow()
271+
}
272+
if draw.Success {
273+
t.Logf("The draw reports it was successful but it should be unsuccessful.\n")
274+
t.FailNow()
275+
}
276+
if !strings.EqualFold(draw.DeckID, deck.DeckID) {
277+
t.Logf("The draw's DeckID and the deck's ID does not match.\n")
278+
t.FailNow()
279+
}
280+
if draw.Remaining != deck.Remaining {
281+
t.Logf("The draw's Remaining and the deck's Remaining cards does not match.\n")
282+
t.FailNow()
283+
}
284+
}
258285
func TestDrawWithInvalidNumber(t *testing.T) {
259286
deck := NewDeckWithJockers(1)
260287
remaining := deck.Remaining

0 commit comments

Comments
 (0)