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.

86 lines
1.5 KiB
Go

package day15
import (
"testing"
"gitea.paas.celticinfo.fr/oabrivard/aoc2023/utils"
)
func TestHash(t *testing.T) {
result := hash([]byte("rn=1"))
if result != 30 {
t.Fatalf("expected 30, got %v", result)
}
result = hash([]byte("cm-"))
if result != 253 {
t.Fatalf("expected 253, got %v", result)
}
result = hash([]byte("qp=3"))
if result != 97 {
t.Fatalf("expected 97, got %v", result)
}
result = hash([]byte("cm=2"))
if result != 47 {
t.Fatalf("expected 47, got %v", result)
}
result = hash([]byte("qp-"))
if result != 14 {
t.Fatalf("expected 14, got %v", result)
}
}
func TestSumHashes(t *testing.T) {
result := SumHashes("rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7,")
if result != 1320 {
t.Fatalf("expected 1320, got %v", result)
}
}
func TestSumHashesWithInput(t *testing.T) {
lines := utils.ReadLines("input.txt")
result := SumHashes(lines[0])
if result != 511416 {
t.Fatalf("expected 511416, got %v", result)
}
}
func TestSumBoxes(t *testing.T) {
result := SumBoxes("rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7,")
if result != 145 {
t.Fatalf("expected 145, got %v", result)
}
}
func TestSumBoxesWithInput(t *testing.T) {
lines := utils.ReadLines("input.txt")
result := SumBoxes(lines[0])
if result != 290779 {
t.Fatalf("expected 290779, got %v", result)
}
}
func TestPart1WithInput(t *testing.T) {
lines := utils.ReadLines("input.txt")
result := Part1(lines[0])
if result != 511416 {
t.Fatalf("expected 511416, got %v", result)
}
}