diff --git a/deck.go b/deck.go index fc3152a..ea27456 100644 --- a/deck.go +++ b/deck.go @@ -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 } @@ -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 } diff --git a/deck_test.go b/deck_test.go index f7f807e..49c7c03 100644 --- a/deck_test.go +++ b/deck_test.go @@ -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