-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-day.ps1
89 lines (72 loc) · 1.56 KB
/
add-day.ps1
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
param([Int32]$day)
$day_string = 'day{0:D2}' -f $day
# Create input and sample files
pushd
cd .\resources
mkdir $day_string
cd $day_string
touch "input.txt"
touch "sample.txt"
popd
# Create the solution and unit test .go files
pushd
cd .\days
mkdir $day_string
cd $day_string
touch "$day_string.go"
$solutionTemplate = @"
package $day_string
import (
"advent-of-code-2024/util"
"fmt"
)
func SolvePart1(useRealInput bool) (int, error) {
_, err := parseInput(useRealInput)
if err != nil {
return 0, err
}
return 0, nil
}
func SolvePart2(useRealInput bool) (int, error) {
_, err := parseInput(useRealInput)
if err != nil {
return 0, err
}
return 0, nil
}
func parseInput(useRealInput bool) ([]string, error) {
data, err := util.ReadInputMulti($day, useRealInput)
if err != nil {
return nil, err
}
if len(data) != 1 {
return nil, fmt.Errorf("expected single line of input")
}
return data[0], nil
}
"@
$solutionTemplate | Out-File -FilePath "$day_string.go"
touch "${day_string}_test.go"
$testTemplate = @"
package $day_string
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShouldCorrectlyDeterminePart1OnExampleInput(t *testing.T) {
solution, err := SolvePart1(false)
if err != nil {
t.Fatalf("Error during Solve: %v", err)
}
assert.Equal(t, 111, solution)
}
func TestShouldCorrectlyDeterminePart2OnExampleInput(t *testing.T) {
solution, err := SolvePart2(false)
if err != nil `{
t.Fatalf("Error during Solve: %v", err)
}
assert.Equal(t, 111, solution)
}
"@
$testTemplate | Out-File -FilePath "${day_string}_test.go"
popd