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