diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..065cbf5 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,54 @@ +name: Push workflow + +on: push + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + os: + - linux + - darwin + arch: + - amd64 + - arm64 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.21.0' + - name: Run build + run: go build -o $GOOS-$GOARCH + env: + GOOS: ${{ matrix.os }} + GOARCH: ${{ matrix.arch }} + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.21.0' + - name: Run test + run: go test -v ./... + + bench: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v3 + with: + go-version: '>=1.21.0' + - name: Run test + run: go test -bench Benchmark -benchmem ./... + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest diff --git a/01/01_test.go b/01/01_test.go index fe07c12..9a30b09 100644 --- a/01/01_test.go +++ b/01/01_test.go @@ -1,6 +1,8 @@ package main -import "testing" +import ( + "testing" +) func TestComputeCalibrationSum(t *testing.T) { type test struct { @@ -41,3 +43,19 @@ func TestComputeCalibrationSum(t *testing.T) { } } + +func BenchmarkComputeCalibrationSum(b *testing.B) { + input := []string{ + "two1nine", + "eightwothree", + "abcone2threexyz", + "xtwone3four", + "4nineeightseven2", + "zoneight234", + "7pqrstsixteen", + } + + for i := 0; i < b.N; i++ { + ComputeCalibrationSum(input) + } +}