Skip to content

Commit e122e61

Browse files
committed
SumInt64
1 parent 990e813 commit e122e61

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

math/sum.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package math
2+
3+
// SumInt64 returns the sum of all the provided values.
4+
func SumInt64(values ...int64) int64 {
5+
var result int64
6+
7+
for _, value := range values {
8+
result += value
9+
}
10+
11+
return result
12+
}

math/sum_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package math_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/yitsushi/go-aoc/math"
7+
)
8+
9+
func TestSumInt64(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
list []int64
13+
want int64
14+
}{
15+
{name: "empty", list: []int64{}, want: 0},
16+
{name: "values", list: []int64{1, 2, 3}, want: 6},
17+
{name: "values", list: []int64{5, 4, 92, 13, 42, 52}, want: 208},
18+
}
19+
for _, tt := range tests {
20+
t.Run(tt.name, func(t *testing.T) {
21+
if got := math.SumInt64(tt.list...); got != tt.want {
22+
t.Errorf("SumInt64() = %v, want %v", got, tt.want)
23+
}
24+
})
25+
}
26+
}

0 commit comments

Comments
 (0)