This commit is contained in:
vinchent 2024-09-10 21:15:12 +02:00
parent fb1e5e2835
commit 5775ea5e50
2 changed files with 24 additions and 0 deletions

10
sum/sum.go Normal file
View File

@ -0,0 +1,10 @@
package sum
func Sum(numbers [5]int) int {
sum := 0
for i := 0; i < 5; i++ {
sum += numbers[i]
}
return sum
}

14
sum/sum_test.go Normal file
View File

@ -0,0 +1,14 @@
package sum
import "testing"
func TestSum(t *testing.T) {
numbers := [5]int{1, 2, 3, 4, 5}
got := Sum(numbers)
exp := 15
if got != exp {
t.Errorf("got %d, expected %d, given %v", got, exp, numbers)
}
}