-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·59 lines (46 loc) · 1.38 KB
/
setup.sh
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
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
day=$1
project_name="go-aoc-template"
# Create day{N}.go
mkdir -p "solutions/day$(printf "%02d" "${day}")" && \
cat << EOF > "solutions/day$(printf "%02d" "${day}")/day$(printf "%02d" "${day}").go"
package day$(printf "%02d" "${day}")
// import (
// h "${project_name}/internal/helpers"
// )
func PartOne(lines []string) string {
return "TODO"
}
func PartTwo(lines []string) string {
return "TODO"
}
EOF
mkdir -p "solutions/day$(printf "%02d" "${day}")/test$(printf "%02d" "${day}")" && \
# Create day{N}_test.go
cat << EOF > "solutions/day$(printf "%02d" "${day}")/test$(printf "%02d" "${day}")/test$(printf "%02d" "${day}").go"
package main
import (
"fmt"
"strings"
day$(printf "%02d" "${day}") "go-aoc-template/solutions/day$(printf "%02d" "${day}")"
)
var lines = strings.Split(\`example input\`, "\n")
var (
partOneAnswer = "example answer"
partTwoAnswer = "example answer"
)
type SolutionFunc func([]string) string
func runTest(part int, solution SolutionFunc, expected string) {
fmt.Printf("Part %d: ", part)
result := solution(lines)
if result != expected {
fmt.Printf("\033[31m%v\033[0m (expected \033[32m%v\033[0m)\n", result, expected)
} else {
fmt.Printf("\033[32m%v\033[0m\n", result)
}
}
func main() {
runTest(1, day$(printf "%02d" "${day}").PartOne, partOneAnswer)
runTest(2, day$(printf "%02d" "${day}").PartTwo, partTwoAnswer)
}
EOF