MCPcopy
hub / github.com/garethgeorge/backrest / TestTPQRemove

Function TestTPQRemove

internal/queue/timepriorityqueue_test.go:97–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestTPQRemove(t *testing.T) {
98 t.Parallel()
99 tpq := NewTimePriorityQueue[val]()
100
101 now := time.Now().Add(-time.Second) // make sure the time is in the past
102 for i := 0; i < 100; i++ {
103 tpq.Enqueue(now, -i, val{i})
104 }
105
106 if tpq.Len() != 100 {
107 t.Errorf("expected length to be 100, got %d", tpq.Len())
108 }
109
110 // remove all even numbers, dequeue the odd numbers
111 for i := 0; i < 100; i += 2 {
112 tpq.Remove(val{i})
113 v := tpq.Dequeue(context.Background())
114 if v.v != i+1 {
115 t.Errorf("expected %d, got %d", i+1, v)
116 }
117 }
118
119 if tpq.Len() != 0 {
120 t.Errorf("expected length to be 0, got %d", tpq.Len())
121 }
122}
123
124func TestTPQReset(t *testing.T) {
125 t.Parallel()

Callers

nothing calls this directly

Calls 5

AddMethod · 0.65
EnqueueMethod · 0.45
LenMethod · 0.45
RemoveMethod · 0.45
DequeueMethod · 0.45

Tested by

no test coverage detected