Implement sumAll
This commit is contained in:
@@ -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
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user