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:
45
collections/generics/sort_map_test.go
Normal file
45
collections/generics/sort_map_test.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user