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.
229 lines
4.0 KiB
Go
229 lines
4.0 KiB
Go
package day8
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.paas.celticinfo.fr/oabrivard/aoc2023/utils"
|
|
)
|
|
|
|
func TestCountSteps1(t *testing.T) {
|
|
lines := []string{
|
|
"RL",
|
|
"",
|
|
"AAA = (BBB, CCC)",
|
|
"BBB = (DDD, EEE)",
|
|
"CCC = (ZZZ, GGG)",
|
|
"DDD = (DDD, DDD)",
|
|
"EEE = (EEE, EEE)",
|
|
"GGG = (GGG, GGG)",
|
|
"ZZZ = (ZZZ, ZZZ)",
|
|
}
|
|
|
|
result := CountSteps(lines)
|
|
|
|
if result != 2 {
|
|
t.Fatalf("expected 2, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountSteps2(t *testing.T) {
|
|
lines := []string{
|
|
"LLR",
|
|
"",
|
|
"AAA = (BBB, BBB)",
|
|
"BBB = (AAA, ZZZ)",
|
|
"ZZZ = (ZZZ, ZZZ)",
|
|
}
|
|
|
|
result := CountSteps(lines)
|
|
|
|
if result != 6 {
|
|
t.Fatalf("expected 6, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountStepsWithInput(t *testing.T) {
|
|
lines := utils.ReadLines("input.txt")
|
|
result := CountSteps(lines)
|
|
|
|
if result != 14257 {
|
|
t.Fatalf("expected 14257, got %d", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps1(t *testing.T) {
|
|
lines := []string{
|
|
"LR",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (XXX, 11Z)",
|
|
"11Z = (11B, XXX)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 6 {
|
|
t.Fatalf("expected 6, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps2(t *testing.T) {
|
|
lines := []string{
|
|
"LR",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (XXX, 11Z)",
|
|
"11Z = (11B, XXX)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 4 {
|
|
t.Fatalf("expected 4, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps3(t *testing.T) {
|
|
lines := []string{
|
|
"LR",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (XXX, 11Z)",
|
|
"11Z = (11B, XXX)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22E, 22E)",
|
|
"22E = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 10 {
|
|
t.Fatalf("expected 10, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps4(t *testing.T) {
|
|
lines := []string{
|
|
"LRL",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (11Z, 11Z)",
|
|
"11Z = (11B, 11B)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22E, 22E)",
|
|
"22E = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 10 {
|
|
t.Fatalf("expected 10, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps5(t *testing.T) {
|
|
lines := []string{
|
|
"LRL",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (11Z, 11Z)",
|
|
"11Z = (11B, 11B)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 4 {
|
|
t.Fatalf("expected 4, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelSteps6(t *testing.T) {
|
|
lines := []string{
|
|
"LRL",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (11Z, 11Z)",
|
|
"11Z = (11B, 11B)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"33A = (33B, XXX)",
|
|
"33B = (33C, 33C)",
|
|
"33C = (33D, 33D)",
|
|
"33D = (33E, 33E)",
|
|
"33E = (33Z, 33Z)",
|
|
"33Z = (33B, 33B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 20 {
|
|
t.Fatalf("expected 20, got %v", result)
|
|
}
|
|
}
|
|
func TestCountParallelSteps7(t *testing.T) {
|
|
lines := []string{
|
|
"LRL",
|
|
"",
|
|
"11A = (11B, XXX)",
|
|
"11B = (11Z, 11Z)",
|
|
"11Z = (11B, 11B)",
|
|
"22A = (22B, XXX)",
|
|
"22B = (22C, 22C)",
|
|
"22C = (22D, 22D)",
|
|
"22D = (22Z, 22Z)",
|
|
"22Z = (22B, 22B)",
|
|
"33A = (33B, XXX)",
|
|
"33B = (33C, 33C)",
|
|
"33C = (33D, 33D)",
|
|
"33D = (33E, 33E)",
|
|
"33E = (33F, 33F)",
|
|
"33F = (33Z, 33Z)",
|
|
"33Z = (33B, 33B)",
|
|
"XXX = (XXX, XXX)",
|
|
}
|
|
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 12 {
|
|
t.Fatalf("expected 12, got %v", result)
|
|
}
|
|
}
|
|
|
|
func TestCountParallelStepsWithInput(t *testing.T) {
|
|
lines := utils.ReadLines("input.txt")
|
|
result := CountParallelSteps(lines)
|
|
|
|
if result != 14257 {
|
|
t.Fatalf("expected 14257, got %d", result)
|
|
}
|
|
}
|