fix new day script

This commit is contained in:
Gabriel Augendre 2023-12-02 13:57:21 +01:00
parent c67b57c949
commit c554a5e463
3 changed files with 27 additions and 22 deletions

18
2023/lib_test.go Normal file
View file

@ -0,0 +1,18 @@
package _023
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
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)
}
}

View file

@ -7,19 +7,19 @@ if [[ $# -ne 2 ]]; then
fi
filename=day$1_$2
cp template.go $filename.go
cp template_test.go $filename_test.go
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
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
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
git add "inputs/day$1*" ${filename}*

View file

@ -1,9 +1,6 @@
package _023
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
"testing"
)
@ -26,13 +23,3 @@ func TestDxxPart2(t *testing.T) {
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)
}
}