test: adapted p2 test as it expects string and not int

This commit is contained in:
2025-11-30 13:04:08 +01:00
parent 959c05b769
commit 20ab5fe4e5

View File

@@ -1,21 +1,58 @@
package daytwo package daytwo
import "testing" import (
"bytes"
var testInput = []string{ "os"
"abcdef", "strings"
"bababc", "testing"
"abbcde", )
"abcccd",
"aabcdd",
"abcdee",
"ababab",
}
func TestPartOne(t *testing.T) { func TestPartOne(t *testing.T) {
input := []string{
"abcdef",
"bababc",
"abbcde",
"abcccd",
"aabcdd",
"abcdee",
"ababab",
}
expected := 12 expected := 12
got := PartOne(testInput) got := PartOne(input)
if got != expected { if got != expected {
t.Errorf("PartOne() = %d, want %d", got, expected) t.Errorf("PartOne() = %d, want %d", got, expected)
} }
} }
func TestPartTwo(t *testing.T) {
input := []string{
"abcde",
"fghij",
"klmno",
"pqrst",
"fguij",
"axcye",
"wvxyz",
}
expected := "fgij"
oldStdout := os.Stdout
r, w, err := os.Pipe()
if err != nil {
t.Fatalf("Failed to create pipe: %v", err)
}
os.Stdout = w
PartTwo(input)
w.Close()
os.Stdout = oldStdout
var buffer bytes.Buffer
buffer.ReadFrom(r)
got := strings.TrimSpace(buffer.String())
if got != expected {
t.Errorf("PartTwo() printed %q, want %q", got, expected)
}
}