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

Function TestTPQReset

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

Source from the content-addressed store, hash-verified

122}
123
124func TestTPQReset(t *testing.T) {
125 t.Parallel()
126 tpq := NewTimePriorityQueue[val]()
127
128 now := time.Now() // make sure the time is in the past
129 for i := 0; i < 50; i++ {
130 tpq.Enqueue(now.Add(time.Second), i, val{i})
131 }
132 for i := 50; i < 100; i++ {
133 tpq.Enqueue(now.Add(-time.Second), i, val{i})
134 }
135
136 if tpq.Len() != 100 {
137 t.Errorf("expected length to be 100, got %d", tpq.Len())
138 }
139
140 dv := tpq.Dequeue(context.Background())
141 if dv.v != 99 {
142 t.Errorf("expected 99, got %d", dv.v)
143 }
144
145 vals := tpq.Reset()
146
147 if len(vals) != 99 {
148 t.Errorf("expected length to be 100, got %d", len(vals))
149 }
150
151 slices.SortFunc(vals, func(i, j val) int {
152 if i.v > j.v {
153 return 1
154 }
155 return -1
156 })
157
158 for i := 0; i < 99; i++ {
159 if vals[i].v != i {
160 t.Errorf("expected %d, got %d", i, vals[i].v)
161 }
162 }
163
164 if tpq.Len() != 0 {
165 t.Errorf("expected length to be 0, got %d", tpq.Len())
166 }
167}
168
169func TestTPQGetAll(t *testing.T) {
170 t.Parallel()

Callers

nothing calls this directly

Calls 5

AddMethod · 0.65
EnqueueMethod · 0.45
LenMethod · 0.45
DequeueMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected