File tree Expand file tree Collapse file tree 4 files changed +85
-2
lines changed Expand file tree Collapse file tree 4 files changed +85
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ archives:
4646 files :
4747 - LICENSE
4848 - README.md
49- - input/*
49+ - input/*/*
5050checksum :
5151 name_template : " {{ .ProjectName }}-{{ .Version }}-checksums.txt"
5252
Original file line number Diff line number Diff line change @@ -9,14 +9,18 @@ import (
99 "github.com/pkg/errors"
1010
1111 "github.com/oleg-balunenko/advent-of-code/puzzles"
12+ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions"
1213)
1314
1415type solution struct {
1516 name string
1617}
1718
1819func init () {
19- const puzzleName = "day01"
20+ puzzleName , err := solutions .MakeName ("2019" , "day01" )
21+ if err != nil {
22+ panic (err )
23+ }
2024
2125 puzzles .Register (puzzleName , solution {
2226 name : puzzleName ,
Original file line number Diff line number Diff line change 1+ package solutions
2+
3+ import (
4+ "errors"
5+ "os"
6+ )
7+
8+ // MakeName builds puzzle name according to year and puzzle passed
9+ func MakeName (year string , puzzle string ) (string , error ) {
10+ if puzzle == "" {
11+ return "" , errors .New ("invalid puzzle name" )
12+ }
13+
14+ if year == "" {
15+ return "" , errors .New ("invalid year" )
16+ }
17+
18+ return year + string (os .PathSeparator ) + puzzle , nil
19+ }
Original file line number Diff line number Diff line change 1+ package solutions
2+
3+ import (
4+ "os"
5+ "testing"
6+
7+ "github.com/stretchr/testify/assert"
8+ )
9+
10+ func TestMakeName (t * testing.T ) {
11+ type args struct {
12+ year string
13+ puzzle string
14+ }
15+ tests := []struct {
16+ name string
17+ args args
18+ want string
19+ wantErr bool
20+ }{
21+ {
22+ name : "valid name" ,
23+ args : args {
24+ year : "2019" ,
25+ puzzle : "day01" ,
26+ },
27+ want : "2019" + string (os .PathSeparator ) + "day01" ,
28+ wantErr : false ,
29+ },
30+ {
31+ name : "missed year - error" ,
32+ args : args {
33+ year : "" ,
34+ puzzle : "day01" ,
35+ },
36+ want : "" ,
37+ wantErr : true ,
38+ },
39+ {
40+ name : "missed puzzle - error" ,
41+ args : args {
42+ year : "2019" ,
43+ puzzle : "" ,
44+ },
45+ want : "" ,
46+ wantErr : true ,
47+ },
48+ }
49+ for _ , tt := range tests {
50+ t .Run (tt .name , func (t * testing.T ) {
51+ got , err := MakeName (tt .args .year , tt .args .puzzle )
52+ if tt .wantErr {
53+ assert .Error (t , err )
54+ return
55+ }
56+ assert .NoError (t , err )
57+ assert .Equal (t , tt .want , got )
58+ })
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments