Add IDs() method for packs
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
Hamcha 2019-06-28 11:17:51 +02:00
parent ac1ae4f506
commit c2d3b3b679
3 changed files with 39 additions and 10 deletions

View file

@ -78,3 +78,12 @@ func (p Pack) String() (str string) {
str = strings.TrimSpace(str) str = strings.TrimSpace(str)
return return
} }
// IDs unwraps all the IDs from the cards in the pack
func (p Pack) IDs() []string {
out := make([]string, len(p))
for i, card := range p {
out[i] = card.ID
}
return out
}

30
pack_test.go Normal file
View file

@ -0,0 +1,30 @@
package draft_test
import (
"testing"
"git.fromouter.space/mcg/draft"
)
// TestPackString makes sure packs are serialized correctly
func TestPackString(t *testing.T) {
p := draft.Pack{{ID: "a"}, {ID: "b"}, {ID: "c"}}
expected := "a b c"
if p.String() != expected {
t.Fatalf("Expected \"%s\" but got \"%s\"", expected, p)
}
}
// TestPackIDs makes sure packs are unwrapped correctly
func TestPackIDs(t *testing.T) {
p := draft.Pack{{ID: "a"}, {ID: "b"}, {ID: "c"}}
ids := p.IDs()
if len(ids) < 3 {
t.Fatalf("Expected %d items but got %d", len(p), len(ids))
}
if ids[0] != "a" || ids[1] != "b" || ids[2] != "c" {
t.Fatalf("Contents expected to be [%s] but got %s", p, ids)
}
}

View file

@ -104,16 +104,6 @@ func TestCubeOverflow(t *testing.T) {
} }
} }
// TestPackString makes sure packs are serialized correctly
func TestPackString(t *testing.T) {
p := draft.Pack{{ID: "a"}, {ID: "b"}, {ID: "c"}}
expected := "a b c"
if p.String() != expected {
t.Fatalf("Expected \"%s\" but got \"%s\"", expected, p)
}
}
// ExampleGenericSet is an example usage of the Set APIs to make packs // ExampleGenericSet is an example usage of the Set APIs to make packs
func ExampleGenericSet() { func ExampleGenericSet() {
// Create a set with some items // Create a set with some items