Skip to content

Commit

Permalink
Added more tests for empty deck scenario on draw
Browse files Browse the repository at this point in the history
  • Loading branch information
heindrichpaul committed Oct 23, 2018
1 parent d0076cb commit 8aa7070
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ func (z *Deck) Draw(amount int) (draw *Draw) {
Cards: make([]*Card, 0),
Remaining: 0,
Success: false,
DeckID: "",
DeckID: z.DeckID,
}

if z.Remaining == 0 {
return
}
Expand Down Expand Up @@ -194,7 +195,6 @@ func (z *Deck) Draw(amount int) (draw *Draw) {
}
draw.Cards = cards
draw.Success = true
draw.DeckID = z.DeckID
draw.Remaining = z.Remaining
return
}
Expand Down
27 changes: 27 additions & 0 deletions deck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,33 @@ func TestDrawWithMoreThanRemainingNumberOfCards(t *testing.T) {
}
}

func TestDrawWithNoMoreCardsRemaining(t *testing.T) {
deck := NewDeckWithJockers(1)
deck.Remaining = 0
remaining := deck.Remaining
drawAmount := remaining + 2
draw := deck.Draw(drawAmount)
if deck.Remaining != 0 {
t.Logf("Draw reduced the number of remaining cards by more than possible.\n")
t.FailNow()
}
if len(draw.Cards) != remaining {
t.Logf("The length of the drawn cards is not the same as the amount of remaining cards.\n")
t.FailNow()
}
if draw.Success {
t.Logf("The draw reports it was successful but it should be unsuccessful.\n")
t.FailNow()
}
if !strings.EqualFold(draw.DeckID, deck.DeckID) {
t.Logf("The draw's DeckID and the deck's ID does not match.\n")
t.FailNow()
}
if draw.Remaining != deck.Remaining {
t.Logf("The draw's Remaining and the deck's Remaining cards does not match.\n")
t.FailNow()
}
}
func TestDrawWithInvalidNumber(t *testing.T) {
deck := NewDeckWithJockers(1)
remaining := deck.Remaining
Expand Down

0 comments on commit 8aa7070

Please sign in to comment.