sum: v1
This commit is contained in:
parent
fb1e5e2835
commit
5775ea5e50
10
sum/sum.go
Normal file
10
sum/sum.go
Normal 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
14
sum/sum_test.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user