github.com/leanovate/gopter@v0.2.9/gen/complex_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 TestComplex128Box(t *testing.T) { 11 minReal := -12345.67 12 maxReal := 2345.78 13 minImag := -5432.8 14 maxImag := 8764.6 15 complexes := gen.Complex128Box(complex(minReal, minImag), complex(maxReal, maxImag)) 16 commonGeneratorTest(t, "complex 128 box", complexes, func(value interface{}) bool { 17 v, ok := value.(complex128) 18 return ok && real(v) >= minReal && real(v) < maxReal && imag(v) >= minImag && imag(v) < maxImag 19 }) 20 } 21 22 func TestComplex128(t *testing.T) { 23 commonGeneratorTest(t, "complex 128", gen.Complex128(), func(value interface{}) bool { 24 v, ok := value.(complex128) 25 return ok && !math.IsNaN(real(v)) && !math.IsNaN(imag(v)) && !math.IsInf(real(v), 0) && !math.IsInf(imag(v), 0) 26 }) 27 } 28 29 func TestComplex64Box(t *testing.T) { 30 minReal := float32(-12345.67) 31 maxReal := float32(2345.78) 32 minImag := float32(-5432.8) 33 maxImag := float32(8764.6) 34 complexes := gen.Complex64Box(complex(minReal, minImag), complex(maxReal, maxImag)) 35 commonGeneratorTest(t, "complex 64 box", complexes, func(value interface{}) bool { 36 v, ok := value.(complex64) 37 return ok && real(v) >= minReal && real(v) < maxReal && imag(v) >= minImag && imag(v) < maxImag 38 }) 39 } 40 41 func TestComplex64(t *testing.T) { 42 commonGeneratorTest(t, "complex 64", gen.Complex64(), func(value interface{}) bool { 43 _, ok := value.(complex64) 44 return ok 45 }) 46 }