proba_test.go 391 B

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