test: adapted p2 test as it expects string and not int
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package daytwo
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testInput = []string{
|
||||
func TestPartOne(t *testing.T) {
|
||||
input := []string{
|
||||
"abcdef",
|
||||
"bababc",
|
||||
"abbcde",
|
||||
@@ -11,11 +17,42 @@ var testInput = []string{
|
||||
"abcdee",
|
||||
"ababab",
|
||||
}
|
||||
|
||||
func TestPartOne(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user