github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/structs/cappedarr/cappedarr_test.go (about)

     1  package cappedarr
     2  
     3  import (
     4  	"math/rand"
     5  	"time"
     6  
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("cappedarr", func() {
    12  	Describe("MinValue", func() {
    13  		defer GinkgoRecover()
    14  		Context("simple case", func() {
    15  			It("returns correct value", func() {
    16  				values := []uint64{1, 2, 3, 4, 5, 6}
    17  				for i := 0; i < 1000; i++ {
    18  					ca := New(4)
    19  					rand.Seed(time.Now().UnixNano())
    20  					rand.Shuffle(len(values), func(i, j int) {
    21  						values[i], values[j] = values[j], values[i]
    22  					})
    23  
    24  					for _, v := range values {
    25  						ca.Push(v)
    26  					}
    27  
    28  					Expect(ca.MinValue()).To(Equal(uint64(3)))
    29  				}
    30  			})
    31  		})
    32  	})
    33  })