github.com/lingyao2333/mo-zero@v1.4.1/core/mathx/proba_test.go (about) 1 package mathx 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestTrueOnProba(t *testing.T) { 11 const proba = math.Pi / 10 12 const total = 100000 13 const epsilon = 0.05 14 var count int 15 p := NewProba() 16 for i := 0; i < total; i++ { 17 if p.TrueOnProba(proba) { 18 count++ 19 } 20 } 21 22 ratio := float64(count) / float64(total) 23 assert.InEpsilon(t, proba, ratio, epsilon) 24 }