测试
This commit is contained in:
parent
e453dd996e
commit
f648fd6765
@ -309,6 +309,14 @@ func Max[T IntNumber | ~float64 | ~float32](a ...T) T {
|
||||
return max
|
||||
}
|
||||
|
||||
func Sum[T IntNumber | ~float64 | ~float32](a ...T) T {
|
||||
s := T(0)
|
||||
for _, t := range a {
|
||||
s += t
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func SliceChunk[T any](arr []T, size int) [][]T {
|
||||
var r [][]T
|
||||
i := 0
|
||||
|
@ -744,3 +744,27 @@ func TestSliceChunk(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSum(t *testing.T) {
|
||||
type args struct {
|
||||
a []int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "t1",
|
||||
args: args{a: RangeSlice(1, 10, 1)},
|
||||
want: 55,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := Sum(tt.args.a...); got != tt.want {
|
||||
t.Errorf("Sum() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user