Add IDs() method for packs
All checks were successful
continuous-integration/drone/tag Build is passing
All checks were successful
continuous-integration/drone/tag Build is passing
This commit is contained in:
parent
ac1ae4f506
commit
c2d3b3b679
3 changed files with 39 additions and 10 deletions
9
pack.go
9
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
|
||||
}
|
||||
|
|
30
pack_test.go
Normal file
30
pack_test.go
Normal 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)
|
||||
}
|
||||
}
|
10
set_test.go
10
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
|
||||
|
|
Loading…
Reference in a new issue