| 95 | } |
| 96 | |
| 97 | func 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 | |
| 124 | func TestTPQReset(t *testing.T) { |
| 125 | t.Parallel() |