Skip to content

Commit

Permalink
feat(puzzles): Add spec and tests for 2016/da03
Browse files Browse the repository at this point in the history
  • Loading branch information
obalunenko committed Dec 18, 2022
1 parent 62c15fa commit f1a5e7e
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/puzzles/solutions/2016/day03/solution.go
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
}
123 changes: 123 additions & 0 deletions internal/puzzles/solutions/2016/day03/solution_test.go
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)
})
}
}
18 changes: 18 additions & 0 deletions internal/puzzles/solutions/2016/day03/spec.md
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?
2 changes: 2 additions & 0 deletions internal/puzzles/solutions/register_2016.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ import (
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day01"
// register day02 solution.
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day02"
// register day03 solution.
_ "github.com/obalunenko/advent-of-code/internal/puzzles/solutions/2016/day03"
)

0 comments on commit f1a5e7e

Please sign in to comment.