sum: sumAll
This commit is contained in:
parent
fc419ec3be
commit
e905c600f3
@ -8,3 +8,7 @@ func Sum(numbers []int) int {
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
func SumAll(x []int, y []int) []int {
|
||||
return []int{Sum(x), Sum(y)}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package sum
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSum(t *testing.T) {
|
||||
t.Run("collection of 5 numbers", func(t *testing.T) {
|
||||
@ -13,15 +16,12 @@ func TestSum(t *testing.T) {
|
||||
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("collection of any size", func(t *testing.T) {
|
||||
numbers := []int{1, 2, 3}
|
||||
|
||||
got := Sum(numbers)
|
||||
exp := 6
|
||||
|
||||
if got != exp {
|
||||
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestSumAll(t *testing.T) {
|
||||
got := SumAll([]int{1, 2}, []int{0, 9})
|
||||
exp := []int{3, 9}
|
||||
if slices.Compare(got, exp) != 0 {
|
||||
t.Errorf("got %d, expected %d", got, exp)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user