collection/reduce_test.go
Alexander Kiryukhin 9cd6b0fca8
initial
2022-04-07 21:36:40 +03:00

38 lines
699 B
Go

package collection
import (
"reflect"
"testing"
)
func TestReduce(t *testing.T) {
type args struct {
collection []int
cb func(previous int, current int, idx int) int
accumulator int
}
tests := []struct {
name string
args args
want int
}{
{
name: "Sum",
args: args{
collection: []int{1, 2, 3, 4, 5, 6},
cb: func(previous, current, idx int) int {
return previous + current
},
},
want: 21,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Reduce(tt.args.collection, tt.args.cb, tt.args.accumulator); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Reduce() = %v, want %v", got, tt.want)
}
})
}
}