|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDay01(t *testing.T) {
|
|
|
|
ans1 := "142"
|
|
|
|
input1 := `1abc2
|
|
|
|
pqr3stu8vwx
|
|
|
|
a1b2c3d4e5f
|
|
|
|
treb7uchet`
|
|
|
|
|
|
|
|
ans2 := "281"
|
|
|
|
input2 := `two1nine
|
|
|
|
eightwothree
|
|
|
|
abcone2threexyz
|
|
|
|
xtwone3four
|
|
|
|
4nineeightseven2
|
|
|
|
zoneight234
|
|
|
|
7pqrstsixteen`
|
|
|
|
|
|
|
|
puzzle := day01{}
|
|
|
|
|
|
|
|
res1 := puzzle.solve1(strings.NewReader(input1))
|
|
|
|
t.Logf("day 1 solution 1: %s", res1)
|
|
|
|
if res1 != ans1 {
|
|
|
|
t.Errorf("day 1 solution 1 = %s; wanted %s", res1, ans1)
|
|
|
|
}
|
|
|
|
|
|
|
|
res2 := puzzle.solve2(strings.NewReader(input2))
|
|
|
|
t.Logf("day 1 solution 2: %s", res2)
|
|
|
|
if res2 != ans2 {
|
|
|
|
t.Errorf("day 1 solution 2 = %s; wanted %s", res2, ans2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDay02(t *testing.T) {
|
|
|
|
input := `Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
|
|
|
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
|
|
|
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
|
|
|
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
|
|
|
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green`
|
|
|
|
|
|
|
|
puzzle := day02{}
|
|
|
|
|
|
|
|
ans1 := "8"
|
|
|
|
res1 := puzzle.solve1(strings.NewReader(input))
|
|
|
|
t.Logf("day 2 solution 1: %s", res1)
|
|
|
|
if res1 != ans1 {
|
|
|
|
t.Errorf("day 2 solution 1 = %s; wanted %s", res1, ans1)
|
|
|
|
}
|
|
|
|
|
|
|
|
ans2 := "2286"
|
|
|
|
res2 := puzzle.solve2(strings.NewReader(input))
|
|
|
|
t.Logf("day 2 solution 2: %s", res2)
|
|
|
|
if res2 != ans2 {
|
|
|
|
t.Errorf("day 2 solution 2 = %s; wanted %s", res2, ans2)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDay03(t *testing.T) {
|
|
|
|
input1 := `467..114..
|
|
|
|
...*......
|
|
|
|
..35..633.
|
|
|
|
......#...
|
|
|
|
617*......
|
|
|
|
.....+.58.
|
|
|
|
..592.....
|
|
|
|
......755.
|
|
|
|
...$.*....
|
|
|
|
.664.598..`
|
|
|
|
|
|
|
|
puzzle := day03{}
|
|
|
|
|
|
|
|
ans1 := "4361"
|
|
|
|
res1 := puzzle.solve1(strings.NewReader(input1))
|
|
|
|
if res1 != ans1 {
|
|
|
|
t.Errorf("day 3 solution 1 = %s; wanted %s", res1, ans1)
|
|
|
|
}
|
|
|
|
}
|