-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc_test.go
49 lines (42 loc) · 1020 Bytes
/
aoc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"os"
"strings"
"testing"
)
func TestAoc(t *testing.T) {
if os.Getenv("TEST_AOC") == "" {
t.Skip("Not running AOC tests")
}
outputsData, err := os.ReadFile("aoc/outputs.txt")
if err != nil {
t.Fatal(err)
}
outputs := strings.Split(strings.TrimSpace(string(outputsData)), "\n")
day := 1
part := 1
for _, expected := range outputs {
expected = expected + "\n"
t.Run(fmt.Sprintf("aoc day %d part %d", day, part), func(t *testing.T) {
inputData, err := os.ReadFile(fmt.Sprintf("../aoc/input/2020/%d.txt", day))
if err != nil {
t.Fatal(err)
}
stdout, err := runScriptFile(fmt.Sprintf("aoc/2020.%02d.%d.toi", day, part), "", string(inputData))
if err != nil {
t.Errorf("expected no error but got: %v", err)
t.Fail()
} else if stdout != expected {
t.Errorf("output not as expected; expected:\n###%s###\nactual:\n###%s###", expected, stdout)
t.Fail()
}
})
if part == 2 {
part = 1
day += 1
} else {
part += 1
}
}
}