diff --git a/cmd/mothd/mothballs.go b/cmd/mothd/mothballs.go index 81a629e..2f6f07e 100644 --- a/cmd/mothd/mothballs.go +++ b/cmd/mothd/mothballs.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "log" + "sort" "strconv" "strings" "sync" @@ -80,6 +81,7 @@ func (m *Mothballs) Inventory() []Category { pointsList = append(pointsList, pointval) } } + sort.Ints(pointsList) categories = append(categories, Category{cat, pointsList}) } return categories diff --git a/cmd/mothd/mothballs_test.go b/cmd/mothd/mothballs_test.go index bc56cd3..565d7ac 100644 --- a/cmd/mothd/mothballs_test.go +++ b/cmd/mothd/mothballs_test.go @@ -11,12 +11,14 @@ import ( var testFiles = []struct { Name, Body string }{ - {"puzzles.txt", "1\n2\n"}, + {"puzzles.txt", "1\n3\n2\n"}, {"answers.txt", "1 answer123\n1 answer456\n2 wat\n"}, {"content/1/puzzle.json", `{"name": "moo"}`}, {"content/1/moo.txt", `moo`}, {"content/2/puzzle.json", `{}`}, {"content/2/moo.txt", `moo`}, + {"content/3/puzzle.json", `{}`}, + {"content/3/moo.txt", `moo`}, } func (m *Mothballs) createMothball(cat string) { @@ -50,6 +52,15 @@ func TestMothballs(t *testing.T) { t.Error("Wrong inventory size:", inv) } for _, cat := range inv { + switch cat.Name { + case "pategory": + if len(cat.Puzzles) != 3 { + t.Error("Puzzles list wrong length") + } + if cat.Puzzles[1] != 2 { + t.Error("Puzzles list not sorted") + } + } for _, points := range cat.Puzzles { f, _, err := m.Open(cat.Name, points, "puzzle.json") if err != nil { diff --git a/go.mod b/go.mod index 24f4000..30167b3 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,12 @@ module github.com/dirtbags/moth go 1.13 require ( + github.com/GoBike/envflag v0.0.0-20160830095501-ae3268980a29 github.com/namsral/flag v1.7.4-pre // indirect github.com/pkg/sftp v1.11.0 // indirect - github.com/russross/blackfriday v2.0.0+incompatible // indirect + github.com/russross/blackfriday v2.0.0+incompatible github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/spf13/afero v1.3.4 golang.org/x/tools v0.0.0-20200817190302-118ac038d721 // indirect - gopkg.in/yaml.v2 v2.3.0 // indirect + gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 9a9da8a..dc5134c 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/GoBike/envflag v0.0.0-20160830095501-ae3268980a29 h1:84c6FHGkcCdLxe0CcyrKdw8to2rMldZRhTAant7A6Q0= +github.com/GoBike/envflag v0.0.0-20160830095501-ae3268980a29/go.mod h1:rC4GgElEkJwdt5ldDml0BgrkguMji8hFftI6d1d6SeU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=