Implement sumAll

This commit is contained in:
2026-03-16 00:29:02 +01:00
parent 3932b66634
commit cf93bb215a
2 changed files with 24 additions and 1 deletions

View File

@@ -8,3 +8,14 @@ func Sum(numbers []int) int {
} }
return sum return sum
} }
func SumAll(numbersToSum ...[]int) []int {
lengthOfNumbers := len(numbersToSum)
sums := make([]int, lengthOfNumbers)
for i, numbers := range numbersToSum {
sums[i] = Sum(numbers)
}
return sums
}

View File

@@ -1,6 +1,9 @@
package main package main
import "testing" import (
"slices"
"testing"
)
func TestSum(t *testing.T) { func TestSum(t *testing.T) {
t.Run("collection of 5 numbers", func(t *testing.T) { t.Run("collection of 5 numbers", func(t *testing.T) {
@@ -25,3 +28,12 @@ func TestSum(t *testing.T) {
} }
}) })
} }
func TestSumAll(t *testing.T) {
got := SumAll([]int{1, 2}, []int{0, 9})
want := []int{3, 9}
if !slices.Equal(got, want) {
t.Errorf("got %d want %v", got, want)
}
}