mirror of
https://github.com/cowardmrx/maps.git
synced 2025-02-23 04:10:31 +08:00
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package maps
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func TestSetMaps(t *testing.T) {
|
|
maps := NewMaps()
|
|
a := maps.Set("key1", "123123")
|
|
fmt.Println(a)
|
|
}
|
|
|
|
func TestExistMaps(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key2", "this is value 2")
|
|
|
|
fmt.Println(a.Exist("key3"))
|
|
}
|
|
|
|
func TestGetMaps(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key1", "value1").Set("key2", "value 2").Set("key3", "value 3")
|
|
|
|
fmt.Println(a.Get("key4"))
|
|
}
|
|
|
|
func TestDeleteMaps(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key1", "value1").Set("key2", "value 2").Set("key3", "value 3")
|
|
|
|
fmt.Println(a.Delete("key1", "key2", "key3", "key4"))
|
|
}
|
|
|
|
func TestKeysValues(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key1", "value1").Set("key2", "value 2").Set("key3", "value 3")
|
|
|
|
fmt.Println(a.Keys())
|
|
fmt.Println(a.Values())
|
|
}
|
|
|
|
func TestOriginMap(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key1", "value1").Set("key2", "value 2").Set("key3", "value 3")
|
|
|
|
fmt.Println(a.OriginMap())
|
|
}
|
|
|
|
func TestSortKey(t *testing.T) {
|
|
maps := NewMaps()
|
|
|
|
a := maps.Set("key3", "value1").Set("key4", "value 2").Set("key1", "value 3")
|
|
|
|
a.SortKey(sort.Strings)
|
|
|
|
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())
|
|
}
|