mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-11-21 14:08:11 +01:00
add new day script for 2023
This commit is contained in:
parent
2a13616ae5
commit
c67b57c949
8 changed files with 97 additions and 19 deletions
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
func Part1(input io.Reader) (int, error) {
|
||||
func D01Part1(input io.Reader) (int, error) {
|
||||
scanner := bufio.NewScanner(input)
|
||||
sum := 0
|
||||
|
||||
|
@ -38,7 +38,7 @@ func Part1(input io.Reader) (int, error) {
|
|||
return sum, nil
|
||||
}
|
||||
|
||||
func Part2(input io.Reader) (int, error) {
|
||||
func D01Part2(input io.Reader) (int, error) {
|
||||
reg, err := regexp.Compile(`[0-9]|one|two|three|four|five|six|seven|eight|nine`)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -1,39 +1,26 @@
|
|||
package _023
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPart1(t *testing.T) {
|
||||
func TestD01Part1(t *testing.T) {
|
||||
tests := []testCase{
|
||||
{"inputs/day01_test1", 142},
|
||||
{"inputs/day01", 53974},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, check(test, Part1))
|
||||
t.Run(test.filename, check(test, D01Part1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPart2(t *testing.T) {
|
||||
func TestD01Part2(t *testing.T) {
|
||||
tests := []testCase{
|
||||
{"inputs/day01_test2", 281},
|
||||
{"inputs/day01_test3", 277},
|
||||
{"inputs/day01", 52840},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, check(test, Part2))
|
||||
}
|
||||
}
|
||||
|
||||
func check(test testCase, fn solveFunc) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
file, err := os.Open(test.filename)
|
||||
require.NoError(t, err)
|
||||
got, err := fn(file)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.want, got)
|
||||
t.Run(test.filename, check(test, D01Part2))
|
||||
}
|
||||
}
|
||||
|
|
0
2023/inputs/dayxx
Normal file
0
2023/inputs/dayxx
Normal file
0
2023/inputs/dayxx_test1
Normal file
0
2023/inputs/dayxx_test1
Normal file
0
2023/inputs/dayxx_test2
Normal file
0
2023/inputs/dayxx_test2
Normal file
25
2023/new_day
Executable file
25
2023/new_day
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
set -euxo pipefail
|
||||
|
||||
if [[ $# -ne 2 ]]; then
|
||||
>&2 echo "Usage: $0 <number> <name>"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
filename=day$1_$2
|
||||
cp template.go $filename.go
|
||||
cp template_test.go $filename_test.go
|
||||
if [ "$(uname -s)" == "Linux" ]; then
|
||||
sed -e "s/Dxx/day$1/g" -i ./$filename.go
|
||||
sed -e "s/Dxx/day$1/g" -i ./$filename_test.go
|
||||
sed -e "s/dayxx/day$1/g" -i ./$filename_test.go
|
||||
else
|
||||
sed -e "s/Dxx/day$1/g" -i "" ./$filename.go
|
||||
sed -e "s/Dxx/day$1/g" -i "" ./$filename_test.go
|
||||
sed -e "s/dayxx/day$1/g" -i "" ./$filename_test.go
|
||||
fi
|
||||
mkdir -p inputs
|
||||
touch inputs/day$1
|
||||
touch inputs/day$1_test1
|
||||
touch inputs/day$1_test2
|
||||
git add "inputs/day$1*" $filename
|
28
2023/template.go
Normal file
28
2023/template.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package _023
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
func DxxPart1(input io.Reader) (int, error) {
|
||||
scanner := bufio.NewScanner(input)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
_ = line
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func DxxPart2(input io.Reader) (int, error) {
|
||||
scanner := bufio.NewScanner(input)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
_ = line
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
38
2023/template_test.go
Normal file
38
2023/template_test.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package _023
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDxxPart1(t *testing.T) {
|
||||
tests := []testCase{
|
||||
{"inputs/dayxx_test1", 0},
|
||||
{"inputs/dayxx", 0},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, check(test, DxxPart1))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDxxPart2(t *testing.T) {
|
||||
tests := []testCase{
|
||||
{"inputs/dayxx_test2", 0},
|
||||
{"inputs/dayxx", 0},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.filename, check(test, DxxPart2))
|
||||
}
|
||||
}
|
||||
|
||||
func check(test testCase, fn solveFunc) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
file, err := os.Open(test.filename)
|
||||
require.NoError(t, err)
|
||||
got, err := fn(file)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, test.want, got)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue