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

Function TestDelete

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

Source from the content-addressed store, hash-verified

231}
232
233func TestDelete(t *testing.T) {
234 t.Run("KeyDoesntExistReturnsFalse", func(t *testing.T) {
235 m := orderedmap.NewOrderedMap()
236 assert.False(t, m.Delete("foo"))
237 })
238
239 t.Run("KeyDoesExist", func(t *testing.T) {
240 m := orderedmap.NewOrderedMap()
241 m.Set("foo", nil)
242 assert.True(t, m.Delete("foo"))
243 })
244
245 t.Run("KeyNoLongerExists", func(t *testing.T) {
246 m := orderedmap.NewOrderedMap()
247 m.Set("foo", nil)
248 m.Delete("foo")
249 _, exists := m.Get("foo")
250 assert.False(t, exists)
251 })
252
253 t.Run("KeyDeleteIsIsolated", func(t *testing.T) {
254 m := orderedmap.NewOrderedMap()
255 m.Set("foo", nil)
256 m.Set("bar", nil)
257 m.Delete("foo")
258 _, exists := m.Get("bar")
259 assert.True(t, exists)
260 })
261
262 t.Run("Performance", func(t *testing.T) {
263 if testing.Short() {
264 t.Skip("performance test skipped in short mode")
265 }
266
267 res1 := testing.Benchmark(benchmarkOrderedMap_Delete(100))
268 res4 := testing.Benchmark(benchmarkOrderedMap_Delete(400))
269
270 // O(1) would mean that res4 should take about 4 times longer than res1
271 // because we are doing 4 times the amount of Set/Delete operations.
272 // Allow for a wide margin, but not too wide that it would permit the
273 // inflection to O(n^2).
274
275 assert.InDelta(t,
276 4*res1.NsPerOp(), res4.NsPerOp(),
277 float64(res4.NsPerOp()))
278 })
279}
280
281func TestOrderedMap_Front(t *testing.T) {
282 t.Run("NilOnEmptyMap", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

DeleteMethod · 0.95
SetMethod · 0.95
GetMethod · 0.95
NewOrderedMapFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…