1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 00:02:28 +08:00

test: add some unit test function for convertor, random, slice, and formatter

This commit is contained in:
dudaodong
2021-11-29 17:27:02 +08:00
parent fee6cb17f3
commit f2ed3c6270
8 changed files with 92 additions and 56 deletions

View File

@@ -137,17 +137,16 @@ func Map(slice, function interface{}) interface{} {
// The function signature should be func(index int, value1, value2 interface{}) interface{} .
func Reduce(slice, function, zero interface{}) interface{} {
sv := sliceValue(slice)
elementType := sv.Type().Elem()
len := sv.Len()
if len == 0 {
return zero
} else if len == 1 {
return sv.Index(0)
return sv.Index(0).Interface()
}
elementType := sv.Type().Elem()
fn := functionValue(function)
if checkSliceCallbackFuncSignature(fn, elementType, elementType, elementType) {
t := elementType.String()
panic("Reduce function must be of type func(int, " + t + ", " + t + ")" + t)