diff --git a/deck.go b/deck.go index 54e9f9a..bb49c7f 100644 --- a/deck.go +++ b/deck.go @@ -22,6 +22,7 @@ func NewDeck() *Deck { return deck } +// Copy returns a copy of the deck. func (deck *Deck) Copy() *Deck { if deck == nil { return nil @@ -33,6 +34,15 @@ func (deck *Deck) Copy() *Deck { return deck2 } +// Remove removes a given card from the deck. +func (deck *Deck) Remove(c Card) { + for i, c2 := range deck.cards { + if c == c2 { + deck.cards = append(deck.cards[:i], deck.cards[i+1:]...) + } + } +} + func (deck *Deck) Shuffle() { deck.cards = make([]Card, len(fullDeck.cards)) copy(deck.cards, fullDeck.cards) diff --git a/deck_test.go b/deck_test.go index 9177f44..a5310b8 100644 --- a/deck_test.go +++ b/deck_test.go @@ -19,6 +19,21 @@ func TestNewDeck(t *testing.T) { assert.False(t, same) } +func TestCopy(t *testing.T) { + deck := NewDeck() + deck2 := deck.Copy() + assert.NotSame(t, deck, deck2) + assert.EqualValues(t, deck, deck2) +} + +func TestRemove(t *testing.T) { + deck := NewDeck() + c := NewCard("As") + assert.Contains(t, deck.cards, c) + deck.Remove(c) + assert.NotContains(t, deck.cards, c) +} + func TestDraw(t *testing.T) { deck := NewDeck()