package joker import ( "testing" ) var deckTestCase = []int{1, 2, 13} func TestDeck(t *testing.T) { d := NewDeck(StandardCards, 0) if len(d.Cards) != 52 { t.Errorf("expected 52 cards, got %d", len(d.Cards)) } for _, suit := range StandardSuits { for _, face := range StandardFaces { found := 0 for _, c := range d.Cards { if c.Equal(Card{face, suit}) { found++ } } if found != 1 { t.Errorf("expected 1 %s, got %d", Card{face, suit}, found) } } } for _, draw := range deckTestCase { d = NewDeck(StandardCards, 0) var discard Cards l := len(d.Cards) / draw for i := 0; i < l; i++ { c, ok := d.Draw(draw) if !ok { t.Errorf("failed to draw %d iteration %d", draw, i) } else if len(c) != draw { t.Errorf("failed to draw %d iteration %d: expected %d cards, got %d", draw, i, draw, len(c)) } discard = append(discard, c...) } if len(d.Cards) != 0 { t.Errorf("failed to draw %d: expected 0 cards after drawing, got %d", draw, len(d.Cards)) } for _, suit := range StandardSuits { for _, face := range StandardFaces { found := 0 for _, c := range discard { if c.Equal(Card{face, suit}) { found++ } } if found != 1 { t.Errorf("failed to draw %d: discard: expected 1 %s, got %d", draw, Card{face, suit}, found) } } } } }