-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(puzzles): Add spec and tests for 2016/da03
- Loading branch information
1 parent
62c15fa
commit f1a5e7e
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Package day03 contains solution for https://adventofcode.com/2016/day/3 puzzle. | ||
package day03 | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/obalunenko/advent-of-code/internal/puzzles" | ||
) | ||
|
||
func init() { | ||
puzzles.Register(solution{}) | ||
} | ||
|
||
type solution struct{} | ||
|
||
func (s solution) Year() string { | ||
return puzzles.Year2016.String() | ||
} | ||
|
||
func (s solution) Day() string { | ||
return puzzles.Day03.String() | ||
} | ||
|
||
func (s solution) Part1(input io.Reader) (string, error) { | ||
return "", puzzles.ErrNotImplemented | ||
} | ||
|
||
func (s solution) Part2(input io.Reader) (string, error) { | ||
return "", puzzles.ErrNotImplemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package day03 | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"strings" | ||
"testing" | ||
"testing/iotest" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_solution_Year(t *testing.T) { | ||
var s solution | ||
|
||
want := "2016" | ||
got := s.Year() | ||
|
||
assert.Equal(t, want, got) | ||
} | ||
|
||
func Test_solution_Day(t *testing.T) { | ||
var s solution | ||
|
||
want := "3" | ||
got := s.Day() | ||
|
||
assert.Equal(t, want, got) | ||
} | ||
|
||
func Test_solution_Part1(t *testing.T) { | ||
var s solution | ||
|
||
type args struct { | ||
input io.Reader | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "test example from description", | ||
args: args{ | ||
input: strings.NewReader("5 10 25\n"), | ||
}, | ||
want: "0", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "test example from description", | ||
args: args{ | ||
input: strings.NewReader("5 10 7\n"), | ||
}, | ||
want: "1", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "", | ||
args: args{ | ||
input: iotest.ErrReader(errors.New("custom error")), | ||
}, | ||
want: "", | ||
wantErr: assert.Error, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := s.Part1(tt.args.input) | ||
if !tt.wantErr(t, err) { | ||
return | ||
} | ||
|
||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func Test_solution_Part2(t *testing.T) { | ||
var s solution | ||
|
||
type args struct { | ||
input io.Reader | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "test example from description", | ||
args: args{ | ||
input: strings.NewReader(""), | ||
}, | ||
want: "230", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "", | ||
args: args{ | ||
input: iotest.ErrReader(errors.New("custom error")), | ||
}, | ||
want: "", | ||
wantErr: assert.Error, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := s.Part2(tt.args.input) | ||
if !tt.wantErr(t, err) { | ||
return | ||
} | ||
|
||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# --- Day 3: Squares With Three Sides --- | ||
|
||
## --- Part One --- | ||
|
||
Now that you can think clearly, you move deeper into the labyrinth of hallways and office furniture that makes up this | ||
part of Easter Bunny HQ. This must be a graphic design department; the walls are covered in specifications for | ||
triangles. | ||
|
||
Or are they? | ||
|
||
The design document gives the side lengths of each triangle it describes, but... `5 10 25`? | ||
Some of these aren't triangles. You can't help but mark the impossible ones. | ||
|
||
In a valid triangle, the sum of any two sides must be larger than the remaining side. | ||
|
||
For example, the "triangle" given above is impossible, because `5 + 10` is not larger than `25`. | ||
|
||
In your puzzle input, how many of the listed triangles are possible? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters