Atlas › Test

TestInsertAndPop

Exact test identity: go.temporal.io/server/common/collection/TestPriorityQueueSuite/TestInsertAndPop

Package
go.temporal.io/server/common/collection
Suite / test hierarchy
TestPriorityQueueSuite/TestInsertAndPop
Test
TestInsertAndPop
Introduced at
TestInsertAndPop, TestRandomNumber Frontier kind: Test frontier
Covered ranges
9
Covered lines
31
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/collection/priority_queue.go 31 covered LOC · 9 ranges

Open complete file

15 func NewPriorityQueue[T any](
16 compareLess func(this T, other T) bool,
17 > ) Queue[T] { priority_queue.go
18 > return &priorityQueueImpl[T]{
19 > compareLess: compareLess,
20 > }
21 > }
22
23 // NewPriorityQueueWithItems creats a new priority queue
47
48 // Add push an item to priority queue
49 > func (pq *priorityQueueImpl[T]) Add(item T) { priority_queue.go
50 > heap.Push(pq, item)
51 > }
52
53 // Remove pop an item from priority queue
54 > func (pq *priorityQueueImpl[T]) Remove() T { priority_queue.go
55 > return heap.Pop(pq).(T)
56 > }
57
58 // IsEmpty indicate if the priority queue is empty
59 > func (pq *priorityQueueImpl[T]) IsEmpty() bool { priority_queue.go
60 > return pq.Len() == 0
61 > }
62
63 // below are the functions used by heap.Interface and go internal heap implementation
64
65 // Len implements sort.Interface
66 > func (pq *priorityQueueImpl[T]) Len() int { priority_queue.go
67 > return len(pq.items)
68 > }
69
70 // Less implements sort.Interface
71 > func (pq *priorityQueueImpl[T]) Less(i, j int) bool { priority_queue.go
72 > return pq.compareLess(pq.items[i], pq.items[j])
73 > }
74
75 // Swap implements sort.Interface
76 > func (pq *priorityQueueImpl[T]) Swap(i, j int) { priority_queue.go
77 > pq.items[i], pq.items[j] = pq.items[j], pq.items[i]
78 > }
79
80 // Push push an item to priority queue, used by go internal heap implementation
81 > func (pq *priorityQueueImpl[T]) Push(item any) { priority_queue.go
82 > pq.items = append(pq.items, item.(T))
83 > }
84
85 // Pop pop an item from priority queue, used by go internal heap implementation
86 > func (pq *priorityQueueImpl[T]) Pop() any { priority_queue.go
87 > pqItem := pq.items[pq.Len()-1]
88 > pq.items = pq.items[0 : pq.Len()-1]
89 > return pqItem
90 > }