Atlas › Test
TestRandomNumber
Exact test identity: go.temporal.io/server/common/collection/TestPriorityQueueSuite/TestRandomNumber
- Package
go.temporal.io/server/common/collection
- Suite / test hierarchy
TestPriorityQueueSuite/TestRandomNumber
- Test
TestRandomNumber
- 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,
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
50
>
heap.Push(pq, item)
51
>
}
52
53
// Remove pop an item from priority queue
55
>
return heap.Pop(pq).(T)
56
>
}
57
58
// IsEmpty indicate if the priority queue is empty
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
67
>
return len(pq.items)
68
>
}
69
70
// Less implements sort.Interface
72
>
return pq.compareLess(pq.items[i], pq.items[j])
73
>
}
74
75
// Swap implements sort.Interface
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
82
>
pq.items = append(pq.items, item.(T))
83
>
}
84
85
// Pop pop an item from priority queue, used by go internal heap implementation
87
>
pqItem := pq.items[pq.Len()-1]
88
>
pq.items = pq.items[0 : pq.Len()-1]
89
>
return pqItem
90
>
}