MCPcopy
hub / github.com/cornelk/hashmap / TestRange

Function TestRange

hashmap_test.go:259–295  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func TestRange(t *testing.T) {
260 t.Parallel()
261 m := New[int, string]()
262
263 items := map[int]string{}
264 m.Range(func(key int, value string) bool {
265 items[key] = value
266 return true
267 })
268 assert.Equal(t, 0, len(items))
269
270 itemCount := 16
271 for i := itemCount; i > 0; i-- {
272 m.Set(i, strconv.Itoa(i))
273 }
274
275 items = map[int]string{}
276 m.Range(func(key int, value string) bool {
277 items[key] = value
278 return true
279 })
280
281 assert.Equal(t, itemCount, len(items))
282 for i := 1; i <= itemCount; i++ {
283 value, ok := items[i]
284 assert.True(t, ok)
285 expected := strconv.Itoa(i)
286 assert.Equal(t, expected, value)
287 }
288
289 items = map[int]string{} // test aborting range
290 m.Range(func(key int, value string) bool {
291 items[key] = value
292 return false
293 })
294 assert.Equal(t, 1, len(items))
295}
296
297// nolint: funlen, gocognit
298func TestHashMap_parallel(t *testing.T) {

Callers

nothing calls this directly

Calls 5

EqualFunction · 0.92
TrueFunction · 0.92
NewFunction · 0.85
RangeMethod · 0.80
SetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…