github.com/Mericusta/go-stp@v0.6.8/map_test.go (about) 1 package stp 2 3 import ( 4 "math" 5 "testing" 6 ) 7 8 func Test_Key(t *testing.T) { 9 m := make(map[int]int) 10 km := make(map[int]interface{}, math.MaxInt16) 11 for i := 0; i != math.MaxInt16; i++ { 12 m[i] = i 13 km[i] = struct{}{} 14 } 15 for _, k := range Key(m) { 16 if _, hasK := km[k]; !hasK { 17 panic("Test_Key failed") 18 } 19 } 20 } 21 22 func Test_Map(t *testing.T) { 23 m := NewMap[int, int]() 24 for i := 0; i != math.MaxInt16; i++ { 25 m.Set(i, i) 26 if m.l != m.c || m.l != i+1 { 27 panic("Test_Map failed") 28 } 29 } 30 if m.Len() != math.MaxInt16 { 31 panic("Test_Map failed") 32 } 33 for i := 0; i != math.MaxInt16; i++ { 34 if v, has := m.Get(i); !has || v != i { 35 panic("Test_Map failed") 36 } 37 } 38 for i := 0; i != math.MaxInt16; i++ { 39 m.Del(i) 40 if _, has := m.Get(i); has { 41 panic("Test_Map failed") 42 } 43 if m.Len() != math.MaxInt16-i-1 { 44 panic("Test_Map failed") 45 } 46 } 47 for i := 0; i != math.MaxInt16; i++ { 48 m.Set(i, i) 49 if m.l != m.c || m.l != i+1 { 50 panic("Test_Map failed") 51 } 52 } 53 m.Range(func(i1, i2 int) bool { 54 if i2%2 == 0 { 55 m.Del(i2) 56 } 57 return true 58 }) 59 for i := 0; i != math.MaxInt16; i++ { 60 if _, has := m.Get(i); (i%2 == 0 && has) || (i%2 != 0 && !has) { 61 panic("Test_Map failed") 62 } 63 } 64 }