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

Function TestTPQGetAll

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

Source from the content-addressed store, hash-verified

167}
168
169func TestTPQGetAll(t *testing.T) {
170 t.Parallel()
171 tpq := NewTimePriorityQueue[val]()
172 now := time.Now()
173
174 for i := 0; i < 100; i++ {
175 tpq.Enqueue(now.Add(time.Second), i, val{i})
176 }
177
178 if tpq.Len() != 100 {
179 t.Errorf("expected length to be 100, got %d", tpq.Len())
180 }
181
182 vals := tpq.GetAll()
183
184 if len(vals) != 100 {
185 t.Errorf("expected length to be 100, got %d", len(vals))
186 }
187
188 slices.SortFunc(vals, func(i, j val) int {
189 if i.v > j.v {
190 return 1
191 }
192 return -1
193 })
194
195 for i := 0; i < 100; i++ {
196 if vals[i].v != i {
197 t.Errorf("expected %d, got %d", i, vals[i].v)
198 }
199 }
200}

Callers

nothing calls this directly

Calls 4

AddMethod · 0.65
GetAllMethod · 0.65
EnqueueMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected