MCPcopy Create free account
hub / github.com/elliotchance/orderedmap / TestGetElement

Function TestGetElement

orderedmap_test.go:321–358  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

319}
320
321func TestGetElement(t *testing.T) {
322 t.Run("ReturnsElementForKey", func(t *testing.T) {
323 m := orderedmap.NewOrderedMap()
324 m.Set("foo", "bar")
325
326 var results []interface{}
327 element := m.GetElement("foo")
328 if element != nil {
329 results = append(results, element.Key, element.Value)
330 }
331
332 assert.Equal(t, []interface{}{"foo", "bar"}, results)
333 })
334
335 t.Run("ElementForKeyDoesntExistOnNonEmptyMap", func(t *testing.T) {
336 m := orderedmap.NewOrderedMap()
337 m.Set("foo", "baz")
338 element := m.GetElement("bar")
339 assert.Nil(t, element)
340 })
341
342 t.Run("Performance", func(t *testing.T) {
343 if testing.Short() {
344 t.Skip("performance test skipped in short mode")
345 }
346
347 res1 := testing.Benchmark(benchmarkOrderedMap_GetElement(100))
348 res4 := testing.Benchmark(benchmarkOrderedMap_GetElement(400))
349
350 // O(1) would mean that res4 should take about the same time as res1,
351 // because we are accessing the same amount of elements, just on
352 // different sized maps.
353
354 assert.InDelta(t,
355 res1.NsPerOp(), res4.NsPerOp(),
356 0.5*float64(res1.NsPerOp()))
357 })
358}
359
360func TestOrderedMap_Has(t *testing.T) {
361 t.Run("ReturnsFalseIfKeyDoesNotExist", func(t *testing.T) {

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
GetElementMethod · 0.95
NewOrderedMapFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…