...
1 package joker
2
3 import (
4 "testing"
5 )
6
7 var deckTestCase = []int{1, 2, 13}
8
9 func TestDeck(t *testing.T) {
10 d := NewDeck(StandardCards, 0)
11
12 if len(d.Cards) != 52 {
13 t.Errorf("expected 52 cards, got %d", len(d.Cards))
14 }
15
16 for _, suit := range StandardSuits {
17 for _, face := range StandardFaces {
18 found := 0
19 for _, c := range d.Cards {
20 if c.Equal(Card{face, suit}) {
21 found++
22 }
23 }
24 if found != 1 {
25 t.Errorf("expected 1 %s, got %d", Card{face, suit}, found)
26 }
27 }
28 }
29
30 for _, draw := range deckTestCase {
31 d = NewDeck(StandardCards, 0)
32 var discard Cards
33
34 l := len(d.Cards) / draw
35 for i := 0; i < l; i++ {
36 c, ok := d.Draw(draw)
37 if !ok {
38 t.Errorf("failed to draw %d iteration %d", draw, i)
39 } else if len(c) != draw {
40 t.Errorf("failed to draw %d iteration %d: expected %d cards, got %d", draw, i, draw, len(c))
41 }
42
43 discard = append(discard, c...)
44 }
45
46 if len(d.Cards) != 0 {
47 t.Errorf("failed to draw %d: expected 0 cards after drawing, got %d", draw, len(d.Cards))
48 }
49
50 for _, suit := range StandardSuits {
51 for _, face := range StandardFaces {
52 found := 0
53 for _, c := range discard {
54 if c.Equal(Card{face, suit}) {
55 found++
56 }
57 }
58 if found != 1 {
59 t.Errorf("failed to draw %d: discard: expected 1 %s, got %d", draw, Card{face, suit}, found)
60 }
61 }
62 }
63 }
64 }
65
View as plain text