github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/test/ordermap_test.go (about) 1 package test 2 3 import ( 4 "fmt" 5 "github.com/isyscore/isc-gobase/isc" 6 "testing" 7 ) 8 9 func TestOrderMap(t *testing.T) { 10 om := isc.NewOrderMap[string, string]() 11 om.Put("a", "1") 12 om.Put("b", "2") 13 om.Put("c", "3") 14 t.Logf("size : %d", om.Size()) 15 16 for i := 0; i < om.Size(); i++ { 17 t.Logf("key : %s, value : %s", om.GetKey(i), om.GetValue(i)) 18 } 19 20 om.ForEachIndexed(func(idx int, k string, v string) { 21 t.Logf("idx: %d, key : %s, value : %s", idx, k, v) 22 }) 23 24 om.Delete("a") 25 26 om.ForEachIndexed(func(idx int, k string, v string) { 27 t.Logf("idx: %d, key : %s, value : %s", idx, k, v) 28 }) 29 30 str := om.JoinToString(func(k string, v string) string { 31 return fmt.Sprintf("{key:%s,v:%s}", k, v) 32 }) 33 t.Logf(str) 34 35 }