Add array sum module

This commit is contained in:
2026-03-16 00:22:46 +01:00
parent c9cc104fe5
commit 3932b66634
2 changed files with 37 additions and 0 deletions

27
arrays/sum_test.go Normal file
View File

@@ -0,0 +1,27 @@
package main
import "testing"
func TestSum(t *testing.T) {
t.Run("collection of 5 numbers", func(t *testing.T) {
numbers := []int{1, 2, 3, 4, 5}
got := Sum(numbers)
want := 15
if got != want {
t.Errorf("got %d want %d given, %v", got, want, numbers)
}
})
t.Run("collection of any size", func(t *testing.T) {
numbers := []int{1, 2, 3}
got := Sum(numbers)
want := 6
if got != want {
t.Errorf("got %d want %d given, %v", got, want, numbers)
}
})
}