github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/catgo/cat-go/cat/manager_test.go (about)

     1  package cat
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestHitSample(t *testing.T) {
     8  	var (
     9  		total  = 100000
    10  		sample = 0.01
    11  		count  = 0
    12  	)
    13  
    14  	for i := 0; i < total; i++ {
    15  		if manager.hitSample(sample) {
    16  			count++
    17  		}
    18  	}
    19  
    20  	if count != int(float64(total)*sample) {
    21  		t.Fail()
    22  	}
    23  }