package main import ( "testing" ) var example = `Sensor at x=2, y=18: closest beacon is at x=-2, y=15 Sensor at x=9, y=16: closest beacon is at x=10, y=16 Sensor at x=13, y=2: closest beacon is at x=15, y=3 Sensor at x=12, y=14: closest beacon is at x=10, y=16 Sensor at x=10, y=20: closest beacon is at x=10, y=16 Sensor at x=14, y=17: closest beacon is at x=10, y=16 Sensor at x=8, y=7: closest beacon is at x=2, y=10 Sensor at x=2, y=0: closest beacon is at x=2, y=10 Sensor at x=0, y=11: closest beacon is at x=2, y=10 Sensor at x=20, y=14: closest beacon is at x=25, y=17 Sensor at x=17, y=20: closest beacon is at x=21, y=22 Sensor at x=16, y=7: closest beacon is at x=15, y=3 Sensor at x=14, y=3: closest beacon is at x=15, y=3 Sensor at x=20, y=1: closest beacon is at x=15, y=3` func Test_part1(t *testing.T) { tests := []struct { name string input string targetRow int want int }{ { name: "example", input: example, targetRow: 10, want: 26, }, { name: "actual", input: input, targetRow: 2000000, want: 4560025, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := part1(tt.input, tt.targetRow); got != tt.want { t.Errorf("part1() = %v, want %v", got, tt.want) } }) } } func Test_part2(t *testing.T) { tests := []struct { name string input string coordLimit int want int }{ { name: "example", input: example, coordLimit: 20, want: 56000011, }, { name: "actual", input: input, coordLimit: 4000000, want: 12480406634249, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := part2(tt.input, tt.coordLimit); got != tt.want { t.Errorf("part2() = %v, want %v", got, tt.want) } }) } }