Skip to content

Commit 2fed1e4

Browse files
committed
Add some automated tests
1 parent 2349b6e commit 2fed1e4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

.github/workflows/go-test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Testing
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
name: Go Test
9+
runs-on: ubuntu-latest
10+
timeout-minutes: 4
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: '^1.22'
19+
20+
- name: Go Test
21+
run: |
22+
go test ./...

util/parse_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package util
2+
3+
import "testing"
4+
5+
func TestIntsToStrings(t *testing.T) {
6+
input := []int{2, 4, 6, 8, 10, 12}
7+
8+
output := IntsToStrings(input)
9+
10+
for i := range output {
11+
if (i+1)*2 != MustAtoi(output[i]) {
12+
t.Errorf("Expected value %v at index %v, but got %v", (i+1)*2, i, MustAtoi(output[i]))
13+
}
14+
}
15+
}
16+
17+
func TestStringToInts(t *testing.T) {
18+
output := StringToInts("2, 4, 6, 8, 10, 12", ", ")
19+
20+
for i := range output {
21+
if (i+1)*2 != output[i] {
22+
t.Errorf("Expected value %v at index %v, but got %v", (i+1)*2, i, output[i])
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)