Skip to content

Commit 770dc49

Browse files
committed
feat(puzzles): Add spec and tests for 2016/da03
1 parent 79a832c commit 770dc49

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Package day03 contains solution for https://adventofcode.com/2016/day/3 puzzle.
2+
package day03
3+
4+
import (
5+
"io"
6+
7+
"github.com/obalunenko/advent-of-code/internal/puzzles"
8+
)
9+
10+
func init() {
11+
puzzles.Register(solution{})
12+
}
13+
14+
type solution struct{}
15+
16+
func (s solution) Year() string {
17+
return puzzles.Year2016.String()
18+
}
19+
20+
func (s solution) Day() string {
21+
return puzzles.Day03.String()
22+
}
23+
24+
func (s solution) Part1(input io.Reader) (string, error) {
25+
return "", puzzles.ErrNotImplemented
26+
}
27+
28+
func (s solution) Part2(input io.Reader) (string, error) {
29+
return "", puzzles.ErrNotImplemented
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package day03
2+
3+
import (
4+
"errors"
5+
"io"
6+
"strings"
7+
"testing"
8+
"testing/iotest"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func Test_solution_Year(t *testing.T) {
14+
var s solution
15+
16+
want := "2016"
17+
got := s.Year()
18+
19+
assert.Equal(t, want, got)
20+
}
21+
22+
func Test_solution_Day(t *testing.T) {
23+
var s solution
24+
25+
want := "3"
26+
got := s.Day()
27+
28+
assert.Equal(t, want, got)
29+
}
30+
31+
func Test_solution_Part1(t *testing.T) {
32+
var s solution
33+
34+
type args struct {
35+
input io.Reader
36+
}
37+
38+
tests := []struct {
39+
name string
40+
args args
41+
want string
42+
wantErr assert.ErrorAssertionFunc
43+
}{
44+
{
45+
name: "test example from description",
46+
args: args{
47+
input: strings.NewReader("5 10 25\n"),
48+
},
49+
want: "0",
50+
wantErr: assert.NoError,
51+
},
52+
{
53+
name: "test example from description",
54+
args: args{
55+
input: strings.NewReader("5 10 7\n"),
56+
},
57+
want: "1",
58+
wantErr: assert.NoError,
59+
},
60+
{
61+
name: "",
62+
args: args{
63+
input: iotest.ErrReader(errors.New("custom error")),
64+
},
65+
want: "",
66+
wantErr: assert.Error,
67+
},
68+
}
69+
70+
for _, tt := range tests {
71+
t.Run(tt.name, func(t *testing.T) {
72+
got, err := s.Part1(tt.args.input)
73+
if !tt.wantErr(t, err) {
74+
return
75+
}
76+
77+
assert.Equal(t, tt.want, got)
78+
})
79+
}
80+
}
81+
82+
func Test_solution_Part2(t *testing.T) {
83+
var s solution
84+
85+
type args struct {
86+
input io.Reader
87+
}
88+
89+
tests := []struct {
90+
name string
91+
args args
92+
want string
93+
wantErr assert.ErrorAssertionFunc
94+
}{
95+
{
96+
name: "test example from description",
97+
args: args{
98+
input: strings.NewReader(""),
99+
},
100+
want: "230",
101+
wantErr: assert.NoError,
102+
},
103+
{
104+
name: "",
105+
args: args{
106+
input: iotest.ErrReader(errors.New("custom error")),
107+
},
108+
want: "",
109+
wantErr: assert.Error,
110+
},
111+
}
112+
113+
for _, tt := range tests {
114+
t.Run(tt.name, func(t *testing.T) {
115+
got, err := s.Part2(tt.args.input)
116+
if !tt.wantErr(t, err) {
117+
return
118+
}
119+
120+
assert.Equal(t, tt.want, got)
121+
})
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# --- Day 3: Squares With Three Sides ---
2+
3+
## --- Part One ---
4+
5+
Now that you can think clearly, you move deeper into the labyrinth of hallways and office furniture that makes up this
6+
part of Easter Bunny HQ. This must be a graphic design department; the walls are covered in specifications for
7+
triangles.
8+
9+
Or are they?
10+
11+
The design document gives the side lengths of each triangle it describes, but... `5 10 25`?
12+
Some of these aren't triangles. You can't help but mark the impossible ones.
13+
14+
In a valid triangle, the sum of any two sides must be larger than the remaining side.
15+
16+
For example, the "triangle" given above is impossible, because `5 + 10` is not larger than `25`.
17+
18+
In your puzzle input, how many of the listed triangles are possible?

internal/puzzles/solutions/register_2016.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ import (
88
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day01"
99
// register day02 solution.
1010
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day02"
11+
// register day03 solution.
12+
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day03"
1113
)

0 commit comments

Comments
 (0)