sum: slice
This commit is contained in:
parent
b427b8fbfb
commit
fc419ec3be
@ -1,6 +1,6 @@
|
||||
package sum
|
||||
|
||||
func Sum(numbers [5]int) int {
|
||||
func Sum(numbers []int) int {
|
||||
sum := 0
|
||||
|
||||
for _, number := range numbers {
|
||||
|
@ -3,7 +3,8 @@ package sum
|
||||
import "testing"
|
||||
|
||||
func TestSum(t *testing.T) {
|
||||
numbers := [5]int{1, 2, 3, 4, 5}
|
||||
t.Run("collection of 5 numbers", func(t *testing.T) {
|
||||
numbers := []int{1, 2, 3, 4, 5}
|
||||
|
||||
got := Sum(numbers)
|
||||
exp := 15
|
||||
@ -11,4 +12,16 @@ func TestSum(t *testing.T) {
|
||||
if got != exp {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user