From 57a21fd1ea68e54802fe88fc1833f5a2d3a7e94c Mon Sep 17 00:00:00 2001 From: Alexander Avery Date: Mon, 2 Dec 2024 22:59:33 -0500 Subject: [PATCH] tests for puzzle day 2 --- 2024/puzzle_test.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/2024/puzzle_test.go b/2024/puzzle_test.go index 623cced..9379376 100644 --- a/2024/puzzle_test.go +++ b/2024/puzzle_test.go @@ -1,10 +1,15 @@ -package main +package adventoc2024 import ( + "io" "strings" "testing" ) +func dup(input string) (io.Reader, io.Reader) { + return strings.NewReader(input), strings.NewReader(input) +} + func TestDay01(t *testing.T) { input := `3 4 4 3 @@ -13,7 +18,7 @@ func TestDay01(t *testing.T) { 3 9 3 3` - p1, p2 := strings.NewReader(input), strings.NewReader(input) + p1, p2 := dup(input) if got, expected := part1(p1), "11"; got != expected { t.Errorf("day01 part 1 = %s; expected %s", got, expected) @@ -23,3 +28,25 @@ func TestDay01(t *testing.T) { t.Errorf("day01 part 2 = %s; expected %s", got, expected) } } + +func TestDay02(t *testing.T) { + input := `7 6 4 2 1 +1 2 7 8 9 +9 7 6 2 1 +1 3 2 4 5 +8 6 4 4 1 +1 3 6 7 9` + + p1, p2 := dup(input) + + solver := Day2{} + + if got, expected := solver.Part1(p1), "2"; got != expected { + t.Errorf("day 2 part 1 = %s; expected %s", got, expected) + } + + if got, expected := solver.Part2(p2), "4"; got != expected { + t.Errorf("day 2 part 2 = %s; expected %s", got, expected) + } + +}