You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package adventoc2024
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func dup(input string) (io.Reader, io.Reader) {
|
|
|
|
return strings.NewReader(input), strings.NewReader(input)
|
|
|
|
}
|
|
|
|
|
|
|
|
type puzzle interface {
|
|
|
|
Part1(io.Reader) string
|
|
|
|
Part2(io.Reader) string
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPuzzles(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
solver puzzle
|
|
|
|
ans1 string
|
|
|
|
ans2 string
|
|
|
|
input string
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
solver: Day1{},
|
|
|
|
ans1: "11",
|
|
|
|
ans2: "31",
|
|
|
|
input: `3 4
|
|
|
|
4 3
|
|
|
|
2 5
|
|
|
|
1 3
|
|
|
|
3 9
|
|
|
|
3 3`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
solver: Day2{},
|
|
|
|
ans1: "2",
|
|
|
|
ans2: "4",
|
|
|
|
input: `7 6 4 2 1
|
|
|
|
1 2 7 8 9
|
|
|
|
9 7 6 2 1
|
|
|
|
1 3 2 4 5
|
|
|
|
8 6 4 4 1
|
|
|
|
1 3 6 7 9`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
name := fmt.Sprintf("Day%d", i+1)
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
p1, p2 := dup(tt.input)
|
|
|
|
if got := tt.solver.Part1(p1); got != tt.ans1 {
|
|
|
|
t.Errorf("Part 1 = %s; expected %s", got, tt.ans1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if got := tt.solver.Part2(p2); got != tt.ans2 {
|
|
|
|
t.Errorf("Part 2 = %s; expected %s", got, tt.ans2)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|