MCPcopy Create free account
hub / github.com/beeker1121/goque / TestPriorityQueueDequeueByPriority

Function TestPriorityQueueDequeueByPriority

priority_queue_test.go:175–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func TestPriorityQueueDequeueByPriority(t *testing.T) {
176 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())
177 pq, err := OpenPriorityQueue(file, ASC)
178 if err != nil {
179 t.Error(err)
180 }
181 defer pq.Drop()
182
183 for p := 0; p <= 4; p++ {
184 for i := 1; i <= 10; i++ {
185 if _, err = pq.EnqueueString(uint8(p), fmt.Sprintf("value for item %d", i)); err != nil {
186 t.Error(err)
187 }
188 }
189 }
190
191 if pq.Length() != 50 {
192 t.Errorf("Expected queue length of 50, got %d", pq.Length())
193 }
194
195 deqItem, err := pq.DequeueByPriority(3)
196 if err != nil {
197 t.Error(err)
198 }
199
200 if pq.Length() != 49 {
201 t.Errorf("Expected queue length of 49, got %d", pq.Length())
202 }
203
204 compStr := "value for item 1"
205
206 if deqItem.Priority != 3 {
207 t.Errorf("Expected priority level to be 1, got %d", deqItem.Priority)
208 }
209
210 if deqItem.ToString() != compStr {
211 t.Errorf("Expected string to be '%s', got '%s'", compStr, deqItem.ToString())
212 }
213}
214
215func TestPriorityQueueEncodeDecodePointerJSON(t *testing.T) {
216 file := fmt.Sprintf("test_db_%d", time.Now().UnixNano())

Callers

nothing calls this directly

Calls 6

OpenPriorityQueueFunction · 0.85
DequeueByPriorityMethod · 0.80
DropMethod · 0.45
EnqueueStringMethod · 0.45
LengthMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected