test: add test for part two
This commit is contained in:
@@ -32,3 +32,27 @@ func TestPartOne(t *testing.T) {
|
|||||||
t.Errorf("PartOne() printed %q, want %q", got, expected)
|
t.Errorf("PartOne() printed %q, want %q", got, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPartTwo(t *testing.T) {
|
||||||
|
expected := "05ace8e3"
|
||||||
|
|
||||||
|
oldStdout := os.Stdout
|
||||||
|
r, w, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create pipe: %v", err)
|
||||||
|
}
|
||||||
|
os.Stdout = w
|
||||||
|
|
||||||
|
PartTwo(testInput)
|
||||||
|
|
||||||
|
_ = 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user