github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/collection/listx/queue_test.go (about) 1 package listx 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestQueue(t *testing.T) { 10 que := NewQueue[int]() 11 for i := 0; i < 10; i++ { 12 que.Enqueue(i) 13 } 14 assert.Equal(t, 10, que.Len()) 15 16 got := make([]int, 0) 17 for i := 0; i < 10; i++ { 18 x, ok := que.Dequeue() 19 got = append(got, x) 20 assert.True(t, ok) 21 if i > 0 { 22 assert.Equal(t, got[i-1]+1, got[i]) 23 } 24 } 25 26 _, ok := que.Peek() 27 assert.False(t, ok) 28 }