github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/queues/lscq/lscq_test.go (about)

     1  package lscq
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestLSCQ(t *testing.T) {
    12  	lq := New[int]()
    13  
    14  	rand.Seed(time.Now().Unix())
    15  	q := make([]int, 0, 10)
    16  	for i := 0; i < 10; i++ {
    17  		v := rand.Int()
    18  		q = append(q, v)
    19  		lq.Enqueue(v)
    20  	}
    21  	for i := 0; i < 10; i++ {
    22  		v, ok := lq.Dequeue()
    23  		assert.Equal(t, true, ok)
    24  		assert.Equal(t, q[i], v)
    25  	}
    26  	_, ok := lq.Dequeue()
    27  	assert.Equal(t, false, ok)
    28  }