You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.1 KiB
Go
117 lines
2.1 KiB
Go
package day18
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.paas.celticinfo.fr/oabrivard/aoc2023/utils"
|
|
)
|
|
|
|
func TestMatrixSize(t *testing.T) {
|
|
lines := []string{
|
|
"R 6 (#70c710)",
|
|
"D 5 (#0dc571)",
|
|
"L 2 (#5713f0)",
|
|
"D 2 (#d2c081)",
|
|
"R 2 (#59c680)",
|
|
"D 2 (#411b91)",
|
|
"L 5 (#8ceee2)",
|
|
"U 2 (#caa173)",
|
|
"L 1 (#1b58a2)",
|
|
"U 2 (#caa171)",
|
|
"R 2 (#7807d2)",
|
|
"U 3 (#a77fa3)",
|
|
"L 2 (#015232)",
|
|
"U 2 (#7a21e3)",
|
|
}
|
|
|
|
minCol, minRow, maxRow, maxCol := matrixSize(lines)
|
|
height, width := maxRow-minRow+1, maxCol-minCol+1
|
|
result := height * width
|
|
|
|
if result != 70 {
|
|
t.Fatalf("expected 70, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestMatrixSizeWithInput(t *testing.T) {
|
|
lines := utils.ReadLines("input.txt")
|
|
|
|
minCol, minRow, maxRow, maxCol := matrixSize(lines)
|
|
height, width := maxRow-minRow+1, maxCol-minCol+1
|
|
result := height * width
|
|
|
|
if result != 88464 {
|
|
t.Fatalf("expected 88464, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestPart1(t *testing.T) {
|
|
lines := []string{
|
|
"R 6 (#70c710)",
|
|
"D 5 (#0dc571)",
|
|
"L 2 (#5713f0)",
|
|
"D 2 (#d2c081)",
|
|
"R 2 (#59c680)",
|
|
"D 2 (#411b91)",
|
|
"L 5 (#8ceee2)",
|
|
"U 2 (#caa173)",
|
|
"L 1 (#1b58a2)",
|
|
"U 2 (#caa171)",
|
|
"R 2 (#7807d2)",
|
|
"U 3 (#a77fa3)",
|
|
"L 2 (#015232)",
|
|
"U 2 (#7a21e3)",
|
|
}
|
|
|
|
result := Part1(lines, true)
|
|
|
|
if result != 62 {
|
|
t.Fatalf("expected 62, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestPart1WithInput(t *testing.T) {
|
|
lines := utils.ReadLines("input.txt")
|
|
|
|
result := Part1(lines, false)
|
|
|
|
if result != 41019 {
|
|
t.Fatalf("expected 41019, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestPart2(t *testing.T) {
|
|
lines := []string{
|
|
"R 6 (#70c710)",
|
|
"D 5 (#0dc571)",
|
|
"L 2 (#5713f0)",
|
|
"D 2 (#d2c081)",
|
|
"R 2 (#59c680)",
|
|
"D 2 (#411b91)",
|
|
"L 5 (#8ceee2)",
|
|
"U 2 (#caa173)",
|
|
"L 1 (#1b58a2)",
|
|
"U 2 (#caa171)",
|
|
"R 2 (#7807d2)",
|
|
"U 3 (#a77fa3)",
|
|
"L 2 (#015232)",
|
|
"U 2 (#7a21e3)",
|
|
}
|
|
|
|
result := Part2(lines)
|
|
|
|
if result != 952408144115 {
|
|
t.Fatalf("expected 952408144115, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestPart2WithInput(t *testing.T) {
|
|
lines := utils.ReadLines("input.txt")
|
|
|
|
result := Part2(lines)
|
|
|
|
if result != 96116995735219 {
|
|
t.Fatalf("expected 96116995735219, got %v", result)
|
|
}
|
|
}
|