Updated test suite to use interface based tests
This commit is contained in:
parent
3fc72e2bc2
commit
5c90e73a5a
23 changed files with 389 additions and 538 deletions
|
|
@ -13,47 +13,37 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestDay%02d(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %%v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := -1
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%%d\ngot:\t%%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := -1
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%%d\ngot:\t%%d", expectedPart2, part2)
|
||||
}
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
// func TestDay%02dSolutions(t *testing.T) {
|
||||
// filename := "input.txt"
|
||||
// if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
// t.Fatalf("test file does not exist: %%v", filename)
|
||||
// }
|
||||
//
|
||||
// part1, part2 := Run(filename)
|
||||
//
|
||||
// expectedPart1 := -1
|
||||
// if part1 != expectedPart1 {
|
||||
// t.Fatalf("unexpected part1:\nwant:\t%%d\ngot:\t%%d", expectedPart1, part1)
|
||||
// }
|
||||
//
|
||||
// expectedPart2 := -1
|
||||
// if part2 != expectedPart2 {
|
||||
// t.Fatalf("unexpected part2:\nwant:\t%%d\ngot:\t%%d", expectedPart2, part2)
|
||||
// }
|
||||
// }
|
||||
func TestDay%02d(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{"test.txt", -1, -1},
|
||||
// {"input.txt", -1, -1},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %%v", test.FileName)
|
||||
}
|
||||
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%%s: unexpected part1:\nwant:\t%%v\ngot:\t%%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%%s: unexpected part2:\nwant:\t%%v\ngot:\t%%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
func generateTestCode(day int) error {
|
||||
testCode := fmt.Sprintf(testCodeTemplate, day, day, day)
|
||||
testCode := fmt.Sprintf(testCodeTemplate, day, day)
|
||||
|
||||
filename := fmt.Sprintf("./day%02d/day%02d_test.go", day, day)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay1(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 11, 31},
|
||||
{"input.txt", 1258579, 23981443},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 11
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 31
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay1Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 1258579
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 23981443
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay2(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 2, 4},
|
||||
{"input.txt", 663, 692},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 2
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 4
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay2Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 663
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 692
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay3(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 161, 48},
|
||||
{"input.txt", 187833789, 94455185},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 161
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 48
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay3Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 187833789
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 94455185
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay4(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 18, 9},
|
||||
{"input.txt", 2603, 1965},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 18
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 9
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay4Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 2603
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 1965
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay5(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 143, 123},
|
||||
{"input.txt", 6498, 5017},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 143
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 123
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay5Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 6498
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 5017
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay6(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 41, 6},
|
||||
{"input.txt", 5101, 1951},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 41
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 6
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay6Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 5101
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 1951
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay7(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 3749, 11387},
|
||||
{"input.txt", 303876485655, 146111650210682},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 3749
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 11387
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay7Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 303876485655
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 146111650210682
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay8(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 14, 34},
|
||||
{"input.txt", 327, 1233},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 14
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 34
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay8Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 327
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 1233
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay9(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 1928, 2858},
|
||||
{"input.txt", 6435922584968, 6469636832766},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 1928
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 2858
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay9Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 6435922584968
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 6469636832766
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,31 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay10(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 1, 16},
|
||||
{"test2.txt", 36, 81},
|
||||
{"input.txt", 461, 875},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 36
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 81
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay10Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 461
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 875
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
89010123
|
||||
78121874
|
||||
87430965
|
||||
96549874
|
||||
45678903
|
||||
32019012
|
||||
01329801
|
||||
10456732
|
||||
0123
|
||||
1234
|
||||
8765
|
||||
9876
|
||||
|
|
|
|||
8
2024/day10/test2.txt
Normal file
8
2024/day10/test2.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
89010123
|
||||
78121874
|
||||
87430965
|
||||
96549874
|
||||
45678903
|
||||
32019012
|
||||
01329801
|
||||
10456732
|
||||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay11(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 55312, 65601038650482},
|
||||
{"input.txt", 197157, 234430066982597},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 55312
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 65601038650482
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay11Solution(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 197157
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 234430066982597
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,31 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestDay12(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 1930
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 1206
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
// func TestDay12Solutions(t *testing.T) {
|
||||
// filename := "input.txt"
|
||||
// if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
// t.Fatalf("test file does not exist: %v", filename)
|
||||
// }
|
||||
//
|
||||
// part1, part2 := Run(filename)
|
||||
//
|
||||
// expectedPart1 := -1
|
||||
// if part1 != expectedPart1 {
|
||||
// t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
// }
|
||||
//
|
||||
// expectedPart2 := -1
|
||||
// if part2 != expectedPart2 {
|
||||
// t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
// }
|
||||
// }
|
||||
func TestDay12(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{"test.txt", 140, 80},
|
||||
{"test2.txt", 1930, 1206},
|
||||
{"input.txt", 1375574, 830566},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,4 @@
|
|||
RRRRIICCFF
|
||||
RRRRIICCCF
|
||||
VVRRRCCFFF
|
||||
VVRCCCJFFF
|
||||
VVVVCJJCFE
|
||||
VVIVCCJJEE
|
||||
VVIIICJJEE
|
||||
MIIIIIJJEE
|
||||
MIIISIJEEE
|
||||
MMMISSJEEE
|
||||
AAAA
|
||||
BBCD
|
||||
BBCC
|
||||
EEEC
|
||||
|
|
|
|||
10
2024/day12/test2.txt
Normal file
10
2024/day12/test2.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
RRRRIICCFF
|
||||
RRRRIICCCF
|
||||
VVRRRCCFFF
|
||||
VVRCCCJFFF
|
||||
VVVVCJJCFE
|
||||
VVIVCCJJEE
|
||||
VVIIICJJEE
|
||||
MIIIIIJJEE
|
||||
MIIISIJEEE
|
||||
MMMISSJEEE
|
||||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay13(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 480, 875318608908},
|
||||
{"input.txt", 35997, 82510994362072},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 480
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 875318608908
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay13Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 35997
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 82510994362072
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,35 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay14(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 21, 17},
|
||||
{"input.txt", 211692000, 6587},
|
||||
}
|
||||
|
||||
part1, _ := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 21
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay14Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 211692000
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 6587
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay15(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", 10092, 9021},
|
||||
{"input.txt", 1497888, 1522420},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 10092
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 9021
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay15Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 1497888
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 1522420
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,40 +5,31 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestDay16(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := 11048
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 64
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay16Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
func TestDay15(t *testing.T) {
|
||||
tests := []TestCase{
|
||||
{"test.txt", 11048, 64},
|
||||
{"test2.txt", 7036, 45},
|
||||
{"input.txt", 98520, 609},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := 98520
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%d\ngot:\t%d", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("%s: unexpected part1:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 609
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("%s: unexpected part2:\nwant:\t%v\ngot:\t%v", test.FileName, test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
2024/day16/test2.txt
Normal file
15
2024/day16/test2.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
###############
|
||||
#.......#....E#
|
||||
#.#.###.#.###.#
|
||||
#.....#.#...#.#
|
||||
#.###.#####.#.#
|
||||
#.#.#.......#.#
|
||||
#.#.#####.###.#
|
||||
#...........#.#
|
||||
###.#.#####.#.#
|
||||
#...#.....#.#.#
|
||||
#.#.#.###.#.#.#
|
||||
#.....#...#.#.#
|
||||
#.###.#.#.#.#.#
|
||||
#S..#.....#...#
|
||||
###############
|
||||
|
|
@ -5,40 +5,30 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
type TestCase struct {
|
||||
FileName string
|
||||
Part1 interface{}
|
||||
Part2 interface{}
|
||||
}
|
||||
|
||||
func TestDay17(t *testing.T) {
|
||||
filename := "test.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
tests := []TestCase{
|
||||
{"test.txt", "5,7,3,0", 117440},
|
||||
{"input.txt", "2,3,6,2,1,6,1,2,1", 90938893795561},
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
for _, test := range tests {
|
||||
if _, err := os.Stat(test.FileName); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", test.FileName)
|
||||
}
|
||||
|
||||
expectedPart1 := "5,7,3,0"
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%s\ngot:\t%s", expectedPart1, part1)
|
||||
}
|
||||
part1, part2 := Run(test.FileName)
|
||||
if test.Part1 != nil && part1 != test.Part1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%v\ngot:\t%v", test.Part1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 117440
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDay17Solutions(t *testing.T) {
|
||||
filename := "input.txt"
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
t.Fatalf("test file does not exist: %v", filename)
|
||||
}
|
||||
|
||||
part1, part2 := Run(filename)
|
||||
|
||||
expectedPart1 := "2,3,6,2,1,6,1,2,1"
|
||||
if part1 != expectedPart1 {
|
||||
t.Fatalf("unexpected part1:\nwant:\t%s\ngot:\t%s", expectedPart1, part1)
|
||||
}
|
||||
|
||||
expectedPart2 := 90938893795561
|
||||
if part2 != expectedPart2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%d\ngot:\t%d", expectedPart2, part2)
|
||||
if test.Part2 != nil && part2 != test.Part2 {
|
||||
t.Fatalf("unexpected part2:\nwant:\t%v\ngot:\t%v", test.Part2, part2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue