Adds list of author computation

This commit is contained in:
2016-01-25 13:13:57 +01:00
parent 88ab821c58
commit 594598ed6b
2 changed files with 58 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"regexp"
"strconv"
"time"
)
@@ -70,3 +71,33 @@ type Album struct {
func AlbumIDString(ID AlbumID) string {
return strconv.FormatUint(uint64(ID), 10)
}
var rxAuthorSkip = regexp.MustCompile(`\A<.*>\z`)
func (a *Album) Authors() []string {
authorsUnsafe := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers))
authors := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers))
set := map[string]bool{}
authorsUnsafe = append(authorsUnsafe, a.Designers...)
authorsUnsafe = append(authorsUnsafe, a.Scenarists...)
authorsUnsafe = append(authorsUnsafe, a.Colorists...)
for _, author := range authorsUnsafe {
if rxAuthorSkip.MatchString(author) == true || set[author] == true {
continue
}
authors = append(authors, author)
set[author] = true
}
return authors
}
func (a *Album) String() string {
res := strconv.FormatUint(uint64(a.ID), 10) + ": "
if len(a.Collection) > 0 {
res += a.Collection + ": "
}
return res + a.Title
}

View File

@@ -11,3 +11,30 @@ func Test(t *testing.T) { TestingT(t) }
type AlbumSuite struct{}
var _ = Suite(&AlbumSuite{})
func (s *AlbumSuite) TestAuthors(c *C) {
data := map[AlbumID][]string{
8179: []string{"Berthet, Philippe", "Andreas"},
44989: []string{"Loro"},
58595: []string{"Plantu"},
19762: []string{"Swal, Christophe", "Polouchine, Igor", "Rastoin, Bernard", "Robert, Jacky"},
9935: []string{"Fournier, Jean-Claude", "D'Authenay, Anne-Marie"},
164: []string{"Adamov, Philippe", "Cothias, Patrick"},
22737: []string{"Leo", "Rodolphe", "Scarlett"},
32043: []string{"Joan", "Harty", "Ptiluc"},
46005: []string{"Tibet"},
15875: []string{"Veyron, Martin"},
84448: []string{"Delitte, Jean-Yves"},
160366: []string{"Trondheim, Lewis", "Findakly, Brigitte"},
754: []string{"Bruyninx, Marc"},
52100: []string{"Guénet, Nicolas", "Téhy", "Vee, J.M."},
}
for _, a := range albumsDataTest {
expected, ok := data[a.ID]
if c.Check(ok, Equals, true) == true {
c.Check(a.Authors(), DeepEquals, expected)
}
}
}