diff --git a/pack.go b/pack.go index 2d7b5b7..9047671 100644 --- a/pack.go +++ b/pack.go @@ -78,3 +78,12 @@ func (p Pack) String() (str string) { str = strings.TrimSpace(str) 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 +} diff --git a/pack_test.go b/pack_test.go new file mode 100644 index 0000000..520a1a6 --- /dev/null +++ b/pack_test.go @@ -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) + } +} diff --git a/set_test.go b/set_test.go index 3a5afb1..78dcce5 100644 --- a/set_test.go +++ b/set_test.go @@ -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 func ExampleGenericSet() { // Create a set with some items