github.com/leanovate/gopter@v0.2.9/gen/complex_shrink.go (about) 1 package gen 2 3 import "github.com/leanovate/gopter" 4 5 // Complex128Shrinker is a shrinker for complex128 numbers 6 func Complex128Shrinker(v interface{}) gopter.Shrink { 7 c := v.(complex128) 8 realShrink := Float64Shrinker(real(c)).Map(func(r float64) complex128 { 9 return complex(r, imag(c)) 10 }) 11 imagShrink := Float64Shrinker(imag(c)).Map(func(i float64) complex128 { 12 return complex(real(c), i) 13 }) 14 return realShrink.Interleave(imagShrink) 15 } 16 17 // Complex64Shrinker is a shrinker for complex64 numbers 18 func Complex64Shrinker(v interface{}) gopter.Shrink { 19 c := v.(complex64) 20 realShrink := Float64Shrinker(float64(real(c))).Map(func(r float64) complex64 { 21 return complex(float32(r), imag(c)) 22 }) 23 imagShrink := Float64Shrinker(float64(imag(c))).Map(func(i float64) complex64 { 24 return complex(real(c), float32(i)) 25 }) 26 return realShrink.Interleave(imagShrink) 27 }