(t *testing.T)
| 319 | } |
| 320 | |
| 321 | func 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 | |
| 360 | func TestOrderedMap_Has(t *testing.T) { |
| 361 | t.Run("ReturnsFalseIfKeyDoesNotExist", func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…