github.com/leanovate/gopter@v0.2.9/gen/complex.go (about) 1 package gen 2 3 import "github.com/leanovate/gopter" 4 5 // Complex128Box generate complex128 numbers within a rectangle/box in the complex plane 6 func Complex128Box(min, max complex128) gopter.Gen { 7 return gopter.CombineGens( 8 Float64Range(real(min), real(max)), 9 Float64Range(imag(min), imag(max)), 10 ).Map(func(values []interface{}) complex128 { 11 return complex(values[0].(float64), values[1].(float64)) 12 }).SuchThat(func(v complex128) bool { 13 return real(v) >= real(min) && real(v) <= real(max) && 14 imag(v) >= imag(min) && imag(v) <= imag(max) 15 }).WithShrinker(Complex128Shrinker) 16 } 17 18 // Complex128 generate arbitrary complex128 numbers 19 func Complex128() gopter.Gen { 20 return gopter.CombineGens( 21 Float64(), 22 Float64(), 23 ).Map(func(values []interface{}) complex128 { 24 return complex(values[0].(float64), values[1].(float64)) 25 }).WithShrinker(Complex128Shrinker) 26 } 27 28 // Complex64Box generate complex64 numbers within a rectangle/box in the complex plane 29 func Complex64Box(min, max complex64) gopter.Gen { 30 return gopter.CombineGens( 31 Float32Range(real(min), real(max)), 32 Float32Range(imag(min), imag(max)), 33 ).Map(func(values []interface{}) complex64 { 34 return complex(values[0].(float32), values[1].(float32)) 35 }).SuchThat(func(v complex64) bool { 36 return real(v) >= real(min) && real(v) <= real(max) && 37 imag(v) >= imag(min) && imag(v) <= imag(max) 38 }).WithShrinker(Complex64Shrinker) 39 } 40 41 // Complex64 generate arbitrary complex64 numbers 42 func Complex64() gopter.Gen { 43 return gopter.CombineGens( 44 Float32(), 45 Float32(), 46 ).Map(func(values []interface{}) complex64 { 47 return complex(values[0].(float32), values[1].(float32)) 48 }).WithShrinker(Complex64Shrinker) 49 }