package game import ( "errors" "slices" "testing" ) func TestPocToString(t *testing.T) { poc := NewPileOfCards() cards := []*Card{NewCard("base/archer"), NewCard("magic/ritual!")} poc.AddCards(cards) exp := "[base/archer, magic/ritual!]" is := poc.String() if is != exp { t.Fatalf("expected string %s does not match %s\n", exp, is) } } func TestPocFromString(t *testing.T) { poc := NewPileOfCards() in := "[base/archer, magic/ritual!]" err := poc.FromString(in) if err != nil { t.Fatal(err) } // Error cases poc = NewPileOfCards() in = "base/archer, magic/ritual!]" err = poc.FromString(in) if !errors.Is(err, ErrInvalidPocString) { t.Fatal("expected ErrInvalidPocString") } in = "[base/archer, magic/ritual!" err = poc.FromString(in) if !errors.Is(err, ErrInvalidPocString) { t.Fatal("expected ErrInvalidPocString") } in = "[base/archer magic/ritual!]" err = poc.FromString(in) if !errors.Is(err, ErrUnknownCardPath) { t.Fatal("expected url.Error") } } func TestPocAddRemoveCard(t *testing.T) { poc := NewPileOfCards() archer := NewCard("base/archer") poc.AddCard(archer) if poc.IsEmpty() { t.Fatal("poc till empty") } if poc.Size() != 1 { t.Fatal("poc size != 1:", poc.Size()) } if !poc.Contains(archer) { t.Fatal("poc does not contain archer") } knight := NewCard("base/knight") poc.RemoveCard(knight) if poc.Size() != 1 { t.Fatal("poc size != 1:", poc.Size()) } poc.RemoveCard(archer) if poc.Size() != 0 { t.Fatal("poc size != 0:", poc.Size()) } if poc.Contains(archer) { t.Fatal("poc still contains archer") } } func TestPocMoveCard(t *testing.T) { poc1 := NewPileOfCards() poc2 := NewPileOfCards() archer := NewCard("base/archer") poc1.AddCard(archer) poc1.MoveCard(archer, poc2) if poc1.Size() != 0 { t.Fatal("poc1 size != 0:", poc1.Size()) } if poc2.Size() != 1 { t.Fatal("poc2 size != 1:", poc2.Size()) } } func TestPocToList(t *testing.T) { poc := NewPileOfCards() archer1 := NewCard("base/archer") poc.AddCard(archer1) archer2 := NewCard("base/archer") poc.AddCard(archer2) knight := NewCard("base/knight") poc.AddCard(knight) if poc.Size() != 3 { t.Fatal("poc size != 3:", poc.Size()) } is := poc.ToList() exp := []string{"2 base/archer\n1 base/knight", "1 base/knight\n2 base/archer"} if !slices.Contains(exp, is) { t.Fatal("not expected cardList:", is) } } func TestPocFilterCards(t *testing.T) { base := NewDeckFromCardPaths(Sets.Base.CardPaths()) units := base.FilterCards(func(c *Card) bool { return c.Type == CardTypes.Unit }) for _, u := range units { if u.Type != CardTypes.Unit { t.Fatal(u, " is not unit") } } }