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
import "testing"
var testInput = []string{
"abcdef",
"bababc",
"abbcde",
"abcccd",
"aabcdd",
"abcdee",
"ababab",
}
import (
"bytes"
"os"
"strings"
"testing"
)
func TestPartOne(t *testing.T) {
input := []string{
"abcdef",
"bababc",
"abbcde",
"abcccd",
"aabcdd",
"abcdee",
"ababab",
}
expected := 12
got := PartOne(testInput)
got := PartOne(input)
if 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)
}
}