Skip to content

Commit 3496a1b

Browse files
committed
Refactor solutions registration
1 parent 7970507 commit 3496a1b

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

cmd/aoc-cli/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
"github.com/pkg/errors"
1313

1414
"github.com/oleg-balunenko/advent-of-code/puzzles"
15-
_ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/2019/day01"
15+
// register all solutions
16+
_ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions"
1617
)
1718

1819
const (

puzzles/solutions/name.go renamed to puzzles/name.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package solutions
1+
package puzzles
22

33
import (
44
"errors"

puzzles/solutions/name_test.go renamed to puzzles/name_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package solutions
1+
package puzzles
22

33
import (
44
"os"
@@ -12,6 +12,7 @@ func TestMakeName(t *testing.T) {
1212
year string
1313
puzzle string
1414
}
15+
1516
tests := []struct {
1617
name string
1718
args args
@@ -46,7 +47,10 @@ func TestMakeName(t *testing.T) {
4647
wantErr: true,
4748
},
4849
}
50+
4951
for _, tt := range tests {
52+
tt := tt
53+
5054
t.Run(tt.name, func(t *testing.T) {
5155
got, err := MakeName(tt.args.year, tt.args.puzzle)
5256
if tt.wantErr {

puzzles/solutions/2019/day01/solution.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ 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"
1312
)
1413

1514
type solution struct {
1615
name string
1716
}
1817

1918
func init() {
20-
puzzleName, err := solutions.MakeName("2019", "day01")
19+
puzzleName, err := puzzles.MakeName("2019", "day01")
2120
if err != nil {
2221
panic(err)
2322
}

puzzles/solutions/doc.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Package declares common interface for puzzle solutions and functionality for register and run them.
1+
// Package solutions registers solutions of puzzles.
22
//
3-
// Each solution should implement `Solver` interface, be implemented udnder separate package and contain `init()`
3+
// Each solution should implement `Solver` interface, be implemented under separate package and contain `init()`
44
// function that will register that solution in list of all solvers.
55
//
66
// Example:
@@ -20,7 +20,11 @@
2020
// }
2121
//
2222
// Then to register solution in the list of all solutions: make a blank import of package with puzzle solution
23-
// at main.go
23+
// at register.go
2424
//
2525
// import _ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/day01"
26+
//
27+
// And then blank import solutions package at main.go to register all solutions
28+
//
29+
// import _ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions
2630
package solutions

puzzles/solutions/register.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package solutions
2+
3+
import (
4+
_ "github.com/oleg-balunenko/advent-of-code/puzzles/solutions/2019/day01" // register day01 solution
5+
)

puzzles/solver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package puzzles declares common interface for puzzle solutions and functionality for register and run them.
12
package puzzles
23

34
import (

0 commit comments

Comments
 (0)