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

feat: add ValuesBy function

This commit is contained in:
dudaodong
2023-02-17 11:48:11 +08:00
parent e71cecefea
commit c2ae784f27
2 changed files with 39 additions and 0 deletions

View File

@@ -59,6 +59,33 @@ func TestKeysBy(t *testing.T) {
assert.Equal([]int{2, 3, 4}, keys)
}
func TestValuesBy(t *testing.T) {
assert := internal.NewAssert(t, "TestValuesBy")
m := map[int]string{
1: "a",
2: "b",
3: "c",
}
values := ValuesBy(m, func(v string) string {
switch v {
case "a":
return "a-1"
case "b":
return "b-2"
case "c":
return "c-3"
default:
return ""
}
})
sort.Strings(values)
assert.Equal([]string{"a-1", "b-2", "c-3"}, values)
}
func TestMerge(t *testing.T) {
assert := internal.NewAssert(t, "TestMerge")