MCPcopy Create free account
hub / github.com/IBM/sarama / TestQueue

Function TestQueue

internal/queue/queue_test.go:10–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestQueue(t *testing.T) {
11 t.Run("zero value reports zero length", func(t *testing.T) {
12 var q Queue[int]
13 assert.Equal(t, 0, q.Length())
14 })
15
16 t.Run("add then peek then remove preserves FIFO order", func(t *testing.T) {
17 var q Queue[int]
18 for i := range 5 {
19 q.Add(i)
20 }
21 assert.Equal(t, 5, q.Length())
22 for i := range 5 {
23 assert.Equal(t, i, q.Peek())
24 assert.Equal(t, i, q.Remove())
25 }
26 assert.Equal(t, 0, q.Length())
27 })
28
29 t.Run("grows beyond initial capacity", func(t *testing.T) {
30 var q Queue[int]
31 const n = 1024
32 for i := range n {
33 q.Add(i)
34 }
35 assert.Equal(t, n, q.Length())
36 for i := range n {
37 assert.Equal(t, i, q.Remove())
38 }
39 assert.Equal(t, 0, q.Length())
40 })
41
42 t.Run("interleaved add and remove wraps around buffer", func(t *testing.T) {
43 var q Queue[int]
44 var want []int
45 for i := range 100 {
46 q.Add(i)
47 q.Add(i + 1000)
48 want = append(want, i, i+1000)
49 }
50 var got []int
51 for q.Length() > 0 {
52 got = append(got, q.Remove())
53 }
54 // re-add and drain to force wrap-around past the original tail
55 for i := range 50 {
56 q.Add(i)
57 }
58 for q.Length() > 0 {
59 q.Remove()
60 }
61 assert.Equal(t, want, got)
62 })
63
64 t.Run("clears slot on remove so the popped element can be GC'd", func(t *testing.T) {
65 type box struct{ v int }
66 var q Queue[*box]
67 q.Add(&box{v: 1})

Callers

nothing calls this directly

Calls 6

RunMethod · 0.80
PeekMethod · 0.80
RemoveMethod · 0.80
LengthMethod · 0.65
AddMethod · 0.45
LessMethod · 0.45

Tested by

no test coverage detected