Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
catdevman committed Mar 17, 2024
1 parent 7e522aa commit c459c2b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/go_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ on: [push]
jobs:
paths-filter:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.22.0' ]
outputs:
files: ${{ steps.filter.outputs.go_files }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
Expand All @@ -16,14 +15,20 @@ jobs:
filters: |
go:
- 'go/**/**'
go-tests:
runs-on: ubuntu-latest
needs: paths-filter
strategy:
matrix:
go-version: [ '1.22.0' ]
changed-files: ${{needs.path-filter.outputs.files}}
steps:
- uses: actions/checkout@v2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Display Go version
if: steps.filter.outputs.go == 'true'
run: go version
- name: workflow tests
if: steps.filter.outputs.go == 'true'
run: cd go/twosum && go test ./... -v
- name: go tests
run: go test ./... -v
working-directory: ${{ matrix.changed-files }}

9 changes: 9 additions & 0 deletions go/twosum/twosum.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@ package twosum

func TwoSum(nums []int, target int) []int {
out := []int{}
for i := 0; i <= len(nums)-2; i++ {
for j := i + 1; j <= len(nums)-1; j++ {
if nums[i]+nums[j] == target {
out = append(out, i)
out = append(out, j)
break
}
}
}
return out
}
5 changes: 5 additions & 0 deletions go/twosum/twosum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func TestTwoSum(t *testing.T) {
6,
[]int{1, 2},
},
{
[]int{2, 3, 4},
6,
[]int{0, 2},
},
}

for _, test := range tests {
Expand Down

0 comments on commit c459c2b

Please sign in to comment.