MCPcopy
hub / github.com/kubernetes/client-go / TestHeap_Update

Function TestHeap_Update

tools/cache/heap_test.go:229–250  ·  view source on GitHub ↗

TestHeap_Update tests Heap.Update and ensures that heap invariant is preserved after adding items.

(t *testing.T)

Source from the content-addressed store, hash-verified

227// TestHeap_Update tests Heap.Update and ensures that heap invariant is
228// preserved after adding items.
229func TestHeap_Update(t *testing.T) {
230 h := NewHeap(testHeapObjectKeyFunc, compareInts)
231 h.Add(mkHeapObj("foo", 10))
232 h.Add(mkHeapObj("bar", 1))
233 h.Add(mkHeapObj("bal", 31))
234 h.Add(mkHeapObj("baz", 11))
235
236 // Update an item to a value that should push it to the head.
237 h.Update(mkHeapObj("baz", 0))
238 if h.data.queue[0] != "baz" || h.data.items["baz"].index != 0 {
239 t.Fatalf("expected baz to be at the head")
240 }
241 item, err := h.Pop()
242 if e, a := 0, item.(testHeapObject).val; err != nil || a != e {
243 t.Fatalf("expected %d, got %d", e, a)
244 }
245 // Update bar to push it farther back in the queue.
246 h.Update(mkHeapObj("bar", 100))
247 if h.data.queue[0] != "foo" || h.data.items["foo"].index != 0 {
248 t.Fatalf("expected foo to be at the head")
249 }
250}
251
252// TestHeap_Get tests Heap.Get.
253func TestHeap_Get(t *testing.T) {

Callers

nothing calls this directly

Calls 5

AddMethod · 0.95
UpdateMethod · 0.95
PopMethod · 0.95
NewHeapFunction · 0.85
mkHeapObjFunction · 0.85

Tested by

no test coverage detected