Compare commits
2 Commits
959c05b769
...
bcef8844ec
| Author | SHA1 | Date | |
|---|---|---|---|
| bcef8844ec | |||
| 20ab5fe4e5 |
2
Makefile
2
Makefile
@@ -8,7 +8,7 @@ build:
|
||||
@$(GO) build -o $(BIN) ./cmd/aoc
|
||||
|
||||
test:
|
||||
@$(GO) test ./...
|
||||
@$(GO) test ./internal/...
|
||||
|
||||
clean:
|
||||
@rm -f $(BIN)
|
||||
|
||||
@@ -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