Playing card library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

package joker
import (
"encoding/json"
"testing"
)
type cardTestCase struct {
Card Card
Expected string
}
var cardTestCases = []*cardTestCase{
{Card: Card{FaceAce, SuitSpades}, Expected: `"AS"`},
{Card: Card{Face7, SuitDiamonds}, Expected: `"7D"`},
{Card: Card{Face10, SuitHearts}, Expected: `"10H"`},
{Card: Card{FaceQueen, SuitHearts}, Expected: `"QH"`},
{Card: Card{FaceJoker, SuitClubs}, Expected: `"!C"`},
{Card: Card{FaceJoker, SuitJoker}, Expected: `"!!"`},
{Card: Card{FaceKing, SuitJoker}, Expected: `"K!"`},
}
func TestMarshalCard(t *testing.T) {
for _, c := range cardTestCases {
buf, err := json.Marshal(c.Card)
if err != nil {
t.Error(err)
}
if string(buf) != c.Expected {
t.Errorf("failed to marshal card: expected %s, got %s", c.Expected, string(buf))
}
}
}
func TestUnmarshalCard(t *testing.T) {
for _, c := range cardTestCases {
var cd Card
err := json.Unmarshal([]byte(c.Expected), &cd)
if err != nil {
t.Error(err)
}
if !cd.Equal(c.Card) {
t.Errorf("failed to unmarshal card: expected %s, got %s", c.Card, cd)
}
}
}