1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00

sort map move to generics

This commit is contained in:
2022-04-22 17:17:02 +08:00
parent e06c8e3463
commit 5f6130ae58
3 changed files with 133 additions and 2 deletions

View File

@ -0,0 +1,45 @@
package generics
import (
"fmt"
"testing"
)
func TestSort(t *testing.T) {
m := map[string]any{
"Bcd": "bcd",
"Abc": "abc",
}
t.Log(NewSortMap(m).Values())
t.Log(NewSortMap(m).Desc().Values())
t.Log(NewSortMap(m).Asc().Values())
}
func TestMapSortInt(t *testing.T) {
m := map[string]int{
"Bcd": 8,
"Abc": 4,
}
ret := NewSortMap(m).Desc().Values()
t.Log(NewSortMap(m).Desc())
t.Log(NewSortMap(m).Asc())
t.Log(ret)
}
func TestJoin(t *testing.T) {
m := map[string]any{
"Bcd": "bcd",
"Abc": "abc",
"Efg": "efg",
}
t.Log(m)
j := NewSortMap(m).Asc().Join("&", func(k string, v any) string {
return fmt.Sprintf("%s=%v", k, v)
})
t.Log(j)
}