File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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+ }
258285func TestDrawWithInvalidNumber (t * testing.T ) {
259286 deck := NewDeckWithJockers (1 )
260287 remaining := deck .Remaining
You can’t perform that action at this time.
0 commit comments