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

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

No files matched your search

+2 -3
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)