forked from all_user/stat_center
48 lines
885 B
Go
48 lines
885 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestStrSliceConstruct(t *testing.T) {
|
|
type args struct {
|
|
length int
|
|
filter StrSliceConstructFilter
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []string
|
|
}{
|
|
{
|
|
name: "1",
|
|
args: args{
|
|
length: 5,
|
|
filter: func(index int) (string, bool) {
|
|
return fmt.Sprintf("%d", index), true
|
|
},
|
|
},
|
|
want: []string{"0", "1", "2", "3", "4"},
|
|
},
|
|
{
|
|
name: "2",
|
|
args: args{
|
|
length: 5,
|
|
filter: func(index int) (string, bool) {
|
|
return fmt.Sprintf("%d", index*index), true
|
|
},
|
|
},
|
|
want: []string{"0", "1", "4", "9", "16"},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := StrSliceConstruct(tt.args.length, tt.args.filter); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("StrSliceConstruct() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|