github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zarray/sort_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package zarray_test 5 6 import ( 7 "testing" 8 9 "github.com/sohaha/zlsgo" 10 "github.com/sohaha/zlsgo/zarray" 11 ) 12 13 func TestNewSortMap(t *testing.T) { 14 tt := zlsgo.NewTest(t) 15 count := 50 16 arr := make([]int, 0, count) 17 18 m := zarray.NewSortMap[int, int]() 19 for i := 0; i < count; i++ { 20 arr = append(arr, i) 21 m.Set(i, i) 22 } 23 24 v, has := m.Get(2) 25 tt.EqualTrue(has) 26 tt.Equal(2, v) 27 28 res := make([]int, 0, count) 29 m.ForEach(func(key int, value int) bool { 30 tt.Equal(key, value) 31 res = append(res, key) 32 return true 33 }) 34 t.Log(res) 35 36 tt.Equal(arr, res) 37 tt.Equal(count, m.Len()) 38 39 m.Delete(1, 10, 20, 20) 40 tt.Equal(count-3, m.Len()) 41 42 t.Log(m.Keys()) 43 }