github.com/grailbio/base@v0.0.11/file/internal/readmatcher/readmatchertest/stress_test.go (about)

     1  package readmatchertest
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestRandInterval(t *testing.T) {
    12  	const (
    13  		size   = 10000
    14  		trials = 10000
    15  	)
    16  	var (
    17  		rnd                  = rand.New(rand.NewSource(1))
    18  		touchZero, touchSize int
    19  	)
    20  	for i := 0; i < trials; i++ {
    21  		start, limit := randInterval(rnd, size)
    22  		require.GreaterOrEqual(t, start, 0)
    23  		require.LessOrEqual(t, limit, size)
    24  		if start == 0 {
    25  			touchZero++
    26  		}
    27  		if limit == size {
    28  			touchSize++
    29  		}
    30  	}
    31  	// 10% is a very loose constraint. We could be more precise, but we don't care too much.
    32  	assert.Greater(t, touchZero, trials/10)
    33  	assert.Greater(t, touchSize, trials/10)
    34  }