Skip to content

Commit

Permalink
feat: pass slice instead of full string
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkinlog committed Mar 1, 2024
1 parent ace7bc3 commit f6dc41e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/templates/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func main() {
fmt.Printf("Running part %d...\n", part)

if part == 1 {
ans := part1(input)
ans := part1(strings.Split(input, "\n"))
fmt.Println(ans)
} else {
ans := part2(input)
ans := part2(strings.Split(input, "\n"))
fmt.Println(ans)
}
}
14 changes: 2 additions & 12 deletions src/templates/go/solution.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
package main

import "strings"

func part1(input string) any {
for _, line := range strings.Split(input, "\n") {
_ = line
}

func part1(input []string) any {
return nil
}

func part2(input string) any {
for _, line := range strings.Split(input, "\n") {
_ = line
}

func part2(input []string) any {
return nil
}
9 changes: 6 additions & 3 deletions src/templates/go/solution_benchmark.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package main

import "testing"
import (
"strings"
"testing"
)

func BenchmarkPart1(b *testing.B) {
for i := 0; i < b.N; i++ {
part1(input)
part1(strings.Split(input, "\n"))
}
}

func BenchmarkPart2(b *testing.B) {
for i := 0; i < b.N; i++ {
part2(input)
part2(strings.Split(input, "\n"))
}
}
9 changes: 6 additions & 3 deletions src/templates/go/solution_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "testing"
import (
"strings"
"testing"
)

func TestPart1(t *testing.T) {
tests := map[string]struct {
Expand All @@ -12,7 +15,7 @@ func TestPart1(t *testing.T) {

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
if got := part1(strings.Split(tt.input, "\n")); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
})
Expand All @@ -29,7 +32,7 @@ func TestPart2(t *testing.T) {

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
if got := part2(strings.Split(tt.input, "\n")); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit f6dc41e

Please sign in to comment.