joker/deck_test.go

65 lines
1.3 KiB
Go
Raw Normal View History

2020-01-15 15:56:59 +00:00
package joker
2020-01-09 15:24:45 +00:00
import (
"testing"
)
2020-01-12 15:41:12 +00:00
var deckTestCase = []int{1, 2, 13}
2020-01-09 15:24:45 +00:00
func TestDeck(t *testing.T) {
2020-01-12 15:41:12 +00:00
d := NewDeck(StandardCards, 0)
2020-01-09 15:24:45 +00:00
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 {
2020-01-14 03:37:38 +00:00
if c.Equal(Card{face, suit}) {
2020-01-09 15:24:45 +00:00
found++
}
}
if found != 1 {
2020-01-14 03:37:38 +00:00
t.Errorf("expected 1 %s, got %d", Card{face, suit}, found)
2020-01-09 15:24:45 +00:00
}
}
}
2020-01-12 15:41:12 +00:00
for _, draw := range deckTestCase {
d = NewDeck(StandardCards, 0)
var discard Cards
2020-01-09 15:24:45 +00:00
2020-01-12 15:41:12 +00:00
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))
}
2020-01-09 15:24:45 +00:00
2020-01-12 15:41:12 +00:00
discard = append(discard, c...)
}
2020-01-09 15:24:45 +00:00
2020-01-12 15:41:12 +00:00
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 {
2020-01-14 03:37:38 +00:00
if c.Equal(Card{face, suit}) {
2020-01-12 15:41:12 +00:00
found++
}
}
if found != 1 {
2020-01-14 03:37:38 +00:00
t.Errorf("failed to draw %d: discard: expected 1 %s, got %d", draw, Card{face, suit}, found)
2020-01-09 15:24:45 +00:00
}
}
}
}
}