mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
25 lines
391 B
Go
25 lines
391 B
Go
|
package mathx
|
||
|
|
||
|
import (
|
||
|
"math"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestTrueOnProba(t *testing.T) {
|
||
|
const proba = math.Pi / 10
|
||
|
const total = 100000
|
||
|
const epsilon = 0.05
|
||
|
var count int
|
||
|
p := NewProba()
|
||
|
for i := 0; i < total; i++ {
|
||
|
if p.TrueOnProba(proba) {
|
||
|
count++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ratio := float64(count) / float64(total)
|
||
|
assert.InEpsilon(t, proba, ratio, epsilon)
|
||
|
}
|