github.com/leanovate/gopter@v0.2.9/gen/floats_test.go (about) 1 package gen_test 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/leanovate/gopter/gen" 8 ) 9 10 func TestFloat64(t *testing.T) { 11 commonGeneratorTest(t, "float 64", gen.Float64(), func(value interface{}) bool { 12 v, ok := value.(float64) 13 return ok && !math.IsNaN(v) && !math.IsInf(v, 0) 14 }) 15 } 16 17 func TestFloat64Range(t *testing.T) { 18 fail := gen.Float64Range(200, 100) 19 20 if value, ok := fail.Sample(); value != nil || ok { 21 t.Fail() 22 } 23 24 commonGeneratorTest(t, "float 64 range", gen.Float64Range(-1234.5, 56789.123), func(value interface{}) bool { 25 v, ok := value.(float64) 26 return ok && !math.IsNaN(v) && !math.IsInf(v, 0) && v >= -1234.5 && v <= 56789.123 27 }) 28 } 29 30 func TestFloat32(t *testing.T) { 31 commonGeneratorTest(t, "float 32", gen.Float32(), func(value interface{}) bool { 32 _, ok := value.(float32) 33 return ok 34 }) 35 } 36 37 func TestFloat32Range(t *testing.T) { 38 fail := gen.Float32Range(200, 100) 39 40 if value, ok := fail.Sample(); value != nil || ok { 41 t.Fail() 42 } 43 44 commonGeneratorTest(t, "float 32 range", gen.Float32Range(-1234.5, 56789.123), func(value interface{}) bool { 45 v, ok := value.(float32) 46 return ok && v >= -1234.5 && v <= 56789.123 47 }) 48 }