mirror of
https://github.com/cowardmrx/maps.git
synced 2025-02-22 20:00:38 +08:00
📝 更新测试文档
This commit is contained in:
parent
c8923b6bf1
commit
db26c97e7b
14
README.md
14
README.md
@ -28,8 +28,20 @@ maps.Values()
|
||||
// GetMapsOriginMap get this maps origin data return a map[string]interface
|
||||
maps.OriginMap()
|
||||
|
||||
// SortKey sort this maps by keys
|
||||
// SortKey sort this maps by keys asc
|
||||
maps.SortKey()
|
||||
|
||||
// other sort
|
||||
// sort by desc
|
||||
sort.Slice(maps.Keys,func (i,j int) bool {
|
||||
return maps.Keys()[i] > maps.Keys()[j]
|
||||
})
|
||||
|
||||
// sort by asc
|
||||
sort.Slice(maps.Keys,func (i,j int) bool {
|
||||
return maps.Keys()[i] < maps.Keys()[j]
|
||||
})
|
||||
|
||||
|
||||
// other example ./maps_test.go
|
||||
```
|
7
maps.go
7
maps.go
@ -5,13 +5,6 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// SortAsc sort by asc
|
||||
SortAsc = "asc"
|
||||
// SortDesc sort by desc
|
||||
SortDesc = "desc"
|
||||
)
|
||||
|
||||
type maps struct {
|
||||
rw sync.RWMutex
|
||||
Key []string
|
||||
|
14
maps_test.go
14
maps_test.go
@ -62,3 +62,17 @@ func TestSortKey(t *testing.T) {
|
||||
|
||||
fmt.Println(a)
|
||||
}
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
maps := NewMaps()
|
||||
|
||||
a := maps.Set("key3", "value1").Set("key4", "value 2").Set("key1", "value 3")
|
||||
|
||||
sort.Slice(a.Keys(), func(i, j int) bool {
|
||||
return a.Keys()[i] > a.Keys()[j]
|
||||
})
|
||||
|
||||
fmt.Println(a.Keys())
|
||||
fmt.Println(a.Values())
|
||||
fmt.Println(a.OriginMap())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user